[rspec-users] [Cucumber, Webrat] Unable to run 2 features in a row
lists at ruby-forum.com
Sat Jan 17 19:07:41 EST 2009
Fernando Perez wrote:
> I have written 2 features that each have 1 scenario. When I execute each
> feature separately with "rake features FEATURE=features/..." they each
> pass, but when I do "rake features", the first feature passes, and the
> second one fails.
> In my Given steps, I populate the DB, and some Given steps are called by
> both features. I can't call Given in only one feature and not the other,
> because in such case, individually running each feature would fail. So I
> have added a check, if the entry already exists, then I shall not create
> a duplicate. But it still doesn't work.
> How to get around this headache? Anyone already bumped into that?
Okay I get it now. That was a nasty one:
Between each Scenario, the DB gets cleared, however when adding entries
to the DB, the object's id gets incremented (i.e: it won't reset to 1).
So you cannot do something like the following in your step files:
product.author_id = 1
The way to fix this problem is to instantiate the object as an instance
@author = Author.create!
And then in the step definition you get its id using:
product.author_id = @author.id
It took me a few hours to figure out, and a lot of trial and error.
As I don't see any other way around, I guess it is a good idea to update
the following documentation page accordingly to explain in which case an
instance var is compulsory:
Posted via http://www.ruby-forum.com/.
More information about the rspec-users