Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default example status to unknown if corrupt #2360

Merged
merged 3 commits into from
Mar 27, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion lib/rspec/core/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -980,7 +980,9 @@ def last_run_statuses
if (path = example_status_persistence_file_path)
begin
ExampleStatusPersister.load_from(path).inject(statuses) do |hash, example|
hash[example.fetch(:example_id)] = example.fetch(:status)
status = example[:status]
status = UNKNOWN_STATUS unless VALID_STATUSES.include?(status)
hash[example.fetch(:example_id)] = status
hash
end
rescue SystemCallError => e
Expand All @@ -1000,6 +1002,12 @@ def last_run_statuses
# @private
FAILED_STATUS = "failed".freeze

# @private
PASSED_STATUS = "passed".freeze

# @private
VALID_STATUSES = [UNKNOWN_STATUS, FAILED_STATUS, PASSED_STATUS]

# @private
def spec_files_with_failures
@spec_files_with_failures ||= last_run_statuses.inject(Set.new) do |files, (id, status)|
Expand Down
38 changes: 38 additions & 0 deletions spec/rspec/core/configuration/only_failures_support_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,44 @@ def spec_files_with_failures
end
end

context 'when the file at `example_status_persistence_file_path` is corrupt' do
before do
simulate_persisted_examples(
{ :example_id => "./spec_1.rb[1:1]" },
{ :example_id => "./spec_1.rb[1:2]", :status => "" },
{ :example_id => "./spec_2.rb[1:2]", :status => nil },
{ :example_id => "./spec_3.rb[1:2]", :status => "wrong" },
{ :example_id => "./spec_4.rb[1:2]", :status => "unknown" },
:example_id => "./spec_5.rb[1:2]", :status => "failed"
)
end

it 'should not crash' do
Array.new(9) do |i|
RSpec.describe("group") { it "example #{i}" do; end }
end
expectation = expect do
RSpec.world.example_groups
end
expectation.not_to raise_error
end
it 'should default invalid statuses to unknown' do
expect(spec_files_with_failures).to(
be_an(Array) &
contain_exactly("./spec_5.rb")
)
# Check that each example has the correct status
expect(config.last_run_statuses).to eq(
'./spec_1.rb[1:1]' => 'unknown',
'./spec_1.rb[1:2]' => 'unknown',
'./spec_2.rb[1:2]' => 'unknown',
'./spec_3.rb[1:2]' => 'unknown',
'./spec_4.rb[1:2]' => 'unknown',
'./spec_5.rb[1:2]' => 'failed'
)
end
end

context "when `example_status_persistence_file_path` is not configured" do
it "returns a memoized blank array" do
config.example_status_persistence_file_path = nil
Expand Down
1 change: 0 additions & 1 deletion spec/rspec/core/configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
require 'rspec/support/spec/in_sub_process'

module RSpec::Core

RSpec.describe Configuration do
include RSpec::Support::InSubProcess

Expand Down