Class: Purobu::Test

Inherits:
Object
  • Object
show all
Defined in:
lib/purobu/test.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name = nil) ⇒ Test

Returns a new instance of Test.



7
8
9
10
11
12
13
14
# File 'lib/purobu/test.rb', line 7

def initialize(name = nil)
  @setups       = []
  @exercise     = -> {}
  @verification = -> {}
  @teardowns    = []
  @fail         = true
  @name         = name
end

Instance Attribute Details

#exercise(&block) ⇒ Object



47
48
49
# File 'lib/purobu/test.rb', line 47

def exercise(&block)
  @exercise = block
end

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'lib/purobu/test.rb', line 4

def name
  @name
end

#setupsObject (readonly)

Returns the value of attribute setups.



4
5
6
# File 'lib/purobu/test.rb', line 4

def setups
  @setups
end

#teardownsObject (readonly)

Returns the value of attribute teardowns.



4
5
6
# File 'lib/purobu/test.rb', line 4

def teardowns
  @teardowns
end

#verification=(value) ⇒ Object (writeonly)

Sets the attribute verification

Parameters:

  • value

    the value to set the attribute verification to.



5
6
7
# File 'lib/purobu/test.rb', line 5

def verification=(value)
  @verification = value
end

Instance Method Details

#pass?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/purobu/test.rb', line 39

def pass?
  !@fail
end

#report_resultObject



67
68
69
70
71
72
73
# File 'lib/purobu/test.rb', line 67

def report_result
  if pass?
    reporter.report_pass
  else
    reporter.report_fail
  end
end

#reporterObject



59
60
61
# File 'lib/purobu/test.rb', line 59

def reporter
  @reporter ||= Reporter.new(self)
end

#reporter=(new_reporter) ⇒ Object



63
64
65
# File 'lib/purobu/test.rb', line 63

def reporter=(new_reporter)
  @reporter = new_reporter
end

#runObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/purobu/test.rb', line 16

def run
  begin
    Purobu.log_context(test: name) do
      Purobu.log(setups: true) do
        @setups.each { |s| s.call }
      end
      Purobu.log(exercise: true) do
        @exercise.call
      end
      Purobu.log(verification: true) do
        @fail = !@verification.call
      end
    end
  rescue
    @fail = true
  ensure
    Purobu.log(teardown: true) do
      @teardowns.each { |s| s.call }
    end
  end
  pass?
end

#setup(&block) ⇒ Object



43
44
45
# File 'lib/purobu/test.rb', line 43

def setup(&block)
  @setups << block
end

#teardown(&block) ⇒ Object



55
56
57
# File 'lib/purobu/test.rb', line 55

def teardown(&block)
  @teardowns << block
end

#verify(&block) ⇒ Object



51
52
53
# File 'lib/purobu/test.rb', line 51

def verify(&block)
  @verification = block
end