Hubert Lepicki
2009-Jan-04 19:13 UTC
[rspec-users] Cucumber model expectations fail to find newly created users
Hi guys, I have strange problem with getting model expectations to work with Cucumber. My setup is that I use Cucumber + Webrat (Selenium backend). 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 end 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? -- Posted via http://www.ruby-forum.com/.
Hubert Lepicki
2009-Jan-04 19:15 UTC
[rspec-users] Cucumber model expectations fail to find newly created users
The step definition is actually: Then /^should exist exactly "(.*)" users$/ do |cnt| User.count.should == cnt.to_i end but that doesn''t change anything, please help! -- Posted via http://www.ruby-forum.com/.
Ben Mabey
2009-Jan-04 19:46 UTC
[rspec-users] Cucumber model expectations fail to find newly created users
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 following? Cucumber::Rails.use_transactional_fixtures 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. -Ben> 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 > end > > 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? >
Hubert Lepicki
2009-Jan-04 20:16 UTC
[rspec-users] Cucumber model expectations fail to find newly created users
Ben Mabey wrote:> 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 > following? > Cucumber::Rails.use_transactional_fixturesThat was a perfect guess! Thank you, Ben, a lot! I have updated Troubleshooting page in Github wiki like you suggested so that other people might find solution quicker than me :). One more time - thanks! -- Posted via http://www.ruby-forum.com/.