Class: Riot::Situation
Overview
A Situation is virtually a stack frame for a single context run. The intent is for all blocks to be evaluated against an instance of a Situation. Given the following superfluous context:
context "Foo" do # block-1
setup do # block-2
{:bar => "baz"}
end
asserts "its hash" do # block-3
topic
end.equals do # block-4
{:bar => "baz"}
end
end # Foo
In this example, block-1 will be evaluated against a Context instance. Whereas block-2, block-3, and block-4 will all be evaluated against the same Situation instance. Situation instances (situations) are bound to a single context run; they are not shared across context runs, regardless of their position in the test tree structure.
What is gained from doing it this way is:
-
variables, methods, etc. set in one situation do not contaminate any others
-
variables, methods, etc. defined during a context run do not stick with the context itself
-
which means that testing state is independent of the test definitions themselves
Direct Known Subclasses
Instance Method Summary collapse
-
#evaluate(&block) ⇒ Object
Anonymously evaluates any block given to it against the current instance of
self
. -
#helper(name, &block) ⇒ Object
This is where a defined helper is born.
-
#setup(&block) ⇒ Object
This is where a setup block is actually evaluated and the
topic
tracked. -
#topic ⇒ Object
Returns the currrently tracked value of
topic
.
Instance Method Details
#evaluate(&block) ⇒ Object
Anonymously evaluates any block given to it against the current instance of self
. This is how assertion and assertion macro blocks are evaluated, for instance.
60 61 62 |
# File 'lib/riot/situation.rb', line 60 def evaluate(&block) self.instance_eval(&block) end |
#helper(name, &block) ⇒ Object
This is where a defined helper is born. A method is defined against the current instance of self
. This method will not be defined on any other instances of Situation created afterwards.
50 51 52 |
# File 'lib/riot/situation.rb', line 50 def helper(name, &block) (class << self; self; end).send(:define_method, name, &block) end |
#setup(&block) ⇒ Object
This is where a setup block is actually evaluated and the topic
tracked.
41 42 43 |
# File 'lib/riot/situation.rb', line 41 def setup(&block) @_topic = self.instance_eval(&block) end |
#topic ⇒ Object
Returns the currrently tracked value of topic
33 34 35 |
# File 'lib/riot/situation.rb', line 33 def topic @_topic ||= nil end |