Class: Lemon::TestCase::Scope

Inherits:
World
  • Object
show all
Defined in:
lib/lemon/test_case.rb

Instance Method Summary collapse

Constructor Details

#initialize(testcase) ⇒ Scope

, &code)



152
153
154
155
156
157
158
159
160
# File 'lib/lemon/test_case.rb', line 152

def initialize(testcase) #, &code)
  @_testcase = testcase
  @_setup    = testcase.setup
  @_skip     = nil

  extend testcase.context.scope if testcase.context

  #module_eval(&code)
end

Instance Method Details

#after(*matches, &procedure) ⇒ Object Also known as: After

Define a complex after procedure. The #before method allows before procedures to be defined that are triggered by a match against the unit’s target method name or aspect description. This allows groups of tests to be defined that share special teardown code.

Examples:

Method :puts do
  Test "standard output (@stdout)" do
    puts "Hello"
  end

  Before /@stdout/ do
    $stdout = StringIO.new
  end

  After /@stdout/ do
    $stdout = STDOUT
  end
end

Parameters:

  • matches (Array<Symbol,Regexp>)

    List of match critera that must all be matched to trigger the after procedure.



261
262
263
# File 'lib/lemon/test_case.rb', line 261

def after(*matches, &procedure)
  @_testcase.advice[:after][matches] = procedure
end

#before(*matches, &procedure) ⇒ Object Also known as: Before

Define a complex before procedure. The #before method allows before procedures to be defined that are triggered by a match against the unit’s target method name or aspect description. This allows groups of tests to be defined that share special setup code.

Examples:

Method :puts do
  Test "standard output (@stdout)" do
    puts "Hello"
  end

  Before /@stdout/ do
    $stdout = StringIO.new
  end

  After /@stdout/ do
    $stdout = STDOUT
  end
end

Parameters:

  • matches (Array<Symbol,Regexp>)

    List of match critera that must all be matched to trigger the before procedure.



231
232
233
# File 'lib/lemon/test_case.rb', line 231

def before(*matches, &procedure)
  @_testcase.advice[:before][matches] = procedure
end

#setup(description = nil, &procedure) ⇒ Object Also known as: Setup, concern, Concern

Setup is used to set things up for each unit test. The setup procedure is run before each unit.

Parameters:

  • description (String) (defaults to: nil)

    A brief description of what the setup procedure sets-up.



183
184
185
186
187
# File 'lib/lemon/test_case.rb', line 183

def setup(description=nil, &procedure)
  if procedure
    @_setup = TestSetup.new(@test_case, description, &procedure)
  end
end

#teardown(&procedure) ⇒ Object Also known as: Teardown

Teardown procedure is used to clean-up after each unit test.



196
197
198
# File 'lib/lemon/test_case.rb', line 196

def teardown(&procedure)
  @_setup.teardown = procedure
end