I am trying to do the following in a Test/Unit integration test using
Capybara. Very basic Rails 3 app, Ruby 1.9.2 just with the pg and
capybara
gems, thats it.
Everything works except that the Person object I create manually in the
test
does not show in the test database… or any other database I can find!
But
Person.all returns him, so he is getting created somewhere. Then, when
Capybara/Selenium go to the browser which I have verified does hit the
test
database fine (through another test), I get an empty list of people on
the
index page.
Capybara/Selenium have the Rails.env correct in terms of hitting the db
correctly. The Test itself says Rails.env = “test”, the data does not go
into the test db. Where is the data getting saved? And how can I
manually
set up data in an Integration test before running Capybara? I thought
maybe
that Capybara was somehow triggering the database being emptied but the
sequence below proves this is not the case:
def test_see_yoohoo
person = Person.new
person.name = “Yoohoo”
person.email = “[email protected]”
assert person.save # passes
assert Person.find_by_name(“Yoohoo”) # passes but in dbconsole
"select
from people" in the test database (or dev database) returns no rows
assert_equal Rails.env, “test” # passes
visit “/people” #
page
loads fine… Capybara/Selenium working…
assert page.has_content?(‘Yoohoo’) # fails (page has
empty
list… the list passes fine on another page so issue is not the view)
assert page.has_content?(‘[email protected]’)
end
database fine (through another test), I get an empty list of people on the
person = Person.new
assert page.has_content?(‘Yoohoo’) # fails (page has
behavior.
Thanks! At first I did not believe this was the issue but I tried and it
worked. So what I learned is that even though my calls to Capybara are
within a single method the transactional fixture object is its own
world. So
it seems the ‘transaction’ never hits the db, right, so the tests are
faster?
And so when the browser boots this is hitting a new transaction… and
thus
the data I just created is gone.
I am trying to do the following in a Test/Unit integration test using
Capybara. Very basic Rails 3 app, Ruby 1.9.2 just with the pg and
capybara
gems, thats it.
[…]
Is there any particular reason that you are torturing yourself this way
instead of using Cucumber?