I have a JS feature spec I'm trying to run with Capybara Webkit. It doesn't seem to be able to find my database records however.
The spec in question looks like this
it "should allow pledging to a Hardback level", js: true do
book = FactoryGirl.create :book
visit book_path(book)
click_link "pledge-btn"
end
Unfortunately, the request to book_path(book)
404s because the book cannot be found.
If I take the :js
flag off, the test passes.
I have DatabaseCleaner
set up to use :truncation
for JS specs as is the recommended method.
# spec/support/database_cleaner.rb
RSpec.configure do |config|
config.use_transactional_fixtures = false
config.before(:suite) do
DatabaseCleaner.clean_with(:truncation)
end
config.before(:each) do
DatabaseCleaner.strategy = :transaction
end
config.before(:each, :js => true) do
DatabaseCleaner.strategy = :truncation
end
config.before(:each) do
DatabaseCleaner.start
DatabaseMetadata.create!(:sanitized_at => DateTime.now)
end
config.after(:each) do
DatabaseCleaner.clean
end
end
I can puts
the book in the test and it will be found.
it "should allow pledging to a Hardback level", js: true do
book = FactoryGirl.create :book
visit book_path(book)
p Book.first
# => .. the book instance
click_link "pledge-btn"
end
I've also tried this shared connection method which doesn't seem to fix the problem either.
What else could be wrong?
config.use_transactional_fixtures = false
? – Behaviorbefore(:each)
block (I simplified a little to keep the question concise). I've tried it within and without and it makes no difference. – Maughambook
does present in the db? You runningputs Book.first
notputs book
, it can be or can be not equal. Can you attach test log? with insert sql, finder sql, transaction marks (like begin, comit). And what is the order of before blocks? If before(:each) runs later then before(:each, :js => true) it can be the reason, try outputting something in them. – Typhus