Class: Riot::Context

Inherits:
Object show all
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

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ContextHelpers

#asserts, #asserts_topic, #denies, #denies_topic, #helper, #hookup, #setup, #should, #should_not, #teardown

Methods included from ContextOptions

#option, #options, #set

Methods included from ContextClassOverrides

#assertion_class, #situation_class

Constructor Details

#initialize(description, parent = nil, &definition) ⇒ Context

Creates a new Context

Parameters:

  • description (String)

    a partial description of this context

  • parent (Riot::Context, nil) (defaults to: nil)

    a parent context or nothing

  • definition (lambda)

    the body of this 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.options
  prepare_middleware(&definition)
end

Instance Attribute Details

#descriptionString (readonly)

The partial description of just this context.

Returns:

  • (String)


38
39
40
# File 'lib/riot/context.rb', line 38

def description
  @description
end

#parentRiot::Context? (readonly)

The parent context.

Returns:



43
44
45
# File 'lib/riot/context.rb', line 43

def parent
  @parent
end

Class Method Details

.middlewaresArray<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.

Parameters:

  • description (String)

Returns:



62
63
64
# File 'lib/riot/context.rb', line 62

def context(description, &definition)
  new_context(description, self.class, &definition)
end

#detailed_descriptionString

Prints the full description from the context tree, grabbing the description from the parent and appending the description given to this context.

Returns:

  • (String)

    the full description for this context



108
109
110
# File 'lib/riot/context.rb', line 108

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.

Parameters:

Returns:



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