Skip to content
This repository was archived by the owner on Nov 30, 2024. It is now read-only.

Commit 25d6b3a

Browse files
committed
refactor configuration so that requires happen before spec files are loaded to ensure we can programatically configure pattern
Conflicts: lib/rspec/core/configuration_options.rb
1 parent c442f14 commit 25d6b3a

File tree

3 files changed

+31
-4
lines changed

3 files changed

+31
-4
lines changed

features/command_line/pattern_option.feature

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,21 @@ Feature: pattern option
2929
"""
3030
When I run `rspec --pattern "spec/**/*.spec"`
3131
Then the output should contain "1 example, 0 failures"
32+
33+
Scenario: override the default pattern in configuration
34+
Given a file named "spec/spec_helper.rb" with:
35+
"""ruby
36+
RSpec.configure do |config|
37+
config.pattern << ',**/*.spec'
38+
end
39+
"""
40+
And a file named "spec/example.spec" with:
41+
"""ruby
42+
describe "addition" do
43+
it "adds things" do
44+
(1 + 2).should eq(3)
45+
end
46+
end
47+
"""
48+
When I run `rspec -rspec_helper`
49+
Then the output should contain "1 example, 0 failures"

lib/rspec/core/configuration_options.rb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,11 @@ def initialize(args)
2020

2121
def configure(config)
2222
config.filter_manager = filter_manager
23-
process_options_into config
2423

24+
config.libs = options[:libs] || []
2525
config.setup_load_path_and_require(options[:requires] || [])
2626

27+
process_options_into config
2728
load_formatters_into config
2829
end
2930

@@ -46,13 +47,13 @@ def filter_manager
4647
private
4748

4849
NON_FORCED_OPTIONS = [
49-
:requires, :libs, :profile, :drb, :files_or_directories_to_run,
50+
:requires, :profile, :drb, :libs, :files_or_directories_to_run,
5051
:line_numbers, :full_description, :full_backtrace, :tty
5152
].to_set
5253

5354
MERGED_OPTIONS = [:requires, :libs].to_set
5455

55-
UNPROCESSABLE_OPTIONS = [:formatters, :requires].to_set
56+
UNPROCESSABLE_OPTIONS = [:libs, :formatters, :requires].to_set
5657

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

71-
order(opts.keys, :libs, :default_path, :pattern).each do |key|
72+
order(opts.keys, :default_path, :pattern).each do |key|
7273
force?(key) ? config.force(key => opts[key]) : config.send("#{key}=", opts[key])
7374
end
7475
end

spec/rspec/core/configuration_options_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@
2929
opts.configure(config)
3030
end
3131

32+
it "sends loads requires before loading specs" do
33+
opts = config_options_object(*%w[-rspec_helper])
34+
config = double("config").as_null_object
35+
expect(config).to receive(:setup_load_path_and_require).ordered
36+
expect(config).to receive(:files_or_directories_to_run=).ordered
37+
opts.configure(config)
38+
end
39+
3240
it "sets up load path and requires before formatter" do
3341
opts = config_options_object(*%w[--require a/path -f a/formatter])
3442
config = double("config").as_null_object

0 commit comments

Comments
 (0)