Module: Homeschool::StandardizedTest::Assertions::InstanceMethods
- Defined in:
- lib/standardized_test.rb
Class Method Summary collapse
Instance Method Summary collapse
- #assert_equal_with_diffing(expected, actual, message = nil) ⇒ Object
- #assert_fails(message = "") ⇒ Object
- #diff(one, two) ⇒ Object
- #diff_format(string, prefix) ⇒ Object
Class Method Details
.included(klass) ⇒ Object
37 38 39 40 |
# File 'lib/standardized_test.rb', line 37 def self.included(klass) klass.send :alias_method, :assert_equal_without_diffing, :assert_equal klass.send :alias_method, :assert_equal, :assert_equal_with_diffing end |
Instance Method Details
#assert_equal_with_diffing(expected, actual, message = nil) ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/standardized_test.rb', line 29 def assert_equal_with_diffing(expected, actual, =nil) if == :diff assert_block(diff(expected, actual)) {expected == actual} else assert_equal_without_diffing(expected, actual, ) end end |
#assert_fails(message = "") ⇒ Object
5 6 7 8 9 10 11 |
# File 'lib/standardized_test.rb', line 5 def assert_fails(="") yield passed = true rescue ensure assert !passed, end |
#diff(one, two) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/standardized_test.rb', line 13 def diff(one, two) prefix = 0 (0...[one, two].min_by(&:length).length).each do |i| if one[i] == two[i] prefix = i + 1 else break end end "Expected <#{diff_format(one, prefix)}> but was <#{diff_format(two, prefix)}>" end |
#diff_format(string, prefix) ⇒ Object
25 26 27 |
# File 'lib/standardized_test.rb', line 25 def diff_format(string, prefix) prefix > 0 ? "...#{string[prefix..-1]}" : string end |