Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes when given an array as rspec_opt #2704

Merged
merged 2 commits into from Mar 18, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/rspec/core/rake_task.rb
Expand Up @@ -122,7 +122,7 @@ def file_inclusion_specification
if ENV['SPEC']
FileList[ENV['SPEC']].sort
elsif String === pattern && !File.exist?(pattern)
return if rspec_opts =~ /--pattern/
return if [*rspec_opts].any? { |opt| opt =~ /--pattern/ }
Copy link
Member

Choose a reason for hiding this comment

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

Wondering where rspec_opts is coming from. I could only find it being assigned a nil here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's a writable attribute, so it can be set directly on the task

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here's an example using an array.

"--pattern #{escape pattern}"
else
# Before RSpec 3.1, we used `FileList` to get the list of matched
Expand Down
15 changes: 13 additions & 2 deletions spec/rspec/core/rake_task_spec.rb
Expand Up @@ -62,15 +62,26 @@ def spec_command
end

context "with rspec_opts" do
include RSpec::Core::ShellEscape

it "adds the rspec_opts" do
task.rspec_opts = "-Ifoo"
expect(spec_command).to match(/#{task.rspec_path}.*-Ifoo/)
expect(spec_command).to match(/#{task.rspec_path}.*-Ifoo/).and(
include(escape(RSpec::Core::RakeTask::DEFAULT_PATTERN)) # sanity check for following specs
)
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)
exclude(escape(RSpec::Core::RakeTask::DEFAULT_PATTERN))
)
end

it 'behaves properly if rspec_opts is an array' do
task.rspec_opts = %w[--pattern some_specs]
expect(spec_command).to include("--pattern some_specs").and(
exclude(escape(RSpec::Core::RakeTask::DEFAULT_PATTERN))
)
end
end
Expand Down