Sha256: bba1390d0614137f6754de15080b55444f48cee67178764856fd5d55dc9d5f6a

Contents?: true

Size: 924 Bytes

Versions: 17

Compression:

Stored size: 924 Bytes

Contents

module Spec
  module Matchers
    
    class Match #:nodoc:
      def initialize(regexp)
        @regexp = regexp
      end
      
      def matches?(given)
        @given = given
        return true if given =~ @regexp
        return false
      end
      
      def failure_message
        return "expected #{@given.inspect} to match #{@regexp.inspect}", @regexp, @given
      end
      
      def negative_failure_message
        return "expected #{@given.inspect} not to match #{@regexp.inspect}", @regexp, @given
      end
      
      def description
        "match #{@regexp.inspect}"
      end
    end
    
    # :call-seq:
    #   should match(regexp)
    #   should_not match(regexp)
    #
    # Given a Regexp, passes if given =~ regexp
    #
    # == Examples
    #
    #   email.should match(/^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i)
    def match(regexp)
      Matchers::Match.new(regexp)
    end
  end
end

Version data entries

17 entries across 17 versions & 5 rubygems

Version Path
dchelimsky-rspec-1.1.10 lib/spec/matchers/match.rb
dchelimsky-rspec-1.1.11 lib/spec/matchers/match.rb
merb-core-1.1.3 spec10/public/webrat/test_app/gems/gems/rspec-1.1.11/lib/spec/matchers/match.rb
merb-core-1.1.2 spec10/public/webrat/test_app/gems/gems/rspec-1.1.11/lib/spec/matchers/match.rb
merb-core-1.1.1 spec10/public/webrat/test_app/gems/gems/rspec-1.1.11/lib/spec/matchers/match.rb
merb-core-1.1.0 spec10/public/webrat/test_app/gems/gems/rspec-1.1.11/lib/spec/matchers/match.rb
merb-core-1.1.0.rc1 spec10/public/webrat/test_app/gems/gems/rspec-1.1.11/lib/spec/matchers/match.rb
merb-core-1.1.0.pre spec10/public/webrat/test_app/gems/gems/rspec-1.1.11/lib/spec/matchers/match.rb
mack-0.8.2 lib/gems/rspec-1.1.11/lib/spec/matchers/match.rb
rspec-1.1.10 lib/spec/matchers/match.rb
rspec-1.1.7 lib/spec/matchers/match.rb
rspec-1.1.6 lib/spec/matchers/match.rb
rspec-1.1.11 lib/spec/matchers/match.rb
rspec-1.1.9 lib/spec/matchers/match.rb
rspec-1.1.8 lib/spec/matchers/match.rb
typo-5.1.98 vendor/plugins/rspec/lib/spec/matchers/match.rb
typo-5.2 vendor/plugins/rspec/lib/spec/matchers/match.rb