[DRE-commits] [ruby-rspec-instafail] 92/126: Add support for RSpec 3

Hideki Yamane henrich at moszumanska.debian.org
Sun Nov 15 19:15:21 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 61ba20659c87ee64304092f668f4151db5166038
Author: Kevin Carter <cartkev at gmail.com>
Date:   Fri Jun 6 17:52:02 2014 -0600

    Add support for RSpec 3
---
 Rakefile                       |  1 +
 lib/rspec/instafail.rb         | 12 +++++++----
 lib/rspec/instafail/rspec_3.rb | 18 ++++++++++++++++
 spec/instafail_spec.rb         | 30 +++++++++++++++++++++++++-
 spec/rspec_3/Gemfile           |  2 ++
 spec/rspec_3/Gemfile.lock      | 22 +++++++++++++++++++
 spec/rspec_3/a_test.rb         | 48 ++++++++++++++++++++++++++++++++++++++++++
 7 files changed, 128 insertions(+), 5 deletions(-)

diff --git a/Rakefile b/Rakefile
index 4c31a47..bb10184 100755
--- a/Rakefile
+++ b/Rakefile
@@ -6,6 +6,7 @@ task :default do
   Bundler.with_clean_env do
     sh "cd spec/rspec_1 && (bundle check || bundle) > /dev/null"
     sh "cd spec/rspec_2 && (bundle check || bundle) > /dev/null"
+    sh "cd spec/rspec_3 && (bundle check || bundle) > /dev/null"
   end
   sh "rspec spec/"
 end
diff --git a/lib/rspec/instafail.rb b/lib/rspec/instafail.rb
index 68fba41..05145a8 100755
--- a/lib/rspec/instafail.rb
+++ b/lib/rspec/instafail.rb
@@ -4,10 +4,14 @@ module RSpec
   lib = File.expand_path(File.dirname(File.dirname(__FILE__)))
   $LOAD_PATH << lib unless $LOAD_PATH.include?(lib)
 
-  begin
-    require "rspec/instafail/rspec_2"
-  rescue LoadError # try rspec 1
-    require "rspec/instafail/rspec_1"
+  if defined?(::RSpec::Core) && ::RSpec::Core::Version::STRING >= '3.0.0'
+    require "rspec/instafail/rspec_3"
+  else
+    begin
+      require "rspec/instafail/rspec_2"
+    rescue LoadError # try rspec 1
+      require "rspec/instafail/rspec_1"
+    end
   end
 
   require 'rspec/instafail/version'
diff --git a/lib/rspec/instafail/rspec_3.rb b/lib/rspec/instafail/rspec_3.rb
new file mode 100755
index 0000000..93321ee
--- /dev/null
+++ b/lib/rspec/instafail/rspec_3.rb
@@ -0,0 +1,18 @@
+require 'rspec/core/formatters/progress_formatter'
+
+module RSpec
+  class Instafail < RSpec::Core::Formatters::ProgressFormatter
+    RSpec::Core::Formatters.register self, :example_failed
+
+    def initialize(output)
+      super
+      @output = output
+      @failed_examples = []
+    end
+
+    def example_failed(failure)
+      @failed_examples << failure.example
+      @output.puts failure.fully_formatted(@failed_examples.size)
+    end
+  end
+end
diff --git a/spec/instafail_spec.rb b/spec/instafail_spec.rb
index 8fd152a..075b402 100755
--- a/spec/instafail_spec.rb
+++ b/spec/instafail_spec.rb
@@ -51,5 +51,33 @@ describe 'RSpec::Instafail' do
       @output.should_not include('ANCESTORS:3')
     end
   end
-end
 
+  context 'Rspec 3.x' do
+    before :all do
+      Bundler.with_clean_env do
+        @rspec_result = `cd spec/rspec_3 && bundle exec rspec a_test.rb --require ../../lib/rspec/instafail --format RSpec::Instafail --no-color --order default`
+      end
+    end
+
+    before do
+      @output = @rspec_result.dup
+    end
+
+    it "outputs failures at start of output" do
+      @output.should =~ /^\s+1\) x fails logically/m
+    end
+
+    it 'outputs errors in middle of output' do
+      @output.should =~ /\.\.\*\s*2\) x raises a simple error/m
+    end
+
+    it 'outputs the the ending block' do
+      @output.should =~ /Finished in \d\.\d+ seconds.*\s*9 examples, 4 failures, 1 pending/
+    end
+
+    it "does not add ancestors after failures" do
+      @output.should include('ANCESTORS:18')
+      @output.should_not include('ANCESTORS:19')
+    end
+  end
+end
diff --git a/spec/rspec_3/Gemfile b/spec/rspec_3/Gemfile
new file mode 100755
index 0000000..d4e4e53
--- /dev/null
+++ b/spec/rspec_3/Gemfile
@@ -0,0 +1,2 @@
+source 'http://rubygems.org'
+gem 'rspec', '>=3.0'
diff --git a/spec/rspec_3/Gemfile.lock b/spec/rspec_3/Gemfile.lock
new file mode 100755
index 0000000..f261f70
--- /dev/null
+++ b/spec/rspec_3/Gemfile.lock
@@ -0,0 +1,22 @@
+GEM
+  remote: http://rubygems.org/
+  specs:
+    diff-lcs (1.2.5)
+    rspec (3.0.0)
+      rspec-core (~> 3.0.0)
+      rspec-expectations (~> 3.0.0)
+      rspec-mocks (~> 3.0.0)
+    rspec-core (3.0.0)
+      rspec-support (~> 3.0.0)
+    rspec-expectations (3.0.0)
+      diff-lcs (>= 1.2.0, < 2.0)
+      rspec-support (~> 3.0.0)
+    rspec-mocks (3.0.0)
+      rspec-support (~> 3.0.0)
+    rspec-support (3.0.0)
+
+PLATFORMS
+  ruby
+
+DEPENDENCIES
+  rspec (>= 3.0)
diff --git a/spec/rspec_3/a_test.rb b/spec/rspec_3/a_test.rb
new file mode 100755
index 0000000..6eabea2
--- /dev/null
+++ b/spec/rspec_3/a_test.rb
@@ -0,0 +1,48 @@
+require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'lib', 'rspec', 'instafail'))
+
+describe 'x' do
+  it 'fails logically' do
+    expect(1).to eq 2
+  end
+
+  it 'b' do
+  end
+
+  it 'c' do
+  end
+
+  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
+
+  context "ancestors" do
+    after do |example|
+      puts "ANCESTORS:#{example.example_group.ancestors.size}"
+    end
+
+    it "does not add ancestors on failure" do
+      raise "BAM"
+    end
+
+    it "does not add ancestors on failure" do
+    end
+  end
+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