Class: Riot::Context

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(description, parent = RootContext.new([],[]), &definition) ⇒ Context

Returns a new instance of Context.



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

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

Instance Attribute Details

#descriptionObject (readonly)

Returns the value of attribute description.



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

def description
  @description
end

Instance Method Details

#asserts(what, &definition) ⇒ Object



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

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

#asserts_topic(what = "topic") ⇒ Object



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

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

#context(description, &definition) ⇒ Object



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

def context(description, &definition)
  @contexts << self.class.new("#{@description} #{description}", self, &definition)
end

#hookup(&definition) ⇒ Object

A setup shortcut that returns the original topic so you don’t have to. Good for nested setups. Instead of doing this in your context:

setup do
  topic.do_something
  topic
end

You would do this:

hookup { topic.do_something } # Yay!


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

def hookup(&definition)
  setup { self.instance_eval(&definition); topic }
end

#run(reporter) ⇒ Object



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

def run(reporter)
  reporter.describe_context(self) unless @assertions.empty?
  local_run(reporter, Situation.new)
  run_sub_contexts(reporter)
  reporter
end

#setup(&definition) ⇒ Object



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

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

#setupsObject



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

def setups; @parent.setups + @setups; end

#should(what, &definition) ⇒ Object



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

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

#teardown(&definition) ⇒ Object



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

def teardown(&definition) (@teardowns << Setup.new(&definition)).last; end

#teardownsObject



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

def teardowns; @parent.teardowns + @teardowns; end