diff --git a/bin/rspecq b/bin/rspecq index 74e5de8..07a2f34 100755 --- a/bin/rspecq +++ b/bin/rspecq @@ -124,6 +124,20 @@ else redis_opts[:host] = opts[:redis_host] end +# Use the RSpec parser to parse any command line args intended for rspec such +# as `-- --format JUnit -o foo.xml` so that we can pass these args to rspec +# while removing the files_or_dirs_to_run since we want to pull those from the +# queue. OptionParser above mutates ARGV, so only options after `--` or +# non-flag arguments (such as files) will make it to this point. +files_or_dirs_to_run = RSpec::Core::Parser.new(ARGV).parse[:files_or_directories_to_run] +l = files_or_dirs_to_run.length +if l.zero? + opts[:rspec_args] = ARGV +else + opts[:rspec_args] = ARGV[0...-l] + opts[:files_or_dirs_to_run] = files_or_dirs_to_run +end + if opts[:report] reporter = RSpecQ::Reporter.new( build_id: opts[:build], @@ -139,7 +153,8 @@ else redis_opts: redis_opts ) - worker.files_or_dirs_to_run = ARGV[0] if ARGV[0] + worker.rspec_args = opts[:rspec_args] + worker.files_or_dirs_to_run = opts[:files_or_dirs_to_run] if opts[:files_or_dirs_to_run] worker.populate_timings = opts[:timings] worker.file_split_threshold = opts[:file_split_threshold] worker.max_requeues = opts[:max_requeues] diff --git a/lib/rspecq/worker.rb b/lib/rspecq/worker.rb index 88362b7..0cb02a0 100644 --- a/lib/rspecq/worker.rb +++ b/lib/rspecq/worker.rb @@ -46,6 +46,11 @@ class Worker # Defaults to 0 attr_accessor :fail_fast + # Optional arguments to pass along to rspec. + # + # Defaults to nil + attr_accessor :rspec_args + attr_reader :queue def initialize(build_id:, worker_id:, redis_opts:) @@ -107,7 +112,8 @@ def work RSpec.configuration.add_formatter(Formatters::JobTimingRecorder.new(queue, job)) end - opts = RSpec::Core::ConfigurationOptions.new(["--format", "progress", job]) + args = [*rspec_args, "--format", "progress", job] + opts = RSpec::Core::ConfigurationOptions.new(args) _result = RSpec::Core::Runner.new(opts).run($stderr, $stdout) queue.acknowledge_job(job) diff --git a/test/sample_suites/tagged_suite/spec/tagged_spec.rb b/test/sample_suites/tagged_suite/spec/tagged_spec.rb new file mode 100644 index 0000000..b3d8f86 --- /dev/null +++ b/test/sample_suites/tagged_suite/spec/tagged_spec.rb @@ -0,0 +1,4 @@ +RSpec.describe do + it("foo", :foo) { expect(true).to be true } + it("bar", :bar) { expect(true).to be true } +end diff --git a/test/test_e2e.rb b/test/test_e2e.rb index b9dc36d..f90846a 100644 --- a/test/test_e2e.rb +++ b/test/test_e2e.rb @@ -129,4 +129,10 @@ def test_suite_with_failures_and_fail_fast assert_includes [2, 3], queue.processed_jobs.length end + + def test_suite_with_rspec_arguments + queue = exec_build("tagged_suite", "-- --tag foo") + + assert_equal 1, queue.example_count + end end