This repository was archived by the owner on Nov 30, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 753
Improve logic that finds the failure line to print. #2088
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
aadd339
Improve logic that finds the failure line to print.
myronmarston 801a48c
Add missing require.
myronmarston a43f596
Fix spec to pass on JRuby.
myronmarston 1f2d437
Use expanded path to begin with so we don’t have to expand it later.
myronmarston 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,158 @@ | ||
require 'support/aruba_support' | ||
|
||
RSpec.describe 'Failed line detection' do | ||
include_context "aruba support" | ||
before { clean_current_dir } | ||
|
||
it "finds the source of a failure in a spec file that is defined at the current directory instead of in the normal `spec` subdir" do | ||
write_file "the_spec.rb", " | ||
RSpec.describe do | ||
it 'fails via expect' do | ||
expect(1).to eq(2) | ||
end | ||
end | ||
" | ||
|
||
run_command "the_spec.rb" | ||
expect(last_cmd_stdout).to include("expect(1).to eq(2)") | ||
end | ||
|
||
it "finds the source of a failure in a spec file loaded by running `ruby file` rather than loaded directly by RSpec" do | ||
write_file "passing_spec.rb", " | ||
RSpec.describe do | ||
example { } | ||
end | ||
" | ||
|
||
write_file "failing_spec.rb", " | ||
RSpec.describe do | ||
it 'fails via expect' do | ||
expect(1).to eq(2) | ||
end | ||
end | ||
" | ||
|
||
file = in_current_dir { "#{Dir.pwd}/failing_spec.rb" } | ||
load file | ||
run_command "passing_spec.rb" | ||
|
||
expect(last_cmd_stdout).to include("expect(1).to eq(2)") | ||
end | ||
|
||
it "finds the direct source of failure in any lib, app or spec file, and allows the user to configure what is considered a project source dir" do | ||
write_file "lib/lib_mod.rb", " | ||
module LibMod | ||
def self.trigger_failure | ||
raise 'LibMod failure' | ||
end | ||
end | ||
" | ||
|
||
write_file "app/app_mod.rb", " | ||
module AppMod | ||
def self.trigger_failure | ||
raise 'AppMod failure' | ||
end | ||
end | ||
" | ||
|
||
write_file "spec/support/spec_support.rb", " | ||
module SpecSupport | ||
def self.trigger_failure | ||
raise 'SpecSupport failure' | ||
end | ||
end | ||
" | ||
|
||
write_file "spec/default_config_spec.rb", " | ||
require './lib/lib_mod' | ||
require './spec/support/spec_support' | ||
require './app/app_mod' | ||
|
||
RSpec.describe do | ||
example('1') { LibMod.trigger_failure } | ||
example('2') { AppMod.trigger_failure } | ||
example('3') { SpecSupport.trigger_failure } | ||
end | ||
" | ||
|
||
run_command "./spec/default_config_spec.rb" | ||
|
||
expect(last_cmd_stdout).to include("raise 'LibMod failure'"). | ||
and include("raise 'AppMod failure'"). | ||
and include("raise 'SpecSupport failure'"). | ||
and exclude("AppMod.trigger_failure") | ||
|
||
write_file "spec/change_config_spec.rb", " | ||
require './app/app_mod' | ||
|
||
RSpec.configure do |c| | ||
c.project_source_dirs = %w[ lib spec ] | ||
end | ||
|
||
RSpec.describe do | ||
example('1') { AppMod.trigger_failure } | ||
end | ||
" | ||
|
||
run_command "./spec/change_config_spec.rb" | ||
|
||
expect(last_cmd_stdout).to include("AppMod.trigger_failure"). | ||
and exclude("raise 'AppMod failure'") | ||
end | ||
|
||
it "finds the callsite of a method provided by a gem that fails (rather than the line in the gem)" do | ||
write_file "vendor/gems/assertions/lib/assertions.rb", " | ||
module Assertions | ||
AssertionFailed = Class.new(StandardError) | ||
|
||
def assert(value, msg) | ||
raise(AssertionFailed, msg) unless value | ||
end | ||
end | ||
" | ||
|
||
write_file "spec/unit/the_spec.rb", " | ||
require './vendor/gems/assertions/lib/assertions' | ||
|
||
RSpec.describe do | ||
include Assertions | ||
|
||
it 'fails via assert' do | ||
assert false, 'failed assertion' | ||
end | ||
|
||
it 'fails via expect' do | ||
expect(1).to eq(2) | ||
end | ||
end | ||
" | ||
|
||
run_command "" | ||
|
||
expect(last_cmd_stdout).to include("assert false, 'failed assertion'"). | ||
and include("expect(1).to eq(2)"). | ||
and exclude("raise(AssertionFailed, msg)") | ||
end | ||
|
||
it "falls back to finding a line in a gem when there are no backtrace lines in the app, lib or spec directories" do | ||
write_file "vendor/gems/before_failure/lib/before_failure.rb", " | ||
RSpec.configure do |c| | ||
c.before { raise 'before failure!' } | ||
end | ||
" | ||
|
||
write_file "spec/unit/the_spec.rb", " | ||
require './vendor/gems/before_failure/lib/before_failure' | ||
|
||
RSpec.describe do | ||
example('1') { } | ||
end | ||
" | ||
|
||
run_command "" | ||
|
||
expect(last_cmd_stdout).to include("c.before { raise 'before failure!' }"). | ||
and exclude("Unable to find matching line from backtrace") | ||
end | ||
end |
This file contains hidden or 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 hidden or 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
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.
neat