Class: Riot::Context
- Inherits:
-
Object
- Object
- 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)
-
- (String) description
readonly
The partial description of just this context.
-
- (Riot::Context?) parent
readonly
The parent context.
Class Method Summary (collapse)
-
+ (Array<Riot::ContextMiddleware>) middlewares
The set of middleware helpers configured for the current test space.
Instance Method Summary (collapse)
-
- (Riot::Context) context(description, &definition)
(also: #describe)
Create a new test context.
-
- (String) detailed_description
Prints the full description from the context tree, grabbing the description from the parent and appending the description given to this context.
-
- (Context) initialize(description, parent = nil, &definition)
constructor
Creates a new Context.
-
- (Riot::Reporter) run(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
- (Context) initialize(description, parent = nil, &definition)
Creates a new Context
50 51 52 53 54 55 56 |
# File 'lib/riot/context.rb', line 50 def initialize(description, parent=nil, &definition) @parent = parent || RootContext.new([],[], "", {}) @description = description @contexts, @setups, @assertions, @teardowns = [], [], [], [] @options = @parent.option_set.dup prepare_middleware(&definition) end |
Instance Attribute Details
- (String) description (readonly)
The partial description of just this context.
38 39 40 |
# File 'lib/riot/context.rb', line 38 def description @description end |
- (Riot::Context?) parent (readonly)
The parent context.
43 44 45 |
# File 'lib/riot/context.rb', line 43 def parent @parent end |
Class Method Details
+ (Array<Riot::ContextMiddleware>) middlewares
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
- (Riot::Context) context(description, &definition) Also known as: describe
Create a new test context.
62 63 64 |
# File 'lib/riot/context.rb', line 62 def context(description, &definition) new_context(description, self.class, &definition) end |
- (String) detailed_description
Prints the full description from the context tree, grabbing the description from the parent and appending the description given to this context.
112 113 114 |
# File 'lib/riot/context.rb', line 112 def detailed_description "#{parent.detailed_description} #{description}".strip end |
- (Riot::Reporter) run(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.
89 90 91 92 93 94 |
# File 'lib/riot/context.rb', line 89 def run(reporter) reporter.describe_context(self) unless @assertions.empty? local_run(reporter, situation_class.new) run_sub_contexts(reporter) reporter end |