[rspec-users] Cucumber model expectations fail to find newly created users
ben at benmabey.com
Sun Jan 4 14:46:54 EST 2009
On 1/4/09 12:13 PM, Hubert Lepicki wrote:
> Hi guys,
> I have strange problem with getting model expectations to work with
> Cucumber. My setup is that I use Cucumber + Webrat (Selenium backend).
My guess is that you are using Selenium in conjuction with rails
transactional fixtures turned on. In your env.rb file do you have the
If so that is your problem. What is happending is that you two separate
processes and two separate DB connections going. One is running the
server for selenium, and the other is for your features. With
transactional_fixtures turned on all of your DB calls for each scenario
are wrapped in into a transaction that is rolled back at the end. Be
default MySQL, and most other DBs I would imagine, don't let the data in
a transaction appear to any other queries until that transaction is
actually committed. That is why you can see the correct count in the
process running the features but not the selenium process.
How do you get around this? You could change your settings on MySQL,
but I wouldn't suggest that. What I do is turn off
transactional_fixtures and then manage the DB cleanup myself in After
blocks. The quick and dirty way to do this is to truncate your tables..
There have been some threads on this list explaining how to do this.
There are some other ways to accomplish this without resorting to
truncating everytime too, but I will let you google and find those threads.
This problem seems to come up quite a bit.. we should probably add this
to the Troubleshooting page on Cucumber's wiki....
Anyways, I hope that helps.
> Story I test is registering user on site. Cucumber runs story perfectly
> fine, and I see it fills in form, sends it, I even see proper "You have
> successfully registered" message at the end. However, as a last element
> of story I want to make sure the user was really created in database -
> and this fails.
> I have definition of following step:
> Then /^should exist exactly "(.*)" users$/ do |cnt, state|
> User.count.should == cnt.to_i
> However, it always complains that there are 0 users, when expected X.
> What is even more stranger, when I log into console, and do User.count,
> I get proper number of users - they were actually created during running
> a story!
> Any ideas?
More information about the rspec-users