Sha256: e900a939596d7c5f089546bf35bbf90c5be41dd5065cdafd758dbff8c7ee62bd

Contents?: true

Size: 891 Bytes

Versions: 4

Compression:

Stored size: 891 Bytes

Contents

module Spec
  module Matchers
    class Match
      def initialize(expected)
        @expected = expected
      end

      def matches?(actual)
        @actual = actual
        actual =~ @expected
      end

      def failure_message_for_should
        return "expected #{@actual.inspect} to match #{@expected.inspect}", @expected, @actual
      end

      def failure_message_for_should_not
        return "expected #{@actual.inspect} not to match #{@expected.inspect}", @expected, @actual
      end

      def description
        "match #{@expected.inspect}"
      end
    end
    
    
    # :call-seq:
    #   should match(regexp)
    #   should_not match(regexp)
    #
    # Given a Regexp, passes if actual =~ regexp
    #
    # == Examples
    #
    #   email.should match(/^([^\s]+)((?:[-a-z0-9]+\.)+[a-z]{2,})$/i)
    def match(expected)
      Match.new(expected)
    end
  end
end

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
dchelimsky-rspec-1.1.99.13 lib/spec/matchers/match.rb
rspec-1.2.0 lib/spec/matchers/match.rb
rspec-1.2.1 lib/spec/matchers/match.rb
rspec-1.2.2 lib/spec/matchers/match.rb