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
19
# File 'lib/lemon/test_proc.rb', line 9

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

  @procedure = procedure

  @tested    = false
end

Instance Attribute Details

#contextObject (readonly)

The parent case to which this test belongs.



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

def context
  @context
end

#labelObject (readonly)

Description of test.



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

def label
  @label
end

#procedureObject (readonly)

Test procedure, in which test assertions should be made.



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

def procedure
  @procedure
end

#setupObject (readonly)

Setup and teardown procedures.



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

def setup
  @setup
end

#skipObject

Returns the value of attribute skip.



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

def skip
  @skip
end

#testedObject

Has this test been executed?



63
64
65
# File 'lib/lemon/test_proc.rb', line 63

def tested
  @tested
end

Instance Method Details

#argumentsObject

TODO: handle parameterized tests



105
106
107
# File 'lib/lemon/test_proc.rb', line 105

def arguments
  []
end

#callObject

Run the test.



128
129
130
131
132
133
134
# File 'lib/lemon/test_proc.rb', line 128

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)


121
122
123
# File 'lib/lemon/test_proc.rb', line 121

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

#scopeObject



139
140
141
# File 'lib/lemon/test_proc.rb', line 139

def scope
  context.scope
end

#skip?Boolean

Don’t run test?

Returns:

  • (Boolean)


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

def skip?
  @skip
end

#tagsObject



58
59
60
# File 'lib/lemon/test_proc.rb', line 58

def tags
  @tags
end

#targetObject

Target method of context.



41
42
43
# File 'lib/lemon/test_proc.rb', line 41

def target
  context.target
end

#to_procObject



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

def to_proc
  lambda do
    call
  end
end

#to_sObject Also known as: name

Test label.



68
69
70
# File 'lib/lemon/test_proc.rb', line 68

def to_s
  label.to_s
end

#topicObject

TODO:

This may be deprecated in future RubyTest.

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



79
80
81
# File 'lib/lemon/test_proc.rb', line 79

def topic
  setup.to_s
end