Module: Remarkable::Assertions
- Defined in:
- lib/remarkable/assertions.rb
Instance Method Summary collapse
-
#assert_accepts(matcher, target) ⇒ Object
Asserts that the given matcher returns true when
targetis passed to #matches?. -
#assert_rejects(matcher, target) ⇒ Object
Asserts that the given matcher returns false when
targetis passed to #matches?. -
#assert_same_elements(a1, a2, msg = nil) ⇒ Object
Asserts that two arrays contain the same elements, the same number of times.
Instance Method Details
#assert_accepts(matcher, target) ⇒ Object
Asserts that the given matcher returns true when target is passed to #matches?
18 19 20 21 |
# File 'lib/remarkable/assertions.rb', line 18 def assert_accepts(matcher, target) success = matcher.matches?(target) assert_block(matcher.) { success } end |
#assert_rejects(matcher, target) ⇒ Object
Asserts that the given matcher returns false when target is passed to #matches?
24 25 26 27 |
# File 'lib/remarkable/assertions.rb', line 24 def assert_rejects(matcher, target) success = !matcher.matches?(target) assert_block(matcher.) { success } end |
#assert_same_elements(a1, a2, msg = nil) ⇒ Object
Asserts that two arrays contain the same elements, the same number of times. Essentially ==, but unordered.
assert_same_elements([:a, :b, :c], [:c, :a, :b]) => passes
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/remarkable/assertions.rb', line 6 def assert_same_elements(a1, a2, msg = nil) [:select, :inject, :size].each do |m| [a1, a2].each {|a| assert_respond_to(a, m, "Are you sure that #{a.inspect} is an array? It doesn't respond to #{m}.") } end assert a1h = a1.inject({}) { |h,e| h[e] = a1.select { |i| i == e }.size; h } assert a2h = a2.inject({}) { |h,e| h[e] = a2.select { |i| i == e }.size; h } assert_equal(a1h, a2h, msg) end |