Skip to content

Commit

Permalink
Fix build for JRuby 9.2.x.x
Browse files Browse the repository at this point in the history
  • Loading branch information
JonRowe committed Dec 6, 2020
1 parent 08ef2ee commit 81b3d13
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 12 deletions.
21 changes: 18 additions & 3 deletions spec/integration/suite_hooks_errors_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
let(:failure_exit_code) { rand(97) + 2 } # 2..99
let(:error_exit_code) { failure_exit_code + 2 } # 4..101

if RSpec::Support::Ruby.jruby_9000?
if RSpec::Support::Ruby.jruby_9000? && RSpec::Support::Ruby.jruby_version > '9.2.0.0'
let(:spec_line_suffix) { ":in `block in <main>'" }
elsif RSpec::Support::Ruby.jruby_9000?
let(:spec_line_suffix) { ":in `block in (root)'" }
elsif RSpec::Support::Ruby.jruby?
let(:spec_line_suffix) { ":in `(root)'" }
Expand Down Expand Up @@ -97,6 +99,19 @@ def run_spec_expecting_non_zero(before_or_after)
end
"

cause =
if RSpec::Support::Ruby.jruby_9000? && RSpec::Support::Ruby.jruby_version > '9.2.0.0'
unindent(<<-EOS)
# ------------------
# --- Caused by: ---
# RuntimeError:
# before 1
# ./the_spec.rb:3:in `block in <main>'
EOS
else
""
end

run_command "the_spec.rb"
expect(last_cmd_exit_status).to eq(error_exit_code)
output = normalize_durations(last_cmd_stdout)
Expand All @@ -116,14 +131,14 @@ def run_spec_expecting_non_zero(before_or_after)
RuntimeError:
after 2
# ./the_spec.rb:6#{spec_line_suffix}
#{ cause }
An error occurred in an `after(:suite)` hook.
Failure/Error: c.after(:suite) { raise 'after 1' }
RuntimeError:
after 1
# ./the_spec.rb:5#{spec_line_suffix}
#{ cause }
Finished in n.nnnn seconds (files took n.nnnn seconds to load)
0 examples, 0 failures, 3 errors occurred outside of examples
Expand Down
27 changes: 18 additions & 9 deletions spec/rspec/core/notifications_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ def normalize_backtraces(failure)
end

def normalize_one_backtrace(exception)
if RSpec::Support::Ruby.jruby_9000? && RSpec::Support::Ruby.jruby_version >= '9.2.0.0'
pending "On JRuby 9.2.x.x these specs are broken due to no backtrace."
end
line = exception.backtrace.find { |l| l.include?(__FILE__) }
exception.set_backtrace([ line.sub(/:in .*$/, '') ])
end
Expand Down Expand Up @@ -117,16 +120,22 @@ def normalize_one_backtrace(exception)
end

context "due to using `:aggregate_failures` metadata" do
let(:exception) do
ex = nil
RSpec.describe do
ex = it "", :aggregate_failures do
expect(1).to fail_with_description("foo")
expect(1).to fail_with_description("bar")
end
end.run
if RSpec::Support::Ruby.jruby_9000? && RSpec::Support::Ruby.jruby_version >= '9.2.0.0'
let(:exception) do
pending "On JRuby 9.2.x.x these specs are broken due to no backtrace."
end
else
let(:exception) do
ex = nil
RSpec.describe do
ex = it "", :aggregate_failures do
expect(1).to fail_with_description("foo")
expect(1).to fail_with_description("bar")
end
end.run

capture_and_normalize_aggregation_error { raise ex.execution_result.exception }
capture_and_normalize_aggregation_error { raise ex.execution_result.exception }
end
end

it 'uses an alternate format for the exception summary to avoid confusing references to the aggregation block or stack trace' do
Expand Down

0 comments on commit 81b3d13

Please sign in to comment.