Module: Kintama::Assertions
- Included in:
- Test
- Defined in:
- lib/kintama/assertions.rb
Instance Method Summary collapse
- #assert(expression, message = "failed") ⇒ Object
- #assert_equal(expected, actual, message = "Expected #{expected.inspect} but got #{actual.inspect}") ⇒ Object
- #assert_kind_of(klass, thing, message = "should be a kind of #{klass}") ⇒ Object
- #assert_match(regexp, string, message = "expected #{string.inspect} to match #{regexp.inspect}") ⇒ Object
- #assert_nil(object, message = "#{object.inspect} was not nil") ⇒ Object
- #assert_not_equal(expected, actual, message = "Expected #{expected.inspect} to not be equal to #{actual.inspect}") ⇒ Object
- #assert_not_nil(object, message = "should not be nil") ⇒ Object
- #assert_nothing_raised(message = "should not raise anything", &block) ⇒ Object
- #assert_raises(klass_or_message = Exception, message = "should raise an exception", &block) ⇒ Object
- #assert_same_elements(expected, object, message = "#{object.inspect} does not contain the same elements as #{expected.inspect}") ⇒ Object
- #flunk(message = "flunked.") ⇒ Object
Instance Method Details
#assert(expression, message = "failed") ⇒ Object
5 6 7 |
# File 'lib/kintama/assertions.rb', line 5 def assert(expression, ="failed") raise Kintama::TestFailure, unless expression end |
#assert_equal(expected, actual, message = "Expected #{expected.inspect} but got #{actual.inspect}") ⇒ Object
13 14 15 |
# File 'lib/kintama/assertions.rb', line 13 def assert_equal(expected, actual, ="Expected #{expected.inspect} but got #{actual.inspect}") assert actual == expected, end |
#assert_kind_of(klass, thing, message = "should be a kind of #{klass}") ⇒ Object
33 34 35 |
# File 'lib/kintama/assertions.rb', line 33 def assert_kind_of(klass, thing, ="should be a kind of #{klass}") assert thing.is_a?(klass), end |
#assert_match(regexp, string, message = "expected #{string.inspect} to match #{regexp.inspect}") ⇒ Object
29 30 31 |
# File 'lib/kintama/assertions.rb', line 29 def assert_match(regexp, string, ="expected #{string.inspect} to match #{regexp.inspect}") assert (string =~ regexp), end |
#assert_nil(object, message = "#{object.inspect} was not nil") ⇒ Object
21 22 23 |
# File 'lib/kintama/assertions.rb', line 21 def assert_nil(object, ="#{object.inspect} was not nil") assert_equal nil, object, end |
#assert_not_equal(expected, actual, message = "Expected #{expected.inspect} to not be equal to #{actual.inspect}") ⇒ Object
17 18 19 |
# File 'lib/kintama/assertions.rb', line 17 def assert_not_equal(expected, actual, ="Expected #{expected.inspect} to not be equal to #{actual.inspect}") assert actual != expected, end |
#assert_not_nil(object, message = "should not be nil") ⇒ Object
25 26 27 |
# File 'lib/kintama/assertions.rb', line 25 def assert_not_nil(object, ="should not be nil") assert_not_equal nil, object, end |
#assert_nothing_raised(message = "should not raise anything", &block) ⇒ Object
41 42 43 44 45 |
# File 'lib/kintama/assertions.rb', line 41 def assert_nothing_raised(="should not raise anything", &block) yield rescue Exception => e raise Kintama::TestFailure, + " (#{e} was raised)" end |
#assert_raises(klass_or_message = Exception, message = "should raise an exception", &block) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/kintama/assertions.rb', line 47 def assert_raises(=Exception, ="should raise an exception", &block) if .respond_to?(:ancestors) klass = else = klass = Exception end yield raised = false rescue => e if e.class.ancestors.include?(klass) raised = true else raised = false end ensure raise Kintama::TestFailure, unless raised end |
#assert_same_elements(expected, object, message = "#{object.inspect} does not contain the same elements as #{expected.inspect}") ⇒ Object
37 38 39 |
# File 'lib/kintama/assertions.rb', line 37 def assert_same_elements(expected, object, = "#{object.inspect} does not contain the same elements as #{expected.inspect}") assert Set.new(expected) == Set.new(object), end |
#flunk(message = "flunked.") ⇒ Object
9 10 11 |
# File 'lib/kintama/assertions.rb', line 9 def flunk(="flunked.") assert false, end |