Class: Riot::Context
- Includes:
- ContextClassOverrides, ContextHelpers, ContextOptions
- Defined in:
- lib/riot/context.rb
Overview
An Assertion is declared within a Context. The context stores setup and teardown blocks, and allows for nesting and refactoring. Extension developers may also configure Middleware objects in order to extend the functionality of a Context.
Instance Attribute Summary collapse
-
#description ⇒ String
readonly
The partial description of just this context.
-
#parent ⇒ Riot::Context?
readonly
The parent context.
Class Method Summary collapse
-
.middlewares ⇒ Array<Riot::ContextMiddleware>
The set of middleware helpers configured for the current test space.
Instance Method Summary collapse
-
#context(description, &definition) ⇒ Riot::Context
(also: #describe)
Create a new test context.
-
#detailed_description ⇒ String
Prints the full description from the context tree, grabbing the description from the parent and appending the description given to this context.
-
#initialize(description, parent = nil, &definition) ⇒ Context
constructor
Creates a new Context.
-
#run(reporter) ⇒ Riot::Reporter
Executes the setups, hookups, assertions, and teardowns and passes results on to a given Reporter.
Methods included from ContextHelpers
#asserts, #asserts_topic, #denies, #denies_topic, #helper, #hookup, #setup, #should, #should_not, #teardown
Methods included from ContextOptions
Methods included from ContextClassOverrides
#assertion_class, #situation_class
Constructor Details
#initialize(description, parent = nil, &definition) ⇒ Context
Creates a new Context
50 51 52 53 54 55 56 57 58 59 |
# File 'lib/riot/context.rb', line 50 def initialize(description, parent=nil, &definition) @parent = parent || RootContext.new([],[], "", {}) @description = description @contexts, @setups, @assertions, @teardowns = [], [], [], [] @context_error = nil @options = @parent.option_set.dup prepare_middleware(&definition) rescue Exception => e @context_error = e end |
Instance Attribute Details
#description ⇒ String (readonly)
The partial description of just this context.
38 39 40 |
# File 'lib/riot/context.rb', line 38 def description @description end |
#parent ⇒ Riot::Context? (readonly)
The parent context.
43 44 45 |
# File 'lib/riot/context.rb', line 43 def parent @parent end |
Class Method Details
.middlewares ⇒ Array<Riot::ContextMiddleware>
The set of middleware helpers configured for the current test space.
33 |
# File 'lib/riot/context.rb', line 33 def self.middlewares; @middlewares ||= []; end |
Instance Method Details
#context(description, &definition) ⇒ Riot::Context Also known as: describe
Create a new test context.
65 66 67 |
# File 'lib/riot/context.rb', line 65 def context(description, &definition) new_context(description, self.class, &definition) end |
#detailed_description ⇒ String
Prints the full description from the context tree, grabbing the description from the parent and appending the description given to this context.
119 120 121 |
# File 'lib/riot/context.rb', line 119 def detailed_description "#{parent.detailed_description} #{description}".strip end |
#run(reporter) ⇒ Riot::Reporter
Executes the setups, hookups, assertions, and teardowns and passes results on to a given Reporter. Sub-contexts will also be executed and provided the given reporter. A new Situation will be created from the specified Situation class.
92 93 94 95 96 97 98 99 100 101 |
# File 'lib/riot/context.rb', line 92 def run(reporter) reporter.describe_context(self) unless @assertions.empty? if @context_error reporter.report("context preparation", [:context_error, @context_error]) else local_run(reporter, situation_class.new) run_sub_contexts(reporter) end reporter end |