Class: Simmer::Configuration::CallbackDsl

Inherits:
Object
  • Object
show all
Defined in:
lib/simmer/configuration/callback_dsl.rb

Overview

Defines lifecycle hooks which can be run before and after the entire suite or just a single test. Very similar to Rspec (relishapp.com/rspec/rspec-core/v/3-9/docs/hooks/before-and-after-hooks).

Instance Method Summary collapse

Constructor Details

#initializeCallbackDsl

Returns a new instance of CallbackDsl.



16
17
18
19
20
21
22
23
# File 'lib/simmer/configuration/callback_dsl.rb', line 16

def initialize
  @before_suite = []
  @after_suite = []
  @before_each = []
  @after_each = []

  freeze
end

Instance Method Details

#after(level = LEVEL_EACH, &block) ⇒ Object

Used to create an after callback. This accepts and optional level parameter which can either be :suite or :each. “:each” is implied if no level is provided.



37
38
39
40
41
# File 'lib/simmer/configuration/callback_dsl.rb', line 37

def after(level = LEVEL_EACH, &block)
  verify_level!(level)

  level == LEVEL_SUITE ? after_suite.push(block) : after_each.push(block)
end

#before(level = LEVEL_EACH, &block) ⇒ Object

Used to create a before callback. This accepts and optional level parameter which can either be :suite or :each. “:each” is implied if no level is provided.



28
29
30
31
32
# File 'lib/simmer/configuration/callback_dsl.rb', line 28

def before(level = LEVEL_EACH, &block)
  verify_level!(level)

  level == LEVEL_SUITE ? before_suite.push(block) : before_each.push(block)
end

#run_single_test_with_callbacksObject

:nodoc:



44
45
46
47
48
49
50
51
52
# File 'lib/simmer/configuration/callback_dsl.rb', line 44

def run_single_test_with_callbacks
  before_each.each(&:call)

  result = yield

  after_each.each { |block| block.call(result) }

  result
end

#run_suite_with_callbacksObject

:nodoc:



55
56
57
58
59
60
61
62
63
# File 'lib/simmer/configuration/callback_dsl.rb', line 55

def run_suite_with_callbacks
  before_suite.each(&:call)

  result = yield

  after_suite.each { |block| block.call(result) }

  result
end