Repository navigation
Usage
Usage
First, create file spec/hornsby_scenarios.rb_. It is a ruby file, containing scenarios. For example (taken from HornsbyScenario’s own specs):
apple do
scenario :just
@apple = Fruit.create! :species => ‘apple’
end
scenario :bananas_and_apples => :just_apple do
@banana = Fruit.create! :species => ‘banana’
end
Then, in your spec you may write some trivial expectation:
describe Fruit do
it “should have species” do
hornsby_scenario :bananas_and_apples
@apple.species.should == ‘apple’
@banana.species.should == ‘banana’
end
end
As you see, one scenario can be based on another.
Even more, it can be based on many scenarios. For example:
scenario :bananas_and_apples => [:just_apple, :just_banana] do # lets imagine that we have :just_banana scenario
end
Contents of last scenario is empty. I removed requirement of such scenarios. Now you can simply write:
it “should do something…” do
hornsby_scenario :just_apple, :just_banana, :just_cherry
end
How it works
A call to hornsby_scenario clears database.
Instance variables, initialized at scenarios, are available at specs.
You can build huge trees of scenarios, and include same scenario in many of them as requirement.
If scenario belongs to scenarios tree, it is run ONCE.
Not repeated many times.
So such scenario would create just one apple:
scenario :many_apples => [:just_apple, :just_apple, :just_apple] do
end