Class: Purobu::Test
- Inherits:
-
Object
- Object
- Purobu::Test
- Includes:
- HerokuHelpers
- Defined in:
- lib/purobu/test.rb
Instance Attribute Summary collapse
- #exercise(&block) ⇒ Object
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#setups ⇒ Object
readonly
Returns the value of attribute setups.
-
#teardowns ⇒ Object
readonly
Returns the value of attribute teardowns.
-
#verification ⇒ Object
writeonly
Sets the attribute verification.
Instance Method Summary collapse
-
#initialize(name = nil) ⇒ Test
constructor
A new instance of Test.
- #pass? ⇒ Boolean
- #report_result ⇒ Object
- #reporter ⇒ Object
- #reporter=(new_reporter) ⇒ Object
- #run ⇒ Object
- #setup(&block) ⇒ Object
- #teardown(&block) ⇒ Object
- #verify(&block) ⇒ Object
Methods included from HerokuHelpers
Constructor Details
#initialize(name = nil) ⇒ Test
Returns a new instance of Test.
9 10 11 12 13 14 15 16 |
# File 'lib/purobu/test.rb', line 9 def initialize(name = nil) @setups = [] @exercise = -> {} @verification = -> {} @teardowns = [] @fail = true @name = name end |
Instance Attribute Details
#exercise(&block) ⇒ Object
48 49 50 |
# File 'lib/purobu/test.rb', line 48 def exercise(&block) @exercise = block end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/purobu/test.rb', line 6 def name @name end |
#setups ⇒ Object (readonly)
Returns the value of attribute setups.
6 7 8 |
# File 'lib/purobu/test.rb', line 6 def setups @setups end |
#teardowns ⇒ Object (readonly)
Returns the value of attribute teardowns.
6 7 8 |
# File 'lib/purobu/test.rb', line 6 def teardowns @teardowns end |
#verification=(value) ⇒ Object (writeonly)
Sets the attribute verification
7 8 9 |
# File 'lib/purobu/test.rb', line 7 def verification=(value) @verification = value end |
Instance Method Details
#pass? ⇒ Boolean
40 41 42 |
# File 'lib/purobu/test.rb', line 40 def pass? !@fail end |
#report_result ⇒ Object
68 69 70 71 72 73 74 |
# File 'lib/purobu/test.rb', line 68 def report_result if pass? reporter.report_pass else reporter.report_fail end end |
#reporter ⇒ Object
60 61 62 |
# File 'lib/purobu/test.rb', line 60 def reporter @reporter ||= Reporter.new(self) end |
#reporter=(new_reporter) ⇒ Object
64 65 66 |
# File 'lib/purobu/test.rb', line 64 def reporter=(new_reporter) @reporter = new_reporter end |
#run ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/purobu/test.rb', line 18 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 Purobu.log(teardown: true) do @teardowns.each { |s| s.call } end end rescue => e @fail = true end pass? end |
#setup(&block) ⇒ Object
44 45 46 |
# File 'lib/purobu/test.rb', line 44 def setup(&block) @setups << block end |
#teardown(&block) ⇒ Object
56 57 58 |
# File 'lib/purobu/test.rb', line 56 def teardown(&block) @teardowns << block end |
#verify(&block) ⇒ Object
52 53 54 |
# File 'lib/purobu/test.rb', line 52 def verify(&block) @verification = block end |