Class: Lemon::TestSetup

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

Overview

Test Subject - Setup and Teardown code.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(context, description, options = {}, &setup) ⇒ TestSetup

New case instance.



20
21
22
23
24
25
26
27
# File 'lib/lemon/test_setup.rb', line 20

def initialize(context, description, options={}, &setup)
  @context      = context
  @description  = description.to_s
  #@singleton   = options[:singleton]
  #@type        = options[:type] || :context
  @setup        = [setup].flatten
  @teardown     = []
end

Instance Attribute Details

#contextObject (readonly)

The test case to which this advice belong.



7
8
9
# File 'lib/lemon/test_setup.rb', line 7

def context
  @context
end

#descriptionObject (readonly)

The description of this concern. Make this as detailed as you wish.



11
12
13
# File 'lib/lemon/test_setup.rb', line 11

def description
  @description
end

#setupObject (readonly)

Setup procedure.



14
15
16
# File 'lib/lemon/test_setup.rb', line 14

def setup
  @setup
end

#teardownObject

Teardown procedure.



17
18
19
# File 'lib/lemon/test_setup.rb', line 17

def teardown
  @teardown
end

Instance Method Details

#run_setup(scope) ⇒ Object

Setup.



35
36
37
38
39
# File 'lib/lemon/test_setup.rb', line 35

def run_setup(scope)
  setup.each do |proc|
    scope.instance_eval(&proc)
  end
end

#run_teardown(scope) ⇒ Object

Teardown.



42
43
44
45
46
# File 'lib/lemon/test_setup.rb', line 42

def run_teardown(scope)
  teardown.each do |proc|
    scope.instance_eval(&proc)
  end
end

#to_sObject

Returns the description with newlines removed.



49
50
51
# File 'lib/lemon/test_setup.rb', line 49

def to_s
  description.gsub(/\n/, ' ')
end