Class: Citron::TestProc

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

Overview

Test procedure –what you would call a honest to goodness unit test.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

New unit test procedure.



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

def initialize(options={}, &procedure)
  @context   = options[:context]
  @label     = options[:label]
  @tags      = options[:tags]
  @skip      = options[:skip]
  @file      = options[:file]
  @line      = options[:line]

  @procedure = procedure
  @tested    = false
end

Instance Attribute Details

#contextObject (readonly) Also known as: parent

The parent testcase to which this test belongs.



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

def context
  @context
end

#labelObject (readonly)

Description of test.



36
37
38
# File 'lib/citron/test_proc.rb', line 36

def label
  @label
end

#procedureObject (readonly)

Test procedure, in which test assertions should be made.



47
48
49
# File 'lib/citron/test_proc.rb', line 47

def procedure
  @procedure
end

#tagsObject (readonly)

Symbol list of tags. Trailing element may be Hash of ‘symbol => object`.



42
43
44
# File 'lib/citron/test_proc.rb', line 42

def tags
  @tags
end

Instance Method Details

#callObject

Run this test in context.



145
146
147
148
149
# File 'lib/citron/test_proc.rb', line 145

def call
  @scope.setup
  @scope.instance_eval(&procedure)
  @scope.teardown
end

#for(scope) ⇒ Object

Return copy with ‘@scope` set.



154
155
156
157
# File 'lib/citron/test_proc.rb', line 154

def for(scope)
  @scope = scope
  self.dup
end

#match?(match) ⇒ Boolean

Match test’s label and/or tags.

Parameters:

  • match (String, Symbol, Regexp, Hash)

    Pattern to match against.

Returns:

  • (Boolean)


129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/citron/test_proc.rb', line 129

def match?(match)
  case match
  when Symbol
    tags.include?(match)
  when Hash
    if Hash === tags.last
      tags.last.any?{ |k,v| match[k] == v }
    end
  else
    match === label
  end
end

#skip=(reason) ⇒ Object

Set whether this test should be skipped of not.

Parameters:

  • reason (Boolean, String)

    Reason to skip, or simple boolean flag.



69
70
71
# File 'lib/citron/test_proc.rb', line 69

def skip=(reason)
  @skip = reason
end

#skip?Boolean, String

Whether to skip this test.

Returns:

  • (Boolean, String)


61
# File 'lib/citron/test_proc.rb', line 61

def skip? ; @skip ; end

#source_locationObject

Location of test definition.



117
118
119
# File 'lib/citron/test_proc.rb', line 117

def source_location
  [file, line]
end

#tested=(boolean) ⇒ Object



83
84
85
# File 'lib/citron/test_proc.rb', line 83

def tested=(boolean)
  @tested = !!boolean
end

#tested?Boolean

TODO:

Is this necessary?

Returns:

  • (Boolean)


76
77
78
# File 'lib/citron/test_proc.rb', line 76

def tested?
  @tested
end

#to_sString

Test description.

Returns:

  • (String)


92
93
94
# File 'lib/citron/test_proc.rb', line 92

def to_s
  label.to_s
end