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

Don't include default pattern when user specifies their own in Rake task. #2305

Merged
merged 1 commit into from
Jul 28, 2016
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
1 change: 1 addition & 0 deletions lib/rspec/core/rake_task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ def file_inclusion_specification
if ENV['SPEC']
FileList[ENV['SPEC']].sort
elsif String === pattern && !File.exist?(pattern)
return if rspec_opts =~ /--pattern/
"--pattern #{escape pattern}"
else
# Before RSpec 3.1, we used `FileList` to get the list of matched
Expand Down
7 changes: 7 additions & 0 deletions spec/rspec/core/rake_task_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ def spec_command
task.rspec_opts = "-Ifoo"
expect(spec_command).to match(/#{task.rspec_path}.*-Ifoo/)
end

it 'correctly excludes the default pattern if rspec_opts includes --pattern' do
task.rspec_opts = "--pattern some_specs"
expect(spec_command).to include("--pattern some_specs").and(
exclude(RSpec::Core::RakeTask::DEFAULT_PATTERN)
)
end
Copy link
Member

@myronmarston myronmarston Jul 27, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On my initial read of this spec, I expected that it would pass even w/o your change -- after all, it's just showing that --pattern some_specs is included in the command, not that the default one is excluded. After running it locally, I understand it now -- you are showing that the custom pattern comes after the rspec path and the regex has an end-of-line anchor with $ so it does show the default pattern not being included. But it's a very implicit way to show it. How about this instead:

expect(spec_command).to include("--pattern some_specs").and exclude(RSpec::Core::RakeTask::DEFAULT_PATTERN)

IMO, that's much more explicit and easy to understand.

end

context "with pattern" do
Expand Down