Sha256: 3b81b6d2fe3028b853e073407ca11f16f089cf941186c8c3bf47c063520688e3

Contents?: true

Size: 1.09 KB

Versions: 74

Compression:

Stored size: 1.09 KB

Contents

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

      def negative_failure_message
        "expected #{@actual} 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

74 entries across 74 versions & 12 rubygems

Version Path
dchelimsky-rspec-1.1.99.1 lib/spec/matchers/satisfy.rb
dchelimsky-rspec-1.1.99.2 lib/spec/matchers/satisfy.rb
dchelimsky-rspec-1.1.99.3 lib/spec/matchers/satisfy.rb
dchelimsky-rspec-1.1.99.4 lib/spec/matchers/satisfy.rb
dchelimsky-rspec-1.1.99.5 lib/spec/matchers/satisfy.rb
dchelimsky-rspec-1.1.99.6 lib/spec/matchers/satisfy.rb
dchelimsky-rspec-1.1.99.7 lib/spec/matchers/satisfy.rb
dchelimsky-rspec-1.1.99.8 lib/spec/matchers/satisfy.rb
dchelimsky-rspec-1.1.99.9 lib/spec/matchers/satisfy.rb
jnstq-acts_as_sms-0.1.0 test/vendor/plugins/rspec/lib/spec/matchers/satisfy.rb
jnstq-acts_as_sms-0.1.1 test/vendor/plugins/rspec/lib/spec/matchers/satisfy.rb
jnstq-acts_as_sms-0.1.3 test/vendor/plugins/rspec/lib/spec/matchers/satisfy.rb
jnstq-acts_as_sms-0.1.4 test/vendor/plugins/rspec/lib/spec/matchers/satisfy.rb
deckshuffler-0.0.2 vendor/plugins/rspec/lib/spec/matchers/satisfy.rb
has_finder-0.1.1 spec/rails/vendor/plugins/rspec/lib/spec/matchers/satisfy.rb
has_finder-0.1.2 spec/rails/vendor/plugins/rspec/lib/spec/matchers/satisfy.rb
has_finder-0.1.3 spec/rails/vendor/plugins/rspec/lib/spec/matchers/satisfy.rb
picolena-0.0.99 app_generators/picolena/templates/vendor/plugins/rspec/lib/spec/matchers/satisfy.rb
picolena-0.1.0 rails_plugins/rspec/lib/spec/matchers/satisfy.rb
picolena-0.1.1 rails_plugins/rspec/lib/spec/matchers/satisfy.rb