Skip to content

Commit

Permalink
Merge pull request #1019 from rspec/warn_if_pattern_set_after_specs
Browse files Browse the repository at this point in the history
Warn if pattern is set after spec files loaded
  • Loading branch information
soulcutter committed Jul 25, 2013
2 parents 8a90124 + c9f44f7 commit a04fb17
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
11 changes: 11 additions & 0 deletions lib/rspec/core/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,14 @@ def self.add_setting(name, opts={})
# Load files matching this pattern (default: `'**/*_spec.rb'`)
add_setting :pattern, :alias_with => :filename_pattern

def pattern= value
if @spec_files_loaded
Kernel.warn "WARNING: Configuring `pattern` to #{value} has no effect since RSpec has already loaded the spec files. Called from #{caller.first}"
end
@pattern = value
end
alias :filename_pattern= :pattern=

# Report the times for the slowest examples (default: `false`).
# Use this to specify the number of examples to include in the profile.
add_setting :profile_examples
Expand Down Expand Up @@ -192,6 +200,7 @@ def initialize
@color = false
@pattern = '**/*_spec.rb'
@failure_exit_code = 1
@spec_files_loaded = false

@backtrace_cleaner = BacktraceCleaner.new

Expand Down Expand Up @@ -226,6 +235,7 @@ def force(hash)

# @private
def reset
@spec_files_loaded = false
@reporter = nil
@formatters.clear
end
Expand Down Expand Up @@ -846,6 +856,7 @@ def configure_expectation_framework
# @private
def load_spec_files
files_to_run.uniq.each {|f| load File.expand_path(f) }
@spec_files_loaded = true
raise_if_rspec_1_is_loaded
end

Expand Down
16 changes: 16 additions & 0 deletions spec/rspec/core/configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,22 @@ def specify_consistent_ordering_of_files_to_run
expect(config.files_to_run).to include("#{dir}/a_bar.rb")
end
end

context "after files have already been loaded" do
it 'will warn that it will have no effect' do
allow(Kernel).to receive(:warn)
config.load_spec_files
config.send(setter, "rspec/**/*.spec"); line = __LINE__
expect(Kernel).to have_received(:warn).with /has no effect.*#{__FILE__}:#{line}/
end

it 'will not warn if reset is called after load_spec_files' do
config.load_spec_files
config.reset
expect(Kernel).to_not receive(:warn)
config.send(setter, "rspec/**/*.spec")
end
end
end
end

Expand Down

0 comments on commit a04fb17

Please sign in to comment.