Class: Riot::Context

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

Instance Method Summary collapse

Constructor Details

#initialize(description, setups = [], &definition) ⇒ Context

Returns a new instance of Context.



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

def initialize(description, setups=[], &definition)
  @description = description
  @contexts, @setups, @assertions = [], setups, []
  self.instance_eval(&definition)
end

Instance Method Details

#asserts(what, &definition) ⇒ Object



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

def asserts(what, &definition) new_assertion("asserts", what, &definition); end

#asserts_topicObject



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

def asserts_topic; asserts("topic") { topic }; end

#context(description, &definition) ⇒ Object



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

def context(description, &definition)
  # not liking the dup
  @contexts << Context.new("#{@description} #{description}", @setups.dup, &definition)
end

#run(reporter) ⇒ Object



23
24
25
26
27
28
29
30
31
32
# File 'lib/riot/context.rb', line 23

def run(reporter)
  runnables = @setups + @assertions
  reporter.describe_context(@description) unless @assertions.empty?
  situation = Situation.new
  runnables.each do |runnable|
    reporter.report(runnable.to_s, runnable.run(situation))
  end
  @contexts.each { |ctx| ctx.run(reporter) }
  reporter
end

#setup(&definition) ⇒ Object



9
10
11
# File 'lib/riot/context.rb', line 9

def setup(&definition)
  @setups << Setup.new(&definition)
end

#should(what, &definition) ⇒ Object



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

def should(what, &definition) new_assertion("should", what, &definition); end