Class: Lemon::TestProc

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

Overview

Test procedure.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(settings = {}, &procedure) ⇒ TestProc

New test procedure.



9
10
11
12
13
14
15
16
17
18
# File 'lib/lemon/test_proc.rb', line 9

def initialize(settings={}, &procedure)
  @context = settings[:context]
  @setup   = settings[:setup]
  @label   = settings[:label]
  @skip    = settings[:skip]

  @procedure = procedure

  @tested    = false
end

Instance Attribute Details

#contextObject (readonly)

The parent case to which this test belongs.



23
24
25
# File 'lib/lemon/test_proc.rb', line 23

def context
  @context
end

#labelObject (readonly)

Description of test.



29
30
31
# File 'lib/lemon/test_proc.rb', line 29

def label
  @label
end

#procedureObject (readonly)

Test procedure, in which test assertions should be made.



32
33
34
# File 'lib/lemon/test_proc.rb', line 32

def procedure
  @procedure
end

#setupObject (readonly)

Setup and teardown procedures.



26
27
28
# File 'lib/lemon/test_proc.rb', line 26

def setup
  @setup
end

#skipObject

Returns the value of attribute skip.



43
44
45
# File 'lib/lemon/test_proc.rb', line 43

def skip
  @skip
end

#testedObject

Has this test been executed?



51
52
53
# File 'lib/lemon/test_proc.rb', line 51

def tested
  @tested
end

Instance Method Details

#argumentsObject

TODO: handle parameterized tests



87
88
89
# File 'lib/lemon/test_proc.rb', line 87

def arguments
  []
end

#callObject



104
105
106
107
108
109
110
# File 'lib/lemon/test_proc.rb', line 104

def call
  context.run(self) do
    setup.run_setup(scope)    if setup
    scope.instance_exec(*arguments, &procedure)
    setup.run_teardown(scope) if setup
  end
end

#match?(match) ⇒ Boolean

Returns:

  • (Boolean)


99
100
101
# File 'lib/lemon/test_proc.rb', line 99

def match?(match)    
  match == target || match === description
end

#scopeObject



113
114
115
# File 'lib/lemon/test_proc.rb', line 113

def scope
  context.scope
end

#skip?Boolean

Don’t run test?

Returns:

  • (Boolean)


46
47
48
# File 'lib/lemon/test_proc.rb', line 46

def skip?
  @skip
end

#targetObject

Target method of context.



38
39
40
# File 'lib/lemon/test_proc.rb', line 38

def target
  context.target
end

#to_procObject



92
93
94
95
96
# File 'lib/lemon/test_proc.rb', line 92

def to_proc
  lambda do
    call
  end
end

#to_sObject Also known as: name

Test label.



54
55
56
# File 'lib/lemon/test_proc.rb', line 54

def to_s
  label.to_s
end

#topicObject

Ruby Test looks for #topic as the description of test setup.



61
62
63
# File 'lib/lemon/test_proc.rb', line 61

def topic
  setup.to_s
end