Skip to content

Commit

Permalink
Updated autotest regular expression and consolidate failures to work …
Browse files Browse the repository at this point in the history
…directly from text formatter

- Closes #97.
  • Loading branch information
Dave Newman authored and dchelimsky committed Aug 23, 2010
1 parent 1d57042 commit 6f6ea21
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 27 deletions.
6 changes: 3 additions & 3 deletions lib/autotest/rspec2.rb
Expand Up @@ -10,7 +10,7 @@ def initialize
super
clear_mappings
setup_rspec_project_mappings
self.failed_results_re = /^\d+\)\n(?:\e\[\d*m)?(?:.*?in )?'([^\n]*)'(?: FAILED)?(?:\e\[\d*m)?\n\n?(.*?(\n\n\(.*?)?)\n\n/m
self.failed_results_re = /^\s*\d\)\s(.*?$\n.*?$).*?#\s(.*?):/m
self.completed_re = /\n(?:\e\[\d*m)?\d* examples?/m
end

Expand All @@ -29,8 +29,8 @@ def setup_rspec_project_mappings
def consolidate_failures(failed)
filters = new_hash_of_arrays
failed.each do |spec, trace|
if trace =~ /\n(\.\/)?(.*spec\.rb):[\d]+:/
filters[$2] << spec
if trace =~ /(.*spec\.rb)/
filters[$1] << spec
end
end
return filters
Expand Down
37 changes: 14 additions & 23 deletions spec/autotest/failed_results_re_spec.rb
@@ -1,31 +1,22 @@
require "spec_helper"

describe "failed_results_re for autotest" do
it "should match a failure" do
re = Autotest::Rspec2.new.failed_results_re
re =~ "1)\n'this example' FAILED\nreason\n/path.rb:37:\n\n"
$1.should == "this example"
$2.should == "reason\n/path.rb:37:"
end

it "should match a failure when matcher outputs multiple lines" do
re = Autotest::Rspec2.new.failed_results_re
re =~ "1)\n'other example' FAILED\n\nreason line 1\nreason line 2\n\n(additional info)\n/path.rb:37:\n\n"
$1.should == "other example"
$2.should == "reason line 1\nreason line 2\n\n(additional info)\n/path.rb:37:"
let(:output) { StringIO.new }
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.run_all(formatter)
RSpec.configuration.stub(:color_enabled?) { false }
formatter.dump_failures
output.string
end

it "should match an Error" do
it "should match a failure" do
re = Autotest::Rspec2.new.failed_results_re
re =~ "1)\nRuntimeError in 'this example'\nreason\n/path.rb:37:\n\n"
$1.should == "this example"
$2.should == "reason\n/path.rb:37:"
re =~ example_output
$1.should == "group name example name\n Failure/Error: example = group.example(\"example name\") { \"this\".should eq(\"that\") }"
$2.should == "./spec/autotest/failed_results_re_spec.rb"
end

it "should match an Error that doesn't end in Error" do
re = Autotest::Rspec2.new.failed_results_re
re =~ "1)\nInvalidArgument in 'this example'\nreason\n/path.rb:37:\n\n"
$1.should == "this example"
$2.should == "reason\n/path.rb:37:"
end
end
2 changes: 1 addition & 1 deletion spec/autotest/rspec_spec.rb
Expand Up @@ -78,7 +78,7 @@
failures = [
[
"false should be false",
"expected: true,\n got: false (using ==)\n#{@spec_file}:203:"
"#{@spec_file}"
]
]
@rspec_autotest.consolidate_failures(failures).should == {
Expand Down

0 comments on commit 6f6ea21

Please sign in to comment.