Skip to content

Commit

Permalink
refactor configuration so that requires happen before spec files are …
Browse files Browse the repository at this point in the history
…loaded to ensure we can programatically configure pattern

Conflicts:
	lib/rspec/core/configuration_options.rb
  • Loading branch information
JonRowe committed Jul 16, 2013
1 parent c442f14 commit 25d6b3a
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
18 changes: 18 additions & 0 deletions features/command_line/pattern_option.feature
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,21 @@ Feature: pattern option
"""
When I run `rspec --pattern "spec/**/*.spec"`
Then the output should contain "1 example, 0 failures"

Scenario: override the default pattern in configuration
Given a file named "spec/spec_helper.rb" with:
"""ruby
RSpec.configure do |config|
config.pattern << ',**/*.spec'
end
"""
And a file named "spec/example.spec" with:
"""ruby
describe "addition" do
it "adds things" do
(1 + 2).should eq(3)
end
end
"""
When I run `rspec -rspec_helper`
Then the output should contain "1 example, 0 failures"
9 changes: 5 additions & 4 deletions lib/rspec/core/configuration_options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ def initialize(args)

def configure(config)
config.filter_manager = filter_manager
process_options_into config

config.libs = options[:libs] || []
config.setup_load_path_and_require(options[:requires] || [])

process_options_into config
load_formatters_into config
end

Expand All @@ -46,13 +47,13 @@ def filter_manager
private

NON_FORCED_OPTIONS = [
:requires, :libs, :profile, :drb, :files_or_directories_to_run,
:requires, :profile, :drb, :libs, :files_or_directories_to_run,
:line_numbers, :full_description, :full_backtrace, :tty
].to_set

MERGED_OPTIONS = [:requires, :libs].to_set

UNPROCESSABLE_OPTIONS = [:formatters, :requires].to_set
UNPROCESSABLE_OPTIONS = [:libs, :formatters, :requires].to_set

def force?(key)
!NON_FORCED_OPTIONS.include?(key)
Expand All @@ -68,7 +69,7 @@ def order(keys, *ordered)
def process_options_into(config)
opts = options.reject { |k, _| UNPROCESSABLE_OPTIONS.include? k }

order(opts.keys, :libs, :default_path, :pattern).each do |key|
order(opts.keys, :default_path, :pattern).each do |key|
force?(key) ? config.force(key => opts[key]) : config.send("#{key}=", opts[key])
end
end
Expand Down
8 changes: 8 additions & 0 deletions spec/rspec/core/configuration_options_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@
opts.configure(config)
end

it "sends loads requires before loading specs" do
opts = config_options_object(*%w[-rspec_helper])
config = double("config").as_null_object
expect(config).to receive(:setup_load_path_and_require).ordered
expect(config).to receive(:files_or_directories_to_run=).ordered
opts.configure(config)
end

it "sets up load path and requires before formatter" do
opts = config_options_object(*%w[--require a/path -f a/formatter])
config = double("config").as_null_object
Expand Down

0 comments on commit 25d6b3a

Please sign in to comment.