Sha256: 54cc7fd93ce04e0879cf4dd5452394a0aaba37a7a5864504ad7e1955f4f8b980

Contents?: true

Size: 939 Bytes

Versions: 84

Compression:

Stored size: 939 Bytes

Contents

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

      def matches?(actual)
        @actual = actual
        # Satisfy expectation here. Return false or raise an error if it's not met.

        if @expected =~ /^\/.*\/?$/ || @expected =~ /^".*"$/
          regex_or_string = eval(@expected)
          if Regexp === regex_or_string
            (@actual =~ regex_or_string) ? true : false
          else
            @actual.index(regex_or_string) != nil
          end
        else
          false
        end
      end

      def failure_message
        "expected #{@actual.inspect} to smart_match #{@expected.inspect}, but it didn't"
      end

      def negative_failure_message
        "expected #{@actual.inspect} not to smart_match #{@expected.inspect}, but it did"
      end
    end

    def smart_match(expected)
      SmartMatch.new(expected)
    end
  end
end

Version data entries

84 entries across 84 versions & 12 rubygems

Version Path
jnstq-acts_as_sms-0.1.1 test/vendor/plugins/rspec/stories/resources/matchers/smart_match.rb
jnstq-acts_as_sms-0.1.3 test/vendor/plugins/rspec/stories/resources/matchers/smart_match.rb
jnstq-acts_as_sms-0.1.4 test/vendor/plugins/rspec/stories/resources/matchers/smart_match.rb
newbamboo-evented-rspec-1.1.12 features/support/matchers/smart_match.rb
newbamboo-rspec-1.1.12 features/support/matchers/smart_match.rb
merb-core-1.1.3 spec10/public/webrat/test_app/gems/gems/rspec-1.1.11/stories/resources/matchers/smart_match.rb
merb-core-1.1.2 spec10/public/webrat/test_app/gems/gems/rspec-1.1.11/stories/resources/matchers/smart_match.rb
merb-core-1.1.1 spec10/public/webrat/test_app/gems/gems/rspec-1.1.11/stories/resources/matchers/smart_match.rb
merb-core-1.1.0 spec10/public/webrat/test_app/gems/gems/rspec-1.1.11/stories/resources/matchers/smart_match.rb
merb-core-1.1.0.rc1 spec10/public/webrat/test_app/gems/gems/rspec-1.1.11/stories/resources/matchers/smart_match.rb
merb-core-1.1.0.pre spec10/public/webrat/test_app/gems/gems/rspec-1.1.11/stories/resources/matchers/smart_match.rb
mack-0.8.2 lib/gems/rspec-1.1.11/stories/resources/matchers/smart_match.rb
picolena-0.0.99 app_generators/picolena/templates/vendor/plugins/rspec/stories/resources/matchers/smart_match.rb
picolena-0.1.1 rails_plugins/rspec/stories/resources/matchers/smart_match.rb
picolena-0.1.0 rails_plugins/rspec/stories/resources/matchers/smart_match.rb
picolena-0.1.2 rails_plugins/rspec/stories/resources/matchers/smart_match.rb
picolena-0.1.3 rails_plugins/rspec/stories/resources/matchers/smart_match.rb
picolena-0.1.4 rails_plugins/rspec/stories/resources/matchers/smart_match.rb
picolena-0.1.6 rails_plugins/rspec/stories/resources/matchers/smart_match.rb
picolena-0.1.5 rails_plugins/rspec/stories/resources/matchers/smart_match.rb