Sha256: d06a33d05d96ac1c2fb9e30ac7fc9fc5feb99ecc56764c0db7a7a33752535a49

Contents?: true

Size: 1.08 KB

Versions: 35

Compression:

Stored size: 1.08 KB

Contents

module Spec
  module Matchers
    
    class Satisfy #:nodoc:
      def initialize(&block)
        @block = block
      end
      
      def matches?(given, &block)
        @block = block if block
        @given = given
        @block.call(given)
      end
      
      def failure_message
        "expected #{@given} to satisfy block"
      end

      def negative_failure_message
        "expected #{@given} not to satisfy block"
      end
    end
    
    # :call-seq:
    #   should satisfy {}
    #   should_not satisfy {}
    #
    # Passes if the submitted block returns true. Yields target to the
    # block.
    #
    # Generally speaking, this should be thought of as a last resort when
    # you can't find any other way to specify the behaviour you wish to
    # specify.
    #
    # If you do find yourself in such a situation, you could always write
    # a custom matcher, which would likely make your specs more expressive.
    #
    # == Examples
    #
    #   5.should satisfy { |n|
    #     n > 3
    #   }
    def satisfy(&block)
      Matchers::Satisfy.new(&block)
    end
  end
end

Version data entries

35 entries across 35 versions & 8 rubygems

Version Path
dchelimsky-rspec-1.1.10 lib/spec/matchers/satisfy.rb
dchelimsky-rspec-1.1.11.1 lib/spec/matchers/satisfy.rb
dchelimsky-rspec-1.1.11.2 lib/spec/matchers/satisfy.rb
dchelimsky-rspec-1.1.11.3 lib/spec/matchers/satisfy.rb
dchelimsky-rspec-1.1.11.4 lib/spec/matchers/satisfy.rb
dchelimsky-rspec-1.1.11.5 lib/spec/matchers/satisfy.rb
dchelimsky-rspec-1.1.11.6 lib/spec/matchers/satisfy.rb
dchelimsky-rspec-1.1.11.7 lib/spec/matchers/satisfy.rb
dchelimsky-rspec-1.1.11 lib/spec/matchers/satisfy.rb
dchelimsky-rspec-1.1.12 lib/spec/matchers/satisfy.rb
newbamboo-evented-rspec-1.1.12 lib/spec/matchers/satisfy.rb
newbamboo-rspec-1.1.12 lib/spec/matchers/satisfy.rb
merb-core-1.1.3 spec10/public/webrat/test_app/gems/gems/rspec-1.1.11/lib/spec/matchers/satisfy.rb
merb-core-1.1.2 spec10/public/webrat/test_app/gems/gems/rspec-1.1.11/lib/spec/matchers/satisfy.rb
merb-core-1.1.1 spec10/public/webrat/test_app/gems/gems/rspec-1.1.11/lib/spec/matchers/satisfy.rb
merb-core-1.1.0 spec10/public/webrat/test_app/gems/gems/rspec-1.1.11/lib/spec/matchers/satisfy.rb
merb-core-1.1.0.rc1 spec10/public/webrat/test_app/gems/gems/rspec-1.1.11/lib/spec/matchers/satisfy.rb
merb-core-1.1.0.pre spec10/public/webrat/test_app/gems/gems/rspec-1.1.11/lib/spec/matchers/satisfy.rb
mack-0.8.2 lib/gems/rspec-1.1.11/lib/spec/matchers/satisfy.rb
mack-0.8.3.1 lib/gems/rspec-1.1.12/lib/spec/matchers/satisfy.rb