I am running my tests for a rails application using test/unit and capybara. I am fairly new to rails, so I'm hoping that I'm missing something obvious. I have the following integration test to fill out a single field and submit a form. This works as expected and the test passes:
test "create post with title only should add post" do
assert_difference('Post.count') do
visit '/posts/new'
fill_in :title, :with => "Sample Post"
click_button 'create Post'
end
assert current_path == post_path(Post.last)
assert page.has_content?("Sample Post")
end
I added a second test, that pretty much copies the previous test but also fills out a second field and checks for the additional input (this fails).
test "create post with title and body should add post" do
assert_difference('Post.count') do
visit '/posts/new'
fill_in :title, :with => "Testing"
fill_in :body, :with => "This is a sample post"
save_and_open_page
click_button 'create Post'
end
save_and_open_page
assert current_path == post_path(Post.last)
assert page.has_content?("Testing")
assert page.has_content?("This is a sample post")
end
When this failed, I added the call to:
save_and_open_page
and found that the form was being filled out with the title value from the previous test and no body value was supplied at all. The name of the test and the assertions match the second test, so this isn't a case of mistaken identity. It seems that Capybara isn't getting the updated values. I also have this code in my test_helper.rb file:
DatabaseCleaner.strategy = :truncation
module ActionController
class IntegrationTest
include Capybara::DSL
self.use_transactional_fixtures = false
teardown do
DatabaseCleaner.clean
Capybara.reset_sessions!
Capybara.use_default_driver
end
end
end
I'm assuming this should clear out values in between tests. Since that clearly wasn't happening, I also tried adding a call to Capybara.rest_sessions! at the end of the first test and that didn't help.
Any advice or help would be greatly appreciated.