Sha256: 0570f39c1b69233da26a258b51ea23ce20073e4332de10d7feefccbfd71344ee

Contents?: true

Size: 1.28 KB

Versions: 13

Compression:

Stored size: 1.28 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 ||= {}
      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

13 entries across 13 versions & 2 rubygems

Version Path
dchelimsky-rspec-1.1.99.1 lib/spec/example/predicate_matchers.rb
dchelimsky-rspec-1.1.99.13 lib/spec/example/predicate_matchers.rb
dchelimsky-rspec-1.1.99.2 lib/spec/example/predicate_matchers.rb
dchelimsky-rspec-1.1.99.3 lib/spec/example/predicate_matchers.rb
dchelimsky-rspec-1.1.99.4 lib/spec/example/predicate_matchers.rb
dchelimsky-rspec-1.1.99.5 lib/spec/example/predicate_matchers.rb
dchelimsky-rspec-1.1.99.6 lib/spec/example/predicate_matchers.rb
dchelimsky-rspec-1.1.99.7 lib/spec/example/predicate_matchers.rb
dchelimsky-rspec-1.1.99.8 lib/spec/example/predicate_matchers.rb
dchelimsky-rspec-1.1.99.9 lib/spec/example/predicate_matchers.rb
rspec-1.2.2 lib/spec/example/predicate_matchers.rb
rspec-1.2.1 lib/spec/example/predicate_matchers.rb
rspec-1.2.0 lib/spec/example/predicate_matchers.rb