[DRE-commits] [ruby-rspec-instafail] 69/126: simplify rspec 1 code 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 33dc17de6a025f61800f27117bf59d3a4409e1ba
Author: grosser <grosser.michael at gmail.com>
Date:   Mon Nov 21 08:14:34 2011 -0800

    simplify rspec 1 code by using existing methods
---
 lib/rspec/instafail/rspec_1.rb | 20 +------------------
 spec/instafail_spec.rb         | 44 ++++++++++++++++++++----------------------
 spec/rspec_1/a_test.rb         | 20 ++++++++++++++++---
 3 files changed, 39 insertions(+), 45 deletions(-)

diff --git a/lib/rspec/instafail/rspec_1.rb b/lib/rspec/instafail/rspec_1.rb
index 5475f87..c79eef3 100644
--- a/lib/rspec/instafail/rspec_1.rb
+++ b/lib/rspec/instafail/rspec_1.rb
@@ -3,25 +3,7 @@ require 'spec/runner/formatter/progress_bar_formatter'
 module RSpec
   class Instafail < Spec::Runner::Formatter::ProgressBarFormatter
     def example_failed(example, counter, failure)
-      short_padding = '  '
-      padding = '     '
-
-      output.puts
-      output.puts red("#{short_padding}#{counter}) #{example_group.description} #{example.description}")
-      output.puts "#{padding}#{red(failure.exception)}"
-
-      [*format_backtrace(failure.exception.backtrace)].each do |backtrace_info|
-        output.puts insta_gray("#{padding}# #{backtrace_info.strip}")
-      end
-
-      output.flush
-    end
-
-    private
-
-    # there is a gray() that returns nil, so we use our own...
-    def insta_gray(text)
-      colour(text, "\e[90m")
+      dump_failure(counter, failure)
     end
   end
 end
diff --git a/spec/instafail_spec.rb b/spec/instafail_spec.rb
index ee8c3a5..ad48057 100644
--- a/spec/instafail_spec.rb
+++ b/spec/instafail_spec.rb
@@ -1,30 +1,28 @@
 describe 'RSpec::Instafail' do
-  it "works correctly with RSpec 1.x" do
-    output = `cd spec/rspec_1 && bundle exec spec a_test.rb --format RSpec::Instafail`
-    expected_output = <<EXP
-  1\\) x a
-     expected: 2,
-     got: 1 \\(using ==\\)
-     # (\\.\\/)?a_test\\.rb:5:(in `block \\(2 levels\\) in <top \\(required\\)>')?
-\\.\\.\\*\\.
-
-Pending:
-
-x d \\(TODO\\)
-(\\.\\/)?a_test\\.rb:14(\:in `block in <top \\(required\\)>')?
-
-1\\)
-'x a' FAILED
-expected: 2,
-     got: 1 \\(using ==\\)
-(\\./)?a_test\\.rb:5:(in `block \\(2 levels\\) in <top \\(required\\)>')?
-EXP
-
-    output.should =~ Regexp.new(expected_output, 'x')
+  context "RSpec 1.x" do
+    before :all do
+      @rspec_result = `cd spec/rspec_1 && bundle exec spec a_test.rb --format RSpec::Instafail`
+    end
+
+    before do
+      @output = @rspec_result.dup
+    end
+
+    it "outputs failures at start of output" do
+      @output.should =~ /^\s*1\)\s*'x fails logically'/m
+    end
+
+    it 'outputs errors in middle of output' do
+      @output.should =~ /\.\.\*\s*2\)\s*RuntimeError in 'x raises a simple error'/m
+    end
+
+    it 'outputs the the ending block' do
+      @output.should =~ /Finished in \d\.\d+ seconds\s*7 examples, 3 failures, 1 pending/
+    end
   end
 
   context 'Rspec 2.x' do
-    before(:all)do
+    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
 
diff --git a/spec/rspec_1/a_test.rb b/spec/rspec_1/a_test.rb
index 5fc5d1f..5b0990d 100644
--- a/spec/rspec_1/a_test.rb
+++ b/spec/rspec_1/a_test.rb
@@ -1,7 +1,7 @@
 require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'lib', 'rspec', 'instafail'))
 
 describe 'x' do
-  it 'a' do
+  it 'fails logically' do
     1.should == 2
   end
 
@@ -11,11 +11,25 @@ describe 'x' do
   it 'c' do
   end
 
-  it 'd' do
+  it 'pends' do
     pending
     raise
   end
 
+  it 'raises a simple error' do
+    raise 'shallow failure'
+  end
+
+  it 'raises a hidden error' do
+    error = ExceptionWrappingException.new('There is an error in this error.')
+    error.original_exception = RuntimeError.new('There is no error in this error.')
+    raise error
+  end
+
   it 'e' do
   end
-end
\ No newline at end of file
+end
+
+class ExceptionWrappingException < RuntimeError
+  attr_accessor :original_exception
+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