ruby on rails - RSpec, Factory Girl and Capybara: no items saved -
i have mountable rails engine rspec:
rspec.configure |config| config.use_transactional_fixtures = false config.before(:suite) databasecleaner.clean_with(:truncation) end config.before(:each) |example| databasecleaner.strategy= example.metadata[:js] ? :truncation : :transaction databasecleaner.start end config.after(:each) databasecleaner.clean end end
simple factory:
factorygirl.define factory :post, :class => myengine::post title 'title' end end
capybara feature:
require 'spec_helper' describe 'post', :type => :feature let(:post) { factorygirl.create :post } 'index action should have post' visit posts_path expect(page).to have_text(post.title) end end
and post model doesn't have validations.
but when running tests shows there no posts created.
also activerecord logs:
insert "my_engine_posts" ... release savepoint active_record_1 rollback transaction
this spec fail.
let
in rspec lazy loading. post
not created until reference in:
expect(page).to have_text(post.title)
so can either use let!
not lazy loading or reference post
before visit page:
require 'spec_helper' describe 'post', :type => :feature let(:post) { factorygirl.create :post } 'index action should have post' post visit posts_path expect(page).to have_text(post.title) end end
Comments
Post a Comment