diff --git a/lib/rspec/core/rake_task.rb b/lib/rspec/core/rake_task.rb index 7f01eab4f3..8cf474a94f 100644 --- a/lib/rspec/core/rake_task.rb +++ b/lib/rspec/core/rake_task.rb @@ -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/ } "--pattern #{escape pattern}" else # Before RSpec 3.1, we used `FileList` to get the list of matched diff --git a/spec/rspec/core/rake_task_spec.rb b/spec/rspec/core/rake_task_spec.rb index 06a28e7f6b..576b8637d0 100644 --- a/spec/rspec/core/rake_task_spec.rb +++ b/spec/rspec/core/rake_task_spec.rb @@ -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