Skip to content

Instantly share code, notes, and snippets.

@JonRowe
Created December 14, 2010 15:08
Show Gist options
  • Save JonRowe/740549 to your computer and use it in GitHub Desktop.
Save JonRowe/740549 to your computer and use it in GitHub Desktop.
RSpec-Core 2.3.0 autotest failed spec regular expression fix for colour
From fa82095f0928decfeead82341959d7e451fd16aa Mon Sep 17 00:00:00 2001
From: Jon Rowe <[email protected]>
Date: Tue, 14 Dec 2010 15:01:10 +0000
Subject: [PATCH] add spec for checking coloured output and regular expression that matches both coloured and non coloured output
---
lib/autotest/rspec2.rb | 2 +-
spec/autotest/failed_results_re_spec.rb | 14 ++++++++++++++
2 files changed, 15 insertions(+), 1 deletions(-)
diff --git a/lib/autotest/rspec2.rb b/lib/autotest/rspec2.rb
index c61772a..0434c2c 100644
--- a/lib/autotest/rspec2.rb
+++ b/lib/autotest/rspec2.rb
@@ -13,7 +13,7 @@ class Autotest::Rspec2 < Autotest
# Example for Ruby 1.8: http://rubular.com/r/AOXNVDrZpx
# Example for Ruby 1.9: http://rubular.com/r/85ag5AZ2jP
- self.failed_results_re = /^\s*\d+\).*\n\s+Failure.*(\n\s+#\s(.*)?:\d+(?::.*)?)+$/m
+ self.failed_results_re = /^\s*\d+\).*\n\s+(?:\e\[\d*m)?Failure.*(\n(?:\e\[\d*m)?\s+#\s(.*)?:\d+(?::.*)?)+$/m
self.completed_re = /\n(?:\e\[\d*m)?\d* examples?/m
end
diff --git a/spec/autotest/failed_results_re_spec.rb b/spec/autotest/failed_results_re_spec.rb
index ec8a933..4633d6b 100644
--- a/spec/autotest/failed_results_re_spec.rb
+++ b/spec/autotest/failed_results_re_spec.rb
@@ -11,10 +11,24 @@ describe "failed_results_re for autotest" do
formatter.dump_failures
output.string
end
+ let(:coloured_example_output) do
+ group = RSpec::Core::ExampleGroup.describe("group name")
+ group.example("example name") { "this".should eq("that") }
+ group.run(formatter)
+ RSpec.configuration.stub(:color_enabled?) { true }
+ formatter.dump_failures
+ output.string
+ end
it "matches a failure" do
re = Autotest::Rspec2.new.failed_results_re
example_output.should =~ re
example_output[re, 2].should == __FILE__.sub(File.expand_path('.'),'.')
end
+
+ it "matches a coloured failure" do
+ re = Autotest::Rspec2.new.failed_results_re
+ coloured_example_output.should =~ re
+ coloured_example_output[re, 2].should == __FILE__.sub(File.expand_path('.'),'.')
+ end
end
--
1.7.2.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment