Sha256: 43acdb438428c5641f8b4ae1b19323227423579a938a677b137568a02e530c59

Contents?: true

Size: 1.36 KB

Versions: 34

Compression:

Stored size: 1.36 KB

Contents

module Spec
  module Example
    module PredicateMatchers
      # :call-seq:
      #   predicate_matchers[matcher_name] = method_on_object
      #   predicate_matchers[matcher_name] = [method1_on_object, method2_on_object]
      #
      # Dynamically generates a custom matcher that will match
      # a predicate on your class. RSpec provides a couple of these
      # out of the box:
      #
      #   exist (for state expectations)
      #     File.should exist("path/to/file")
      #
      #   an_instance_of (for mock argument matchers)
      #     mock.should_receive(:message).with(an_instance_of(String))
      #
      # == Examples
      #
      #   class Fish
      #     def can_swim?
      #       true
      #     end
      #   end
      #
      #   describe Fish do
      #     predicate_matchers[:swim] = :can_swim?
      #     it "should swim" do
      #       Fish.new.should swim
      #     end
      #   end
      def predicate_matchers
        @predicate_matchers ||= Spec::HashWithDeprecationNotice.new("predicate_matchers", "the new Matcher DSL")
      end

      def define_methods_from_predicate_matchers # :nodoc:
        predicate_matchers.each_pair do |matcher_method, method_on_object|
          define_method matcher_method do |*args|
            eval("be_#{method_on_object.to_s.gsub('?','')}(*args)")
          end
        end
      end

    end
  end
end

Version data entries

34 entries across 34 versions & 11 rubygems

Version Path
rspec-instructure-1.3.3 lib/spec/example/predicate_matchers.rb
radiant-1.0.0 ruby-debug/ruby/1.8/gems/rspec-1.3.2/lib/spec/example/predicate_matchers.rb
rspec-1.3.2 lib/spec/example/predicate_matchers.rb
rspec-1.3.1 lib/spec/example/predicate_matchers.rb
rspec-1.3.1.rc lib/spec/example/predicate_matchers.rb
rspec-1.3.0 lib/spec/example/predicate_matchers.rb
hubbub-0.0.11 lib/vendor/plugins/rspec/lib/spec/example/predicate_matchers.rb
hubbub-0.0.10 lib/vendor/plugins/rspec/lib/spec/example/predicate_matchers.rb
hubbub-0.0.9 lib/vendor/plugins/rspec/lib/spec/example/predicate_matchers.rb
hubbub-0.0.8 lib/vendor/plugins/rspec/lib/spec/example/predicate_matchers.rb
hubbub-0.0.6 lib/vendor/plugins/rspec/lib/spec/example/predicate_matchers.rb
simple-templater-0.0.1.4 gems/gems/rspec-1.2.9/lib/spec/example/predicate_matchers.rb
media-path-0.1.2 vendor/rspec/lib/spec/example/predicate_matchers.rb
simple-templater-0.0.1.3 vendor/rspec/lib/spec/example/predicate_matchers.rb
pupu-0.0.2.pre vendor/rspec/lib/spec/example/predicate_matchers.rb
media-path-0.1.1.pre vendor/rspec/lib/spec/example/predicate_matchers.rb
simple-templater-0.0.1.2 vendor/rspec/lib/spec/example/predicate_matchers.rb
media-path-0.1.1 vendor/rspec/lib/spec/example/predicate_matchers.rb
simple-templater-0.0.1.1 vendor/rspec/lib/spec/example/predicate_matchers.rb
pupu-0.0.2 vendor/rspec/lib/spec/example/predicate_matchers.rb