|
80 | 80 | refute x.equivalent_to?(y) |
81 | 81 | end |
82 | 82 |
|
83 | | - FirstErrror = Class.new(StandardError) |
| 83 | + FirstError = Class.new(StandardError) |
84 | 84 | SecondError = Class.new(StandardError) |
85 | 85 |
|
86 | 86 | it "compares exception classes" do |
|
92 | 92 | refute x.equivalent_to?(y) |
93 | 93 | end |
94 | 94 |
|
95 | | - it "compares values using a comparator block" do |
| 95 | + it "compares values using a comparator proc" do |
96 | 96 | a = Scientist::Observation.new("test", @experiment) { 1 } |
97 | 97 | b = Scientist::Observation.new("test", @experiment) { "1" } |
98 | 98 |
|
99 | 99 | refute a.equivalent_to?(b) |
100 | | - assert a.equivalent_to?(b) { |x, y| x.to_s == y.to_s } |
| 100 | + |
| 101 | + compare_on_string = -> (x, y) { x.to_s == y.to_s } |
| 102 | + |
| 103 | + assert a.equivalent_to?(b, compare_on_string) |
101 | 104 |
|
102 | 105 | yielded = [] |
103 | | - a.equivalent_to?(b) do |x, y| |
| 106 | + compare_appends = -> (x, y) do |
104 | 107 | yielded << x |
105 | 108 | yielded << y |
106 | 109 | true |
107 | 110 | end |
| 111 | + a.equivalent_to?(b, compare_appends) |
| 112 | + |
108 | 113 | assert_equal [a.value, b.value], yielded |
109 | 114 | end |
110 | 115 |
|
| 116 | + it "compares exceptions using an error comparator proc" do |
| 117 | + x = Scientist::Observation.new("test", @experiment) { raise FirstError, "error" } |
| 118 | + y = Scientist::Observation.new("test", @experiment) { raise SecondError, "error" } |
| 119 | + z = Scientist::Observation.new("test", @experiment) { raise FirstError, "ERROR" } |
| 120 | + |
| 121 | + refute x.equivalent_to?(z) |
| 122 | + refute x.equivalent_to?(y) |
| 123 | + |
| 124 | + compare_on_class = -> (error, other_error) { |
| 125 | + error.class == other_error.class |
| 126 | + } |
| 127 | + compare_on_message = -> (error, other_error) { |
| 128 | + error.message == other_error.message |
| 129 | + } |
| 130 | + |
| 131 | + assert x.equivalent_to?(z, nil, compare_on_class) |
| 132 | + assert x.equivalent_to?(y, nil, compare_on_message) |
| 133 | + end |
| 134 | + |
111 | 135 | describe "#cleaned_value" do |
112 | 136 | it "returns the observation's value by default" do |
113 | 137 | a = Scientist::Observation.new("test", @experiment) { 1 } |
|
0 commit comments