Sha256: 013bcab5a6210a4f0ed1966066529dcad2e9c8392ebf1b233a041c9054167930

Contents?: true

Size: 482 Bytes

Versions: 5

Compression:

Stored size: 482 Bytes

Contents

require 'rspec/expectations'

Rspec::Matchers.define :smart_match do |expected|
  def regexp?
    /^\/.*\/?$/
  end

  def quoted?
    /^".*"$/
  end

  match do |actual|
    case expected
    when regexp?
      actual =~ eval(expected)
    when quoted?
      actual.index(eval(expected))
    else # multi-line string
      actual.index(expected)
    end
  end

  failure_message_for_should do |actual|
    <<-MESSAGE
#{'*'*50}
got:
#{'*'*30}
#{actual}
#{'*'*50}
MESSAGE
  end

end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
rspec-core-2.0.0.a9 features/support/matchers/smart_match.rb
rspec-core-2.0.0.a8 features/support/matchers/smart_match.rb
rspec-core-2.0.0.a7 features/support/matchers/smart_match.rb
rspec-core-2.0.0.a6 features/support/matchers/smart_match.rb
rspec-core-2.0.0.a5 features/support/matchers/smart_match.rb