Sha256: 6fbba6218f8e25b5448a0748c4d50092742312f2dee7eda6a26c272df23e1bbd

Contents?: true

Size: 1.07 KB

Versions: 7

Compression:

Stored size: 1.07 KB

Contents

module RSpec
  module Matchers
    class Satisfy
      def initialize(&block)
        @block = block
      end
      
      def matches?(actual, &block)
        @block = block if block
        @actual = actual
        @block.call(actual)
      end
      
      def failure_message_for_should
        "expected #{@actual} to satisfy block"
      end

      def failure_message_for_should_not
        "expected #{@actual} not to satisfy block"
      end

      def description
        "satisfy block"
      end
    end
    
    # 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.
    #
    # @example
    #
    #   5.should satisfy { |n|
    #     n > 3
    #   }
    def satisfy(&block)
      Matchers::Satisfy.new(&block)
    end
  end
end

Version data entries

7 entries across 7 versions & 3 rubygems

Version Path
resque-pool-0.3.0 vendor/bundle/ruby/1.8/gems/rspec-expectations-2.8.0/lib/rspec/matchers/satisfy.rb
resque-pool-0.3.0.beta.2 vendor/bundle/ruby/1.8/gems/rspec-expectations-2.8.0/lib/rspec/matchers/satisfy.rb
horseman-0.0.4 vendor/ruby/1.9.1/gems/rspec-expectations-2.8.0/lib/rspec/matchers/satisfy.rb
horseman-0.0.3 vendor/ruby/1.9.1/gems/rspec-expectations-2.8.0/lib/rspec/matchers/satisfy.rb
rspec-expectations-2.8.0 lib/rspec/matchers/satisfy.rb
rspec-expectations-2.8.0.rc2 lib/rspec/matchers/satisfy.rb
rspec-expectations-2.8.0.rc1 lib/rspec/matchers/satisfy.rb