-
Notifications
You must be signed in to change notification settings - Fork 24
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
Allow passing through RSpec arguments #47
base: master
Are you sure you want to change the base?
Changes from 1 commit
75f5d36
a20a635
28c576c
2d08373
68e4442
8a3e7df
8687720
74202f3
b9c5763
5316d7c
8c714a1
d5c165d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we simply do |
||
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], | ||
|
@@ -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] | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now that we accept a |
||
opts = RSpec::Core::ConfigurationOptions.new(args) | ||
_result = RSpec::Core::Runner.new(opts).run($stderr, $stdout) | ||
|
||
queue.acknowledge_job(job) | ||
|
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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To be on the safe side, I think we should test for more things here. A few thoughts:
|
||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So there are some disparities compared to what the
rspec
binary accepts, which makes me a bit skeptical about this approach.For example, the following works in RSpec:
while the same doesn't work with RSpecQ:
That said, putting the flags before the files to execute works fine.