Permalink
Browse files

Fix bug with autotest failure-matching where it missed cases in which

the spec file wasn't the first line in the backtrace.

- Closes #178.
  • Loading branch information...
1 parent 4a2768f commit 35efcc839883bdfd5461b508c12d04e17c08dff1 @dchelimsky dchelimsky committed Oct 9, 2010
Showing with 20 additions and 28 deletions.
  1. +1 −1 lib/autotest/rspec2.rb
  2. +3 −4 spec/autotest/failed_results_re_spec.rb
  3. +16 −23 spec/autotest/rspec_spec.rb
@@ -10,7 +10,7 @@ def initialize
super
clear_mappings
setup_rspec_project_mappings
- self.failed_results_re = /^\s*\d\)\s(.*?$\n.*?$).*?#\s(.*?):/m
+ self.failed_results_re = /^\s*\d\).*\n\s+Failure.*(\n\s+#\s(.*)?:\d+)+$/m
self.completed_re = /\n(?:\e\[\d*m)?\d* examples?/m
end
@@ -5,17 +5,16 @@
let(:formatter) { RSpec::Core::Formatters::BaseTextFormatter.new(output) }
let(:example_output) do
group = RSpec::Core::ExampleGroup.describe("group name")
- example = group.example("example name") { "this".should eq("that") }
+ group.example("example name") { "this".should eq("that") }
group.run(formatter)
RSpec.configuration.stub(:color_enabled?) { false }
formatter.dump_failures
output.string
end
-
- it "should match a failure" do
+
+ it "matches a failure" do
re = Autotest::Rspec2.new.failed_results_re
re =~ example_output
- $1.should == "group name example name\n Failure/Error: example = group.example(\"example name\") { \"this\".should eq(\"that\") }"
$2.should == __FILE__.sub(File.expand_path('.'),'.')
end
end
@@ -66,39 +66,32 @@
end
describe "consolidating failures" do
- before do
- @spec_file = "spec/autotest/some_spec.rb"
- rspec_autotest.instance_variable_set("@files", {@spec_file => Time.now})
- rspec_autotest.stub!(:find_files_to_test).and_return true
- end
+ let(:subject_file) { "lib/autotest/some.rb" }
+ let(:spec_file) { "spec/autotest/some_spec.rb" }
it "returns no failures if no failures were given in the output" do
rspec_autotest.consolidate_failures([[]]).should == {}
end
it "returns a hash with the spec filename => spec name for each failure or error" do
- rspec_autotest.stub!(:test_files_for).and_return "spec/autotest/some_spec.rb"
- failures = [
- [
- "false should be false",
- "#{@spec_file}"
- ]
- ]
+ failures = [ [ "false should be false", spec_file ] ]
rspec_autotest.consolidate_failures(failures).should == {
- @spec_file => ["false should be false"]
+ spec_file => ["false should be false"]
}
end
- it "does not include the subject file" do
- subject_file = "lib/autotest/some.rb"
- rspec_autotest.stub!(:test_files_for).and_return "spec/autotest/some_spec.rb"
- failures = [
- [
- "false should be false",
- "expected: true,\n got: false (using ==)\n#{subject_file}:143:\n#{@spec_file}:203:"
- ]
- ]
- rspec_autotest.consolidate_failures(failures).keys.should_not include(subject_file)
+ context "when subject file appears before the spec file in the backtrace" do
+ let(:failures) do
+ [ [ "false should be false", "#{subject_file}:143:\n#{spec_file}:203:" ] ]
+ end
+
+ it "excludes the subject file" do
+ rspec_autotest.consolidate_failures(failures).keys.should_not include(subject_file)
+ end
+
+ it "includes the spec file" do
+ rspec_autotest.consolidate_failures(failures).keys.should include(spec_file)
+ end
end
end

0 comments on commit 35efcc8

Please sign in to comment.