|
142 | 142 |
|
143 | 143 | it "produces the correct failure message when used in the negative" do |
144 | 144 | as_both_colored_and_uncolored do |color_enabled| |
145 | | - snippet = %|expect("Jennifer").to eq("Marty")| |
| 145 | + snippet = %|expect("Jennifer").not_to eq("Jennifer")| |
146 | 146 | program = make_plain_test_program( |
147 | 147 | snippet, |
148 | 148 | color_enabled: color_enabled, |
149 | 149 | ) |
150 | 150 |
|
151 | 151 | expected_output = build_expected_output( |
152 | 152 | color_enabled: color_enabled, |
153 | | - snippet: %|expect("Jennifer").to eq("Marty")|, |
| 153 | + snippet: %|expect("Jennifer").not_to eq("Jennifer")|, |
154 | 154 | expectation: proc { |
155 | 155 | line do |
156 | 156 | plain "Expected " |
157 | 157 | beta %|"Jennifer"| |
| 158 | + plain " not to eq " |
| 159 | + alpha %|"Jennifer"| |
| 160 | + plain "." |
| 161 | + end |
| 162 | + }, |
| 163 | + ) |
| 164 | + |
| 165 | + expect(program). |
| 166 | + to produce_output_when_run(expected_output). |
| 167 | + in_color(color_enabled) |
| 168 | + end |
| 169 | + end |
| 170 | + end |
| 171 | + |
| 172 | + context "when comparing two different Time instances" do |
| 173 | + it "produces the correct failure message when used in the positive" do |
| 174 | + as_both_colored_and_uncolored do |color_enabled| |
| 175 | + snippet = <<~RUBY |
| 176 | + expected = Time.utc(2011, 12, 13, 14, 15, 16) |
| 177 | + actual = Time.utc(2011, 12, 13, 14, 15, 16, 500_000) |
| 178 | + expect(expected).to eq(actual) |
| 179 | + RUBY |
| 180 | + program = make_plain_test_program( |
| 181 | + snippet, |
| 182 | + color_enabled: color_enabled, |
| 183 | + ) |
| 184 | + |
| 185 | + expected_output = build_expected_output( |
| 186 | + color_enabled: color_enabled, |
| 187 | + snippet: %|expect(expected).to eq(actual)|, |
| 188 | + expectation: proc { |
| 189 | + line do |
| 190 | + plain "Expected " |
| 191 | + beta %|2011-12-13 14:15:16.000 UTC +00:00 (Time)| |
158 | 192 | plain " to eq " |
159 | | - alpha %|"Marty"| |
| 193 | + alpha %|2011-12-13 14:15:16.500 UTC +00:00 (Time)| |
160 | 194 | plain "." |
161 | 195 | end |
162 | 196 | }, |
| 197 | + diff: proc { |
| 198 | + plain_line " #<Time {" |
| 199 | + plain_line " year: 2011," |
| 200 | + plain_line " month: 12," |
| 201 | + plain_line " day: 13," |
| 202 | + plain_line " hour: 14," |
| 203 | + plain_line " min: 15," |
| 204 | + plain_line " sec: 16," |
| 205 | + alpha_line "- nsec: 500000000," |
| 206 | + beta_line "+ nsec: 0," |
| 207 | + plain_line " zone: \"UTC\"," |
| 208 | + plain_line " gmt_offset: 0" |
| 209 | + plain_line " }>" |
| 210 | + }, |
| 211 | + ) |
| 212 | + |
| 213 | + expect(program). |
| 214 | + to produce_output_when_run(expected_output). |
| 215 | + in_color(color_enabled) |
| 216 | + end |
| 217 | + end |
| 218 | + |
| 219 | + it "produces the correct failure message when used in the negative" do |
| 220 | + as_both_colored_and_uncolored do |color_enabled| |
| 221 | + snippet = <<~RUBY |
| 222 | + time = Time.utc(2011, 12, 13, 14, 15, 16) |
| 223 | + expect(time).not_to eq(time) |
| 224 | + RUBY |
| 225 | + program = make_plain_test_program( |
| 226 | + snippet, |
| 227 | + color_enabled: color_enabled, |
| 228 | + ) |
| 229 | + |
| 230 | + expected_output = build_expected_output( |
| 231 | + color_enabled: color_enabled, |
| 232 | + snippet: %|expect(time).not_to eq(time)|, |
| 233 | + newline_before_expectation: true, |
| 234 | + expectation: proc { |
| 235 | + line do |
| 236 | + plain " Expected " |
| 237 | + beta %|2011-12-13 14:15:16.000 UTC +00:00 (Time)| |
| 238 | + end |
| 239 | + |
| 240 | + line do |
| 241 | + plain "not to eq " |
| 242 | + alpha %|2011-12-13 14:15:16.000 UTC +00:00 (Time)| |
| 243 | + end |
| 244 | + }, |
| 245 | + ) |
| 246 | + |
| 247 | + expect(program). |
| 248 | + to produce_output_when_run(expected_output). |
| 249 | + in_color(color_enabled) |
| 250 | + end |
| 251 | + end |
| 252 | + end |
| 253 | + |
| 254 | + context "when comparing two different Time and ActiveSupport::TimeWithZone instances" do |
| 255 | + it "produces the correct failure message when used in the positive" do |
| 256 | + as_both_colored_and_uncolored do |color_enabled| |
| 257 | + snippet = <<~RUBY |
| 258 | + expected = Time.utc(2011, 12, 13, 14, 15, 16) |
| 259 | + actual = Time.utc(2011, 12, 13, 15, 15, 16).in_time_zone("Europe/Stockholm") |
| 260 | + expect(expected).to eq(actual) |
| 261 | + RUBY |
| 262 | + program = make_rspec_rails_test_program( |
| 263 | + snippet, |
| 264 | + color_enabled: color_enabled, |
| 265 | + ) |
| 266 | + |
| 267 | + expected_output = build_expected_output( |
| 268 | + color_enabled: color_enabled, |
| 269 | + snippet: %|expect(expected).to eq(actual)|, |
| 270 | + expectation: proc { |
| 271 | + line do |
| 272 | + plain "Expected " |
| 273 | + beta %|2011-12-13 14:15:16.000 UTC +00:00 (Time)| |
| 274 | + end |
| 275 | + |
| 276 | + line do |
| 277 | + plain " to eq " |
| 278 | + alpha %|2011-12-13 16:15:16.000 CET +01:00 (ActiveSupport::TimeWithZone)| |
| 279 | + end |
| 280 | + }, |
| 281 | + diff: proc { |
| 282 | + plain_line " #<ActiveSupport::TimeWithZone {" |
| 283 | + plain_line " year: 2011," |
| 284 | + plain_line " month: 12," |
| 285 | + plain_line " day: 13," |
| 286 | + alpha_line "- hour: 16," |
| 287 | + beta_line "+ hour: 14," |
| 288 | + plain_line " min: 15," |
| 289 | + plain_line " sec: 16," |
| 290 | + plain_line " nsec: 0," |
| 291 | + alpha_line "- zone: \"CET\"," |
| 292 | + beta_line "+ zone: \"UTC\"," |
| 293 | + alpha_line "- gmt_offset: 3600" |
| 294 | + beta_line "+ gmt_offset: 0" |
| 295 | + plain_line " }>" |
| 296 | + }, |
163 | 297 | ) |
164 | 298 |
|
165 | 299 | expect(program). |
|
0 commit comments