-
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
Open
jacobthemyth
wants to merge
12
commits into
skroutz:master
Choose a base branch
from
Kajabi:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+149
−2
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
75f5d36
Pass through RSpec arguments except files
jacobthemyth a20a635
WIP formatter output with job id
rwc9u 28c576c
Add suite to filename when option is set.
rwc9u 2d08373
Fix counter.
rwc9u 68e4442
Add junit formatter.
rwc9u 8a3e7df
Cleanup debugging.
rwc9u 8687720
Add support for rspec parallel multiple files.
rwc9u 74202f3
Add ability to define formatter file name and path.
rwc9u b9c5763
Rename junit-formatter option to junit-output.
rwc9u 5316d7c
Merge pull request #1 from Kajabi/add-job-to-junit-file
rwc9u 8c714a1
Fixes gemspec dependency ordering
prsimp d5c165d
Merge remote-tracking branch 'upstream/master'
prsimp File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -103,6 +103,13 @@ OptionParser.new do |o| | |
opts[:fail_fast] = v | ||
end | ||
|
||
o.on("--junit-output filepath", String, "Output junit formatted xml " \ | ||
"for CI suites to the defined file path. Substitution parameters " \ | ||
"{{TEST_ENV_NUMBER}} - parallel gem proc number. " \ | ||
"{{JOB_INDEX}} - increments with each suite that is run.") do |v| | ||
opts[:junit_output] = v | ||
end | ||
|
||
o.on("--reproduction", "Enable reproduction mode: run rspec on the given files " \ | ||
"and examples in the exact order they are given. Incompatible with " \ | ||
"--timings.") do |v| | ||
|
@@ -140,6 +147,7 @@ opts[:queue_wait_timeout] ||= Integer(ENV["RSPECQ_QUEUE_WAIT_TIMEOUT"] || DEFAUL | |
opts[:redis_url] ||= ENV["RSPECQ_REDIS_URL"] | ||
opts[:fail_fast] ||= Integer(ENV["RSPECQ_FAIL_FAST"] || DEFAULT_FAIL_FAST) | ||
opts[:reproduction] ||= env_set?("RSPECQ_REPRODUCTION") | ||
opts[:junit_output] ||= ENV["RSPECQ_JUNIT_OUTPUT"] | ||
|
||
# rubocop:disable Style/RaiseArgs | ||
raise OptionParser::MissingArgument.new(:build) if opts[:build].nil? | ||
|
@@ -156,6 +164,19 @@ end | |
|
||
Sentry.init if ENV["SENTRY_DSN"] | ||
|
||
# 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], | ||
|
@@ -172,7 +193,8 @@ else | |
redis_opts: redis_opts | ||
) | ||
|
||
worker.files_or_dirs_to_run = ARGV if ARGV.any? | ||
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] | ||
|
@@ -181,5 +203,6 @@ else | |
worker.seed = Integer(opts[:seed]) if opts[:seed] | ||
worker.reproduction = opts[:reproduction] | ||
worker.tags = opts[:tags] | ||
worker.junit_output = opts[:junit_output] | ||
worker.work | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
require "rspec_junit_formatter" | ||
|
||
module RSpecQ | ||
module Formatters | ||
# Junit output formatter that handles outputting of requeued examples, | ||
# parallel gem, and multiple suites per rspecq run. | ||
class JUnitFormatter < RSpecJUnitFormatter | ||
def initialize(queue, job, max_requeues, job_index, path) | ||
@queue = queue | ||
@job = job | ||
@max_requeues = max_requeues | ||
@requeued_examples = [] | ||
path = path.gsub(/{{TEST_ENV_NUMBER}}/,ENV["TEST_ENV_NUMBER"].to_s) | ||
path = path.gsub(/{{JOB_INDEX}}/, job_index.to_s) | ||
RSpec::Support::DirectoryMaker.mkdir_p(File.dirname(path)) | ||
output_file = File.new(path, "w") | ||
super(output_file) | ||
end | ||
|
||
def example_failed(notification) | ||
# if it is requeued, store the notification | ||
if @queue.requeueable_job?(notification.example.id, @max_requeues) | ||
@requeued_examples << notification.example | ||
end | ||
end | ||
|
||
private | ||
|
||
def example_count | ||
@summary_notification.example_count - @requeued_examples.size | ||
end | ||
|
||
def failure_count | ||
@summary_notification.failure_count - @requeued_examples.size | ||
end | ||
|
||
def examples | ||
@examples_notification.notifications.reject do |example_notification| | ||
@requeued_examples.map(&:id).include?(example_notification.example.id) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,12 @@ | ||
require "test_helpers" | ||
|
||
class TestEndToEnd < RSpecQTest | ||
def after_teardown | ||
Dir["./test/sample_suites/flakey_suite/test/test_results/**/*"].each do |file| | ||
File.delete(file) | ||
end | ||
end | ||
|
||
def test_suite_with_legit_failures | ||
queue = exec_build("failing_suite") | ||
|
||
|
@@ -129,4 +135,26 @@ 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:
|
||
|
||
def test_suite_with_junit_output | ||
queue = exec_build("flakey_suite", | ||
"--junit-output test/test_results/test.{{JOB_INDEX}}.xml") | ||
|
||
assert queue.build_successful? | ||
assert_processed_jobs [ | ||
"./spec/foo_spec.rb", | ||
"./spec/foo_spec.rb[1:1]", | ||
], queue | ||
|
||
assert_equal({ "./spec/foo_spec.rb[1:1]" => "2" }, queue.requeued_jobs) | ||
assert File.exist?("test/sample_suites/flakey_suite/test/test_results/test.0.xml") | ||
assert File.exist?("test/sample_suites/flakey_suite/test/test_results/test.1.xml") | ||
assert File.exist?("test/sample_suites/flakey_suite/test/test_results/test.2.xml") | ||
end | ||
end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.