Class: Riot::Context
- Includes:
- ContextClassOverrides, ContextHelpers, ContextOptions
- Defined in:
- lib/riot/context.rb
Overview
You make your assertions within a Context. The context stores setup and teardown blocks, and allows for nesting and refactoring into helpers. Extension developers may also configure ContextMiddleware objects in order to extend the functionality of a Context.
Instance Attribute Summary collapse
-
#description ⇒ String
readonly
The description of the context.
-
#parent ⇒ Riot::Context
readonly
The parent context.
Class Method Summary collapse
-
.middlewares ⇒ Array
The set of middleware helpers configured for the current test space.
Instance Method Summary collapse
-
#context(description, &definition) ⇒ Object
(also: #describe)
Create a new test context.
-
#detailed_description ⇒ Object
Prints the full description from the context tree.
-
#initialize(description, parent = nil, &definition) ⇒ Context
constructor
A new instance of Context.
- #local_run(reporter, situation) ⇒ Object
- #run(reporter) ⇒ Object
-
#setups ⇒ Array[Riot::RunnableBlock]
Returns an ordered list of the setup blocks for the context.
-
#teardowns ⇒ Array[Riot::RunnableBlock]
Returns an ordered list of the teardown blocks for the context.
Methods included from ContextHelpers
#asserts, #asserts_topic, #denies, #helper, #hookup, #setup, #should, #teardown
Methods included from ContextOptions
Methods included from ContextClassOverrides
#assertion_class, #situation_class
Constructor Details
#initialize(description, parent = nil, &definition) ⇒ Context
Returns a new instance of Context.
35 36 37 38 39 40 41 |
# File 'lib/riot/context.rb', line 35 def initialize(description, parent=nil, &definition) @parent = parent || RootContext.new([],[], "", {}) @description = description @contexts, @setups, @assertions, @teardowns = [], [], [], [] @options = @parent. prepare_middleware(&definition) end |
Instance Attribute Details
#description ⇒ String (readonly)
The description of the context.
28 29 30 |
# File 'lib/riot/context.rb', line 28 def description @description end |
#parent ⇒ Riot::Context (readonly)
The parent context.
33 34 35 |
# File 'lib/riot/context.rb', line 33 def parent @parent end |
Class Method Details
.middlewares ⇒ Array
The set of middleware helpers configured for the current test space.
23 |
# File 'lib/riot/context.rb', line 23 def self.middlewares; @middlewares ||= []; end |
Instance Method Details
#context(description, &definition) ⇒ Object Also known as: describe
Create a new test context.
46 47 48 |
# File 'lib/riot/context.rb', line 46 def context(description, &definition) new_context(description, self.class, &definition) end |
#detailed_description ⇒ Object
Prints the full description from the context tree
77 78 79 |
# File 'lib/riot/context.rb', line 77 def detailed_description "#{parent.detailed_description} #{description}".strip end |
#local_run(reporter, situation) ⇒ Object
72 73 74 |
# File 'lib/riot/context.rb', line 72 def local_run(reporter, situation) runnables.each { |runnable| reporter.report(runnable.to_s, runnable.run(situation)) } end |
#run(reporter) ⇒ Object
65 66 67 68 69 70 |
# File 'lib/riot/context.rb', line 65 def run(reporter) reporter.describe_context(self) unless @assertions.empty? local_run(reporter, situation_class.new) run_sub_contexts(reporter) reporter end |
#setups ⇒ Array[Riot::RunnableBlock]
Returns an ordered list of the setup blocks for the context.
54 55 56 |
# File 'lib/riot/context.rb', line 54 def setups @parent.setups + @setups end |
#teardowns ⇒ Array[Riot::RunnableBlock]
Returns an ordered list of the teardown blocks for the context.
61 62 63 |
# File 'lib/riot/context.rb', line 61 def teardowns @parent.teardowns + @teardowns end |