Skip to content

Commit

Permalink
Pass through RSpec arguments except files
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobthemyth committed Dec 7, 2020
1 parent 5038ca3 commit 75f5d36
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 2 deletions.
16 changes: 15 additions & 1 deletion bin/rspecq
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,19 @@ 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]
if files_or_dirs_to_run.length.zero?
opts[:rspec_args] = ARGV
else
opts[:rspec_args] = ARGV[0...-files_or_dirs_to_run.length]
opts[:files_or_dirs_to_run] = files_or_dirs_to_run
end

if opts[:report]
reporter = RSpecQ::Reporter.new(
build_id: opts[:build],
Expand All @@ -139,7 +152,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]
Expand Down
8 changes: 7 additions & 1 deletion lib/rspecq/worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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:)
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions test/sample_suites/tagged_suite/spec/tagged_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
RSpec.describe do
it("foo", :foo) { expect(true).to be true }
it("bar", :bar) { expect(true).to be true }
end
6 changes: 6 additions & 0 deletions test/test_e2e.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 75f5d36

Please sign in to comment.