Class: Riot::Context
Instance Attribute Summary collapse
-
#description ⇒ Object
readonly
Returns the value of attribute description.
Instance Method Summary collapse
- #assertion_class ⇒ Object
- #asserts(what, &definition) ⇒ Object
- #asserts_topic ⇒ Object
- #context(description, &definition) ⇒ Object
- #extend_assertions(*extension_modules) ⇒ Object
-
#initialize(description, parent = RootContext.new([],[]), &definition) ⇒ Context
constructor
A new instance of Context.
- #run(reporter) ⇒ Object
- #setup(&definition) ⇒ Object
- #setups ⇒ Object
- #should(what, &definition) ⇒ Object
- #teardown(&definition) ⇒ Object
- #teardowns ⇒ Object
Constructor Details
#initialize(description, parent = RootContext.new([],[]), &definition) ⇒ Context
Returns a new instance of Context.
10 11 12 13 14 15 |
# File 'lib/riot/context.rb', line 10 def initialize(description, parent=RootContext.new([],[]), &definition) @parent = parent @description = description @contexts, @setups, @assertions, @teardowns = [], [], [], [] self.instance_eval(&definition) end |
Instance Attribute Details
#description ⇒ Object (readonly)
Returns the value of attribute description.
9 10 11 |
# File 'lib/riot/context.rb', line 9 def description @description end |
Instance Method Details
#assertion_class ⇒ Object
44 45 46 |
# File 'lib/riot/context.rb', line 44 def assertion_class @assertion_class ||= @parent.assertion_class end |
#asserts(what, &definition) ⇒ Object
23 |
# File 'lib/riot/context.rb', line 23 def asserts(what, &definition) new_assertion("asserts", what, &definition); end |
#asserts_topic ⇒ Object
25 |
# File 'lib/riot/context.rb', line 25 def asserts_topic; asserts("topic") { topic }; end |
#context(description, &definition) ⇒ Object
27 28 29 |
# File 'lib/riot/context.rb', line 27 def context(description, &definition) @contexts << self.class.new("#{@description} #{description}", self, &definition) end |
#extend_assertions(*extension_modules) ⇒ Object
31 32 33 34 35 |
# File 'lib/riot/context.rb', line 31 def extend_assertions(*extension_modules) @assertion_class = Class.new(Assertion) do include *extension_modules end end |
#run(reporter) ⇒ Object
37 38 39 40 41 42 |
# File 'lib/riot/context.rb', line 37 def run(reporter) reporter.describe_context(self) unless @assertions.empty? local_run(reporter, Situation.new) run_sub_contexts(reporter) reporter end |
#setup(&definition) ⇒ Object
20 |
# File 'lib/riot/context.rb', line 20 def setup(&definition) (@setups << Setup.new(&definition)).last; end |
#setups ⇒ Object
17 |
# File 'lib/riot/context.rb', line 17 def setups; @parent.setups + @setups; end |
#should(what, &definition) ⇒ Object
24 |
# File 'lib/riot/context.rb', line 24 def should(what, &definition) new_assertion("should", what, &definition); end |
#teardown(&definition) ⇒ Object
21 |
# File 'lib/riot/context.rb', line 21 def teardown(&definition) (@teardowns << Setup.new(&definition)).last; end |
#teardowns ⇒ Object
18 |
# File 'lib/riot/context.rb', line 18 def teardowns; @parent.teardowns + @teardowns; end |