Class: Riot::Context

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

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ContextHelpers

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

Methods included from ContextOptions

#option, #options, #set

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

Instance Attribute Details

#descriptionString (readonly)

The description of the context.

Returns:

  • (String)


28
29
30
# File 'lib/riot/context.rb', line 28

def description
  @description
end

#parentRiot::Context (readonly)

The parent context.

Returns:



33
34
35
# File 'lib/riot/context.rb', line 33

def parent
  @parent
end

Class Method Details

.middlewaresArray

The set of middleware helpers configured for the current test space.

Returns:

  • (Array)


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.

Parameters:

  • description (String)


46
47
48
# File 'lib/riot/context.rb', line 46

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

#detailed_descriptionObject

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

#setupsArray[Riot::RunnableBlock]

Returns an ordered list of the setup blocks for the context.

Returns:



54
55
56
# File 'lib/riot/context.rb', line 54

def setups
  @parent.setups + @setups
end

#teardownsArray[Riot::RunnableBlock]

Returns an ordered list of the teardown blocks for the context.

Returns:



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

def teardowns
  @parent.teardowns + @teardowns
end