Jay McGavren
2008-Mar-13 20:43 UTC
[rspec-users] Equivalent to before(:all) for StepGroups?
I have a helper object that I''d like to have available inside each of
my story steps, but would like to declare it *outside* all the steps.
(It knows how to create various objects in my library, then stores a
string reference to it for later steps to refer to.)
Problem is, I''ve tried assigning to a module variable both inside and
outside my steps_for block, and I get an error that the variable
hasn''t been previously assigned when I reference it within a step
block. To get it to work, I have to create the object within a step
block:
steps_for(:all) do
#TODO: This is a total kludge.
Given /an environment/ do
@om = ObjectManager.new
@environment = @om.resolve_objects("an environment").first
def add_to_environment(object)
@environment << object
object
end
@om.on_create("target") {add_to_environment Creature.new}
@om.on_create("creature") {add_to_environment Creature.new}
@om.on_create("game object") {add_to_environment GameObject.new}
end
Given /(an? (?:creature|game object|target))/i do |subject|
@om.resolve_objects(subject)
end
...
...meaning I have to begin each story with "Given an environment",
whether that''s appropriate to the story or not.
Is there some equivalent to before(:all) that I can use within
stories? Or failing that, how else can I create a module variable in
the context that the step blocks run within? (I''d prefer to avoid
global variables, of course.) Many thanks for any advice!
-Jay McGavren
http://jay.mcgavren.com/zyps
