[DRE-commits] [ruby-rspec-instafail] 41/108: default to rspec 2, fall back to rspec 1

Hideki Yamane henrich at moszumanska.debian.org
Sun Nov 15 18:36:17 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 cf8f963a9059fa401b5e07ba24b5456b68f0269f
Author: Steve Tooke <steve.tooke at gmail.com>
Date:   Tue Nov 16 18:53:33 2010 +0000

    default to rspec 2, fall back to rspec 1
---
 lib/rspec/instafail.rb | 46 ++++++++++++++++++++++------------------------
 1 file changed, 22 insertions(+), 24 deletions(-)

diff --git a/lib/rspec/instafail.rb b/lib/rspec/instafail.rb
index b43cf60..8661b29 100644
--- a/lib/rspec/instafail.rb
+++ b/lib/rspec/instafail.rb
@@ -1,5 +1,25 @@
 module RSpec
-  klass = if defined? Spec
+  begin
+    # rspec 2.x
+    require 'rspec/core/formatters/progress_formatter'
+    class Instafail < RSpec::Core::Formatters::ProgressFormatter
+      def example_failed(example)
+        @counter ||= 0
+        @counter += 1
+        exception = example.metadata[:execution_result][:exception_encountered]
+        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)}"
+        format_backtrace(exception.backtrace, example).each do |backtrace_info|
+          output.puts grey("#{padding}# #{backtrace_info}")
+        end
+        output.flush
+      end
+    end
+  rescue LoadError => try_rspec_1
     # rspec 1.x
     require 'spec/runner/formatter/progress_bar_formatter'
     class Instafail < Spec::Runner::Formatter::ProgressBarFormatter
@@ -25,29 +45,7 @@ module RSpec
         colour(text, "\e[90m")
       end
     end
-    Instafail
-  else
-    # rspec 2.x
-    require 'rspec/core/formatters/progress_formatter'
-    class Instafail < RSpec::Core::Formatters::ProgressFormatter
-      def example_failed(example)
-        @counter ||= 0
-        @counter += 1
-        exception = example.metadata[:execution_result][:exception_encountered]
-        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)}"
-        format_backtrace(exception.backtrace, example).each do |backtrace_info|
-          output.puts grey("#{padding}# #{backtrace_info}")
-        end
-        output.flush
-      end
-    end
-    Instafail
   end
 
-  klass::VERSION = File.read( File.join(File.dirname(__FILE__),'..','..','VERSION') ).strip
+  Instafail::VERSION = File.read( File.join(File.dirname(__FILE__),'..','..','VERSION') ).strip
 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