Class: LiveUnit::TestCase
- Inherits:
-
Object
- Object
- LiveUnit::TestCase
- Includes:
- Minitest::Assertions
- Defined in:
- lib/liveunit/testcase.rb
Overview
all liveunit tests will be a child of LiveUnit::TestCase uses the assertion system from Minitest
Instance Attribute Summary collapse
-
#assertions ⇒ Object
Returns the value of attribute assertions.
Instance Method Summary collapse
-
#initialize(obj_env, obj, myreturn) ⇒ TestCase
constructor
A new instance of TestCase.
-
#me ⇒ Object
returns a cloned version of the object where the methods are defined.
-
#method_missing(m) ⇒ Object
ignore error for not implemented unit tests.
-
#msg(m = "") ⇒ Object
extra msg string for tests.
-
#myreturn ⇒ Object
the unit’s returned value.
-
#passed? ⇒ Boolean
returns true if all our tests has passed.
-
#result_msg ⇒ Object
expectation messages if our tests have failed.
-
#state ⇒ Object
the object’s enviroment, includes constants, instance and class variables.
Methods included from Minitest::Assertions
#assert, #last_result, #results
Constructor Details
#initialize(obj_env, obj, myreturn) ⇒ TestCase
Returns a new instance of TestCase.
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/liveunit/testcase.rb', line 11 def initialize(obj_env, obj, myreturn) @obj_env = obj_env @obj = obj @myreturn = myreturn #for minitest @assertions = 0 @results ||= [] @last_result ||={} @untested = 0 end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(m) ⇒ Object
ignore error for not implemented unit tests
56 57 58 59 60 61 62 |
# File 'lib/liveunit/testcase.rb', line 56 def method_missing(m) if m.to_s =~ /test_/ @untested += 1 else super end end |
Instance Attribute Details
#assertions ⇒ Object
Returns the value of attribute assertions.
9 10 11 |
# File 'lib/liveunit/testcase.rb', line 9 def assertions @assertions end |
Instance Method Details
#me ⇒ Object
returns a cloned version of the object where the methods are defined
28 29 30 |
# File 'lib/liveunit/testcase.rb', line 28 def me @obj end |
#msg(m = "") ⇒ Object
extra msg string for tests
33 34 35 |
# File 'lib/liveunit/testcase.rb', line 33 def msg(m="") @m ||= m end |
#myreturn ⇒ Object
the unit’s returned value
23 24 25 |
# File 'lib/liveunit/testcase.rb', line 23 def myreturn @myreturn end |
#passed? ⇒ Boolean
returns true if all our tests has passed
38 39 40 41 |
# File 'lib/liveunit/testcase.rb', line 38 def passed? results.each { |re| return false unless re[:passed] } true end |
#result_msg ⇒ Object
expectation messages if our tests have failed
44 45 46 47 48 |
# File 'lib/liveunit/testcase.rb', line 44 def result_msg msgs = [] results.each { |re| msgs.push(re[:msg]) unless re[:passed]} msgs end |
#state ⇒ Object
the object’s enviroment, includes constants, instance and class variables
51 52 53 |
# File 'lib/liveunit/testcase.rb', line 51 def state @obj_env end |