Permalink
Browse files

Handle both RSpec 2.11 and 2.12 RaiseError implementations.

  • Loading branch information...
1 parent d78b2e7 commit da5e8c56be146b25cb33eed0c0312d88d0cead43 @jimweirich committed Nov 24, 2012
Showing with 38 additions and 20 deletions.
  1. +1 −1 Gemfile
  2. +8 −8 Gemfile.lock
  3. +29 −11 lib/rspec/given/have_failed.rb
View
@@ -1,3 +1,3 @@
source 'https://rubygems.org'
-gem 'rspec', '>= 2.0'
+gem 'rspec', '>= 2.12'
gem 'rake', '>= 0.9.2.2'
View
@@ -3,18 +3,18 @@ GEM
specs:
diff-lcs (1.1.3)
rake (0.9.2.2)
- rspec (2.11.0)
- rspec-core (~> 2.11.0)
- rspec-expectations (~> 2.11.0)
- rspec-mocks (~> 2.11.0)
- rspec-core (2.11.1)
- rspec-expectations (2.11.2)
+ rspec (2.12.0)
+ rspec-core (~> 2.12.0)
+ rspec-expectations (~> 2.12.0)
+ rspec-mocks (~> 2.12.0)
+ rspec-core (2.12.0)
+ rspec-expectations (2.12.0)
diff-lcs (~> 1.1.3)
- rspec-mocks (2.11.2)
+ rspec-mocks (2.12.0)
PLATFORMS
ruby
DEPENDENCIES
rake (>= 0.9.2.2)
- rspec (>= 2.0)
+ rspec (>= 2.12)
@@ -4,22 +4,40 @@ module HaveFailed
# Specializes the RaiseError matcher to handle
# Failure/non-failure objects.
- class HaveFailedMatcher < RSpec::Matchers::BuiltIn::RaiseError
- def matches?(given_proc, negative_expectation = false)
- if given_proc.is_a?(Failure)
- super
- else
- super(lambda { }, negative_expectation)
+
+ # The implementation of RaiseError changed between RSpec 2.11 and 2.12.
+ if RSpec::Matchers::BuiltIn::RaiseError.instance_methods.include?(:does_not_match?)
+
+ class HaveFailedMatcher < RSpec::Matchers::BuiltIn::RaiseError
+ def matches?(given_proc, negative_expectation = false)
+ if given_proc.is_a?(Failure)
+ super
+ else
+ super(lambda { }, negative_expectation)
+ end
+ end
+
+ def does_not_match?(given_proc)
+ if given_proc.is_a?(Failure)
+ super(given_proc)
+ else
+ super(lambda { })
+ end
end
end
- def does_not_match?(given_proc)
- if given_proc.is_a?(Failure)
- super(given_proc)
- else
- super(lambda { })
+ else
+
+ class HaveFailedMatcher < RSpec::Matchers::BuiltIn::RaiseError
+ def matches?(given_proc)
+ if given_proc.is_a?(Failure)
+ super
+ else
+ super(lambda { })
+ end
end
end
+
end
# Simular to raise_error(...), but reads a bit better when using

0 comments on commit da5e8c5

Please sign in to comment.