Module: Tunit::Assertions
- Included in:
- Test
- Defined in:
- lib/tunit/assertions.rb
Instance Method Summary collapse
- #assert(test, msg = nil) ⇒ Object
- #assert_equal(exp, act, msg = nil) ⇒ Object
- #assert_includes(collection, obj, msg = nil) ⇒ Object
- #assert_instance_of(klass, obj, msg = nil) ⇒ Object
- #assert_respond_to(obj, meth, msg = nil) ⇒ Object
- #refute(test, msg = nil) ⇒ Object
- #refute_equal(exp, act, msg = nil) ⇒ Object
- #refute_includes(collection, obj, msg = nil) ⇒ Object
- #refute_instance_of(klass, obj, msg = nil) ⇒ Object
- #refute_respond_to(obj, meth, msg = nil) ⇒ Object
- #skip(msg = nil, bt = caller) ⇒ Object
Instance Method Details
#assert(test, msg = nil) ⇒ Object
11 12 13 14 15 16 17 18 19 |
# File 'lib/tunit/assertions.rb', line 11 def assert test, msg = nil msg ||= "Failed assertion, no message given." self.assertions += 1 unless test msg = msg.call if Proc === msg fail ::Tunit::Assertion, msg end true end |
#assert_equal(exp, act, msg = nil) ⇒ Object
21 22 23 24 |
# File 'lib/tunit/assertions.rb', line 21 def assert_equal exp, act, msg = nil msg ||= "Failed assertion, no message given." assert exp == act, msg end |
#assert_includes(collection, obj, msg = nil) ⇒ Object
26 27 28 29 30 |
# File 'lib/tunit/assertions.rb', line 26 def assert_includes collection, obj, msg = nil msg ||= "Expected #{collection.inspect} to include #{obj}" assert_respond_to collection, :include? assert collection.include?(obj), msg end |
#assert_instance_of(klass, obj, msg = nil) ⇒ Object
37 38 39 40 |
# File 'lib/tunit/assertions.rb', line 37 def assert_instance_of klass, obj, msg = nil msg ||= "Expected #{obj.inspect} to be an instance of #{klass}, not #{obj.class}" assert obj.instance_of?(klass), msg end |
#assert_respond_to(obj, meth, msg = nil) ⇒ Object
32 33 34 35 |
# File 'lib/tunit/assertions.rb', line 32 def assert_respond_to obj, meth, msg = nil msg ||= "Expected #{obj.inspect} (#{obj.class}) to respond to ##{meth}" assert obj.respond_to?(meth), msg end |
#refute(test, msg = nil) ⇒ Object
42 43 44 45 |
# File 'lib/tunit/assertions.rb', line 42 def refute test, msg = nil msg ||= "Failed assertion, no message given." ! assert !test, msg end |
#refute_equal(exp, act, msg = nil) ⇒ Object
47 48 49 50 |
# File 'lib/tunit/assertions.rb', line 47 def refute_equal exp, act, msg = nil msg ||= "Failed assertion, no message given." refute exp == act, msg end |
#refute_includes(collection, obj, msg = nil) ⇒ Object
52 53 54 55 56 |
# File 'lib/tunit/assertions.rb', line 52 def refute_includes collection, obj, msg = nil msg ||= "Expected #{collection.inspect} to not include #{obj}" assert_respond_to collection, :include? refute collection.include?(obj), msg end |
#refute_instance_of(klass, obj, msg = nil) ⇒ Object
63 64 65 66 |
# File 'lib/tunit/assertions.rb', line 63 def refute_instance_of klass, obj, msg = nil msg ||= "Expected #{obj.inspect} not to be an instance of #{klass}" refute obj.instance_of?(klass), msg end |
#refute_respond_to(obj, meth, msg = nil) ⇒ Object
58 59 60 61 |
# File 'lib/tunit/assertions.rb', line 58 def refute_respond_to obj, meth, msg = nil msg ||= "Expected #{obj.inspect} (#{obj.class}) to not respond to #{meth}" refute obj.respond_to?(meth), msg end |