[DRE-commits] [ruby-rspec-instafail] 68/126: simplify rspec 2 formatter by using existing methods
Hideki Yamane
henrich at moszumanska.debian.org
Sun Nov 15 19:15:16 UTC 2015
This is an automated email from the git hooks/post-receive script.
henrich pushed a commit to branch debian/sid
in repository ruby-rspec-instafail.
commit c1e9593abd46c5c0b1f5b96f1ee9a89c37ad3188
Author: grosser <grosser.michael at gmail.com>
Date: Mon Nov 21 07:53:58 2011 -0800
simplify rspec 2 formatter by using existing methods
---
lib/rspec/instafail/rspec_2.rb | 25 ++++------------
spec/instafail_spec.rb | 68 +++++-------------------------------------
2 files changed, 13 insertions(+), 80 deletions(-)
diff --git a/lib/rspec/instafail/rspec_2.rb b/lib/rspec/instafail/rspec_2.rb
index 0d249fb..f43cc10 100644
--- a/lib/rspec/instafail/rspec_2.rb
+++ b/lib/rspec/instafail/rspec_2.rb
@@ -3,26 +3,13 @@ require 'rspec/core/formatters/progress_formatter'
module RSpec
class Instafail < RSpec::Core::Formatters::ProgressFormatter
def example_failed(example)
- @counter ||= 0
- @counter += 1
+ # do what BaseFormatter#example_failed would do
+ @failed_examples << example
- result = example.metadata[:execution_result]
-
- exception = result[:exception_encountered] || result[:exception] # rspec 2.0 || rspec 2.2
- short_padding = ' '
- padding = ' '
- output.puts
- output.puts "#{short_padding}#{@counter}) #{example.full_description}"
- output.puts "#{padding}#{red("Failure/Error:")} #{red(read_failed_line(exception, example).strip)}"
- output.puts "#{padding}#{red(exception)}"
- if exception.respond_to?(:original_exception)
- output.puts "#{padding}#{red(exception.original_exception)}"
- end
- format_backtrace(exception.backtrace, example).each do |backtrace_info|
- color = defined?(cyan) ? :cyan : :grey # cyan was added in rspec 2.6
- output.puts send(color, "#{padding}# #{backtrace_info}")
- end
- output.flush
+ # do what BaseTextFormatter#dump_failures would do
+ index = failed_examples.size - 1
+ dump_pending_example_fixed(example, index) || dump_failure(example, index)
+ dump_backtrace(example)
end
end
end
diff --git a/spec/instafail_spec.rb b/spec/instafail_spec.rb
index 391e3d7..ee8c3a5 100644
--- a/spec/instafail_spec.rb
+++ b/spec/instafail_spec.rb
@@ -27,75 +27,21 @@ EXP
before(:all)do
@rspec_result = `cd spec/rspec_2 && bundle exec rspec a_test.rb --require ../../lib/rspec/instafail --format RSpec::Instafail --no-color`
end
+
before do
@output = @rspec_result.dup
end
- it "outputs logical failures" do
- expected = <<EXP
- 1\\) x fails logically
- Failure\\/Error: 1\\.should == 2
- expected: 2,
- got: 1 \\(using ==\\)
-EXP
- @output.should =~ Regexp.new(expected, 'x')
-
- @output.should include('/a_test.rb:5')
- end
-
- it 'outputs a simple error' do
- expected = <<EXP
-\\.\\.\\*
- 2\\) x raises a simple error
- Failure\\/Error: raise 'shallow failure'
- shallow failure
-EXP
- @output.should =~ Regexp.new(expected, 'x')
- end
-
- it 'outputs an error which responds to original_exception' do
- expected = <<EXP
- 3\\) x raises a hidden error
- Failure\\/Error: raise error
- There is an error in this error\\.
- There is no error in this error\\.
-EXP
- @output.should =~ Regexp.new(expected, 'x')
+ it "outputs failures at start of output" do
+ @output.should =~ /^\s+1\) x fails logically/m
end
- it 'outputs the remaining passing specs and the ending block' do
- expected = <<EXP
-\\.
-Pending:
- x pends
- # No reason given
- # \\./a_test\\.rb:14
-
-Finished in \\d\\.\\d+ seconds
-7 examples, 3 failures, 1 pending
-EXP
- @output.should =~ Regexp.new(expected, 'x')
+ it 'outputs errors in middle of output' do
+ @output.should =~ /\.\.\*\s*2\) x raises a simple error/m
end
- it "works correctly with RSpec 2.x" do
- pending 'the backtrace for the error is always absolute on my machine'
- expected_output = <<EXP
- 1\\) x a
- Failure\\/Error: 1\\.should == 2
- expected: 2,
- got: 1 \\(using ==\\)
- # \\./a_test\\.rb:5
-\\.\\.\\*\\.
-
-Pending:
- x d
- # No reason given
- # \\./a_test\\.rb:14
-
-Finished in \\d\\.\\d+ seconds
-7 examples, 3 failures, 1 pending
-EXP
- @output.should =~ Regexp.new(expected_output, 'x')
+ it 'outputs the the ending block' do
+ @output.should =~ /Finished in \d\.\d+ seconds\s*7 examples, 3 failures, 1 pending/
end
end
end
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-ruby-extras/ruby-rspec-instafail.git
More information about the Pkg-ruby-extras-commits
mailing list