Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cucumber: Before hook run only once for all scenarios

I have a scenario outline with multiple scenarios. I'd like my Before hook to run only once so I can bootstrap the ActiveRecord objects I need to run against all of the scenarios. The problem is if I use

Before do
    # my code here
end

This will execute before each Scenario. Is there anyway to run it once for the entire Outline?

like image 508
randombits Avatar asked Oct 24 '10 23:10

randombits


1 Answers

I think if you simply create the objects in a file in features/support they will be persisted:

ImportantThing.create(:name => "USEFUL THING")

This is because before every Scenario Cucumber will start a database transaction and then rollback to its prior status, which should contain the objects you've loaded.

like image 88
Ryan Bigg Avatar answered Sep 29 '22 20:09

Ryan Bigg