|
1 | 1 | require 'rspec/core/notifications'
|
2 | 2 |
|
| 3 | +# ANSI codes aren't easy to read in failure output, so use tags instead |
| 4 | +class TagColorizer |
| 5 | + def self.wrap(text, code_or_symbol) |
| 6 | + "<#{code_or_symbol}>#{text}</#{code_or_symbol}>" |
| 7 | + end |
| 8 | +end |
| 9 | + |
3 | 10 | RSpec.describe "FailedExampleNotification" do
|
4 | 11 | include FormatterSupport
|
5 | 12 |
|
@@ -32,13 +39,6 @@ def dedent(string)
|
32 | 39 | string.gsub(/^ +\|/, '')
|
33 | 40 | end
|
34 | 41 |
|
35 |
| - # ANSI codes aren't easy to read in failure output, so use tags instead |
36 |
| - class TagColorizer |
37 |
| - def self.wrap(text, code_or_symbol) |
38 |
| - "<#{code_or_symbol}>#{text}</#{code_or_symbol}>" |
39 |
| - end |
40 |
| - end |
41 |
| - |
42 | 42 | context "when the exception is a MultipleExpectationsNotMetError" do
|
43 | 43 | RSpec::Matchers.define :fail_with_description do |desc|
|
44 | 44 | match { false }
|
@@ -357,3 +357,103 @@ module RSpec::Core::Notifications
|
357 | 357 | end
|
358 | 358 | end
|
359 | 359 | end
|
| 360 | + |
| 361 | +module RSpec::Core::Notifications |
| 362 | + RSpec.describe SummaryNotification do |
| 363 | + include FormatterSupport |
| 364 | + |
| 365 | + subject(:notification) do |
| 366 | + summary_notification( |
| 367 | + duration, |
| 368 | + examples, |
| 369 | + failed_examples, |
| 370 | + pending_examples, |
| 371 | + load_time, |
| 372 | + errors_outside_of_examples_count |
| 373 | + ) |
| 374 | + end |
| 375 | + |
| 376 | + let(:duration) do |
| 377 | + 1.23 |
| 378 | + end |
| 379 | + |
| 380 | + let(:examples) do |
| 381 | + [ |
| 382 | + new_example(:status => :passed), |
| 383 | + new_example(:status => :passed) |
| 384 | + ] |
| 385 | + end |
| 386 | + |
| 387 | + let(:failed_examples) do |
| 388 | + examples.select { |example| example.execution_result.status == :failed } |
| 389 | + end |
| 390 | + |
| 391 | + let(:pending_examples) do |
| 392 | + examples.select { |example| example.execution_result.status == :pending } |
| 393 | + end |
| 394 | + |
| 395 | + let(:load_time) do |
| 396 | + 0.1 |
| 397 | + end |
| 398 | + |
| 399 | + let(:errors_outside_of_examples_count) do |
| 400 | + 0 |
| 401 | + end |
| 402 | + |
| 403 | + describe '#fully_formatted' do |
| 404 | + subject(:fully_formatted) do |
| 405 | + notification.fully_formatted(TagColorizer) |
| 406 | + end |
| 407 | + |
| 408 | + context 'when all examples are passed' do |
| 409 | + let(:examples) do |
| 410 | + [ |
| 411 | + new_example(:status => :passed), |
| 412 | + new_example(:status => :passed) |
| 413 | + ] |
| 414 | + end |
| 415 | + |
| 416 | + it 'turns the summary line green' do |
| 417 | + expect(fully_formatted).to include('<green>2 examples, 0 failures</green>') |
| 418 | + end |
| 419 | + end |
| 420 | + |
| 421 | + context "when there're a pending example and no failed example" do |
| 422 | + let(:examples) do |
| 423 | + [ |
| 424 | + new_example(:status => :passed), |
| 425 | + new_example(:status => :pending) |
| 426 | + ] |
| 427 | + end |
| 428 | + |
| 429 | + it 'turns the summary line yellow' do |
| 430 | + expect(fully_formatted).to include('<yellow>2 examples, 0 failures, 1 pending</yellow>') |
| 431 | + end |
| 432 | + end |
| 433 | + |
| 434 | + context "when there're a pending example and a failed example" do |
| 435 | + let(:examples) do |
| 436 | + [ |
| 437 | + new_example(:status => :passed), |
| 438 | + new_example(:status => :pending), |
| 439 | + new_example(:status => :failed) |
| 440 | + ] |
| 441 | + end |
| 442 | + |
| 443 | + it 'turns the summary line red' do |
| 444 | + expect(fully_formatted).to include('<red>3 examples, 1 failure, 1 pending</red>') |
| 445 | + end |
| 446 | + end |
| 447 | + |
| 448 | + context "when there's an error outside of examples" do |
| 449 | + let(:errors_outside_of_examples_count) do |
| 450 | + 1 |
| 451 | + end |
| 452 | + |
| 453 | + it 'turns the summary line red' do |
| 454 | + expect(fully_formatted).to include('<red>2 examples, 0 failures, 1 error occurred outside of examples</red>') |
| 455 | + end |
| 456 | + end |
| 457 | + end |
| 458 | + end |
| 459 | +end |
0 commit comments