aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/plugins/rspec/lib/spec/matchers.rb
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/plugins/rspec/lib/spec/matchers.rb')
-rw-r--r--vendor/plugins/rspec/lib/spec/matchers.rb107
1 files changed, 73 insertions, 34 deletions
diff --git a/vendor/plugins/rspec/lib/spec/matchers.rb b/vendor/plugins/rspec/lib/spec/matchers.rb
index afae5ae5f..4ef832936 100644
--- a/vendor/plugins/rspec/lib/spec/matchers.rb
+++ b/vendor/plugins/rspec/lib/spec/matchers.rb
@@ -1,19 +1,31 @@
-require 'spec/matchers/simple_matcher'
+require 'spec/matchers/extensions/instance_exec'
+require 'spec/matchers/pretty'
+require 'spec/matchers/matcher'
+require 'spec/matchers/operator_matcher'
require 'spec/matchers/be'
require 'spec/matchers/be_close'
+require 'spec/matchers/be_instance_of'
+require 'spec/matchers/be_kind_of'
require 'spec/matchers/change'
require 'spec/matchers/eql'
require 'spec/matchers/equal'
+require 'spec/matchers/errors'
require 'spec/matchers/exist'
+require 'spec/matchers/generated_descriptions'
require 'spec/matchers/has'
require 'spec/matchers/have'
require 'spec/matchers/include'
require 'spec/matchers/match'
+require 'spec/matchers/match_array'
+require 'spec/matchers/method_missing'
require 'spec/matchers/raise_error'
require 'spec/matchers/respond_to'
require 'spec/matchers/satisfy'
+require 'spec/matchers/simple_matcher'
require 'spec/matchers/throw_symbol'
-require 'spec/matchers/operator_matcher'
+require 'spec/matchers/wrap_expectation'
+require 'spec/matchers/compatibility'
+require 'spec/matchers/dsl'
module Spec
@@ -21,12 +33,21 @@ module Spec
# is any object that responds to the following methods:
#
# matches?(actual)
- # failure_message
- # negative_failure_message #optional
+ # failure_message_for_should
+ #
+ # These methods are also part of the matcher protocol, but are optional:
+ #
+ # does_not_match?(actual)
+ # failure_message_for_should_not
# description #optional
#
+ # These methods are from older versions of the protocol. They are still supported,
+ # but are not recommended:
+ #
+ # failure_message (use failure_message_for_should instead)
+ # negative_failure_message (use failure_message_for_should_not instead)
+ #
# See Spec::Expectations to learn how to use these as Expectation Matchers.
- # See Spec::Mocks to learn how to use them as Mock Argument Constraints.
#
# == Predicates
#
@@ -63,14 +84,17 @@ module Spec
# You can use this feature to invoke any predicate that begins with "has_", whether it is
# part of the Ruby libraries (like +Hash#has_key?+) or a method you wrote on your own class.
#
- # == Custom Expectation Matchers
+ # == Custom Matchers
#
# When you find that none of the stock Expectation Matchers provide a natural
- # feeling expectation, you can very easily write your own.
+ # feeling expectation, you can very easily write your own using RSpec's matcher
+ # DSL or writing one from scratch.
+ #
+ # === Matcher DSL
#
- # For example, imagine that you are writing a game in which players can
- # be in various zones on a virtual board. To specify that bob should
- # be in zone 4, you could say:
+ # Imagine that you are writing a game in which players can be in various
+ # zones on a virtual board. To specify that bob should be in zone 4, you
+ # could say:
#
# bob.current_zone.should eql(Zone.new("4"))
#
@@ -82,7 +106,42 @@ module Spec
#
# bob.should_not be_in_zone("3")
#
- # To do this, you would need to write a class like this:
+ # You can create such a matcher like so:
+ #
+ # Spec::Matchers.define :be_in_zone do |zone|
+ # match do |player|
+ # player.in_zone?(zone)
+ # end
+ # end
+ #
+ # This will generate a <tt>be_in_zone</tt> method that returns a matcher
+ # with logical default messages for failures. You can override the failure
+ # messages and the generated description as follows:
+ #
+ # Spec::Matchers.define :be_in_zone do |zone|
+ # match do |player|
+ # player.in_zone?(zone)
+ # end
+ # failure_message_for_should do |player|
+ # # generate and return the appropriate string.
+ # end
+ # failure_message_for_should_not do |player|
+ # # generate and return the appropriate string.
+ # end
+ # description do
+ # # generate and return the appropriate string.
+ # end
+ # end
+ #
+ # Each of the message-generation methods has access to the block arguments
+ # passed to the <tt>create</tt> method (in this case, <tt>zone</tt>). The
+ # failure message methods (<tt>failure_message_for_should</tt> and
+ # <tt>failure_message_for_should_not</tt>) are passed the actual value (the
+ # receiver of <tt>should</tt> or <tt>should_not</tt>).
+ #
+ # === Custom Matcher from scratch
+ #
+ # You could also write a custom matcher from scratch, as follows:
#
# class BeInZone
# def initialize(expected)
@@ -92,10 +151,10 @@ module Spec
# @target = target
# @target.current_zone.eql?(Zone.new(@expected))
# end
- # def failure_message
+ # def failure_message_for_should
# "expected #{@target.inspect} to be in Zone #{@expected}"
# end
- # def negative_failure_message
+ # def failure_message_for_should_not
# "expected #{@target.inspect} not to be in Zone #{@expected}"
# end
# end
@@ -132,25 +191,5 @@ module Spec
# config.include(CustomGameMatchers)
# end
#
- module Matchers
- module ModuleMethods
- attr_accessor :generated_description
-
- def clear_generated_description
- self.generated_description = nil
- end
- end
-
- extend ModuleMethods
-
- def method_missing(sym, *args, &block) # :nodoc:
- return Matchers::Be.new(sym, *args) if sym.starts_with?("be_")
- return Matchers::Has.new(sym, *args) if sym.starts_with?("have_")
- super
- end
-
- class MatcherError < StandardError
- end
-
- end
+ module Matchers; end
end