Class: Riot::Context

Inherits:
Object
  • Object
show all
Defined in:
lib/riot/context.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Context.



5
6
7
8
9
10
11
12
# File 'lib/riot/context.rb', line 5

def initialize(description, reporter, parent=nil, &context_block)
  @description, @reporter, @parent = description, reporter, parent
  @assertions = []
  @situation = Situation.new
  bootstrap(@situation)
  instance_eval(&context_block) if block_given? # running the context
  report
end

Instance Attribute Details

#assertionsObject (readonly)

The protein



4
5
6
# File 'lib/riot/context.rb', line 4

def assertions
  @assertions
end

#descriptionObject (readonly)

The protein



4
5
6
# File 'lib/riot/context.rb', line 4

def description
  @description
end

#situationObject (readonly)

The protein



4
5
6
# File 'lib/riot/context.rb', line 4

def situation
  @situation
end

Instance Method Details

#asserts(what, &block) ⇒ Object



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

def asserts(what, &block) add_assertion("asserts #{what}", &block); end

#bootstrap(a_situation) ⇒ Object

Walk it out. Call setup from parent first



15
16
17
18
# File 'lib/riot/context.rb', line 15

def bootstrap(a_situation)
  run_setup(a_situation, &@parent.bootstrap(a_situation)) if @parent
  @setup
end

#context(description, &block) ⇒ Object



32
# File 'lib/riot/context.rb', line 32

def context(description, &block) Context.new(description, @reporter, self, &block); end

#reportObject



20
21
22
# File 'lib/riot/context.rb', line 20

def report
  assertions.each { |assertion| @reporter.process_assertion(assertion) }
end

#setup(&block) ⇒ Object

DSLee stuff



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

def setup(&block)
  run_setup(situation, &(@setup = block))
end

#should(what, &block) ⇒ Object



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

def should(what, &block) add_assertion("should #{what}", &block); end

#to_sObject



24
# File 'lib/riot/context.rb', line 24

def to_s; @to_s ||= [@parent.to_s, @description].join(' ').strip; end