Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add config option for example status persistence file path.
  • Loading branch information
myronmarston committed Mar 10, 2015
1 parent 597b9fd commit ee490cc
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -19,3 +19,4 @@ Gemfile-custom
.idea
bundle
.rspec-local
examples.txt
2 changes: 2 additions & 0 deletions lib/rspec/core.rb
Expand Up @@ -146,6 +146,8 @@ def self.world

# Namespace for the rspec-core code.
module Core
autoload :ExampleStatusPersister, "rspec/core/example_status_persister"

# @private
# This avoids issues with reporting time caused by examples that
# change the value/meaning of Time.now without properly restoring
Expand Down
4 changes: 4 additions & 0 deletions lib/rspec/core/configuration.rb
Expand Up @@ -154,6 +154,10 @@ def deprecation_stream=(value)
end
end

# @macro add_setting
# Sets a file path to use for persisting example statuses.
add_setting :example_status_persistence_file_path

# @macro add_setting
# Clean up and exit after the first failure (default: `false`).
add_setting :fail_fast
Expand Down
15 changes: 14 additions & 1 deletion lib/rspec/core/runner.rb
Expand Up @@ -83,7 +83,9 @@ def initialize(options, configuration=RSpec.configuration, world=RSpec.world)
# @param out [IO] output stream
def run(err, out)
setup(err, out)
run_specs(@world.ordered_example_groups)
run_specs(@world.ordered_example_groups).tap do
persist_example_statuses
end
end

# Wires together the various configuration objects and state holders.
Expand Down Expand Up @@ -112,6 +114,17 @@ def run_specs(example_groups)
end
end

private

def persist_example_statuses
return unless @configuration.example_status_persistence_file_path

ExampleStatusPersister.persist(
@world.all_examples,
@configuration.example_status_persistence_file_path
)
end

# @private
def self.disable_autorun!
@autorun_disabled = true
Expand Down
30 changes: 30 additions & 0 deletions spec/rspec/core/runner_spec.rb
Expand Up @@ -236,6 +236,36 @@ def run_specs
end
end

describe "persistence of example statuses" do
let(:all_examples) { [double("example")] }

def run
allow(world).to receive(:all_examples).and_return(all_examples)
allow(config).to receive(:load_spec_files)

class_spy(ExampleStatusPersister).as_stubbed_const

runner = build_runner
runner.run(err, out)
end

context "when `example_status_persistence_file_path` is configured" do
it 'persists the status of all loaded examples' do
config.example_status_persistence_file_path = "examples.txt"
run
expect(ExampleStatusPersister).to have_received(:persist).with(all_examples, "examples.txt")
end
end

context "when `example_status_persistence_file_path` is not configured" do
it 'persists the status of all loaded examples' do
config.example_status_persistence_file_path = nil
run
expect(ExampleStatusPersister).not_to have_received(:persist)
end
end
end

context "running files" do
include_context "spec files"

Expand Down
2 changes: 2 additions & 0 deletions spec/spec_helper.rb
Expand Up @@ -56,6 +56,8 @@ def without_env_vars(*vars)
end

RSpec.configure do |c|
c.example_status_persistence_file_path = "./examples.txt"

# structural
c.alias_it_behaves_like_to 'it_has_behavior'
c.include(RSpecHelpers)
Expand Down

0 comments on commit ee490cc

Please sign in to comment.