Sha256: a22af1cfd653add9998e8cf11cdaa50e6b068b3c0ddcf8e0bae3664f7044744e

Contents?: true

Size: 451 Bytes

Versions: 6

Compression:

Stored size: 451 Bytes

Contents

Spec::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

6 entries across 6 versions & 3 rubygems

Version Path
rspec-instructure-1.3.3 features/support/matchers/smart_match.rb
radiant-1.0.0 ruby-debug/ruby/1.8/gems/rspec-1.3.2/features/support/matchers/smart_match.rb
rspec-1.3.2 features/support/matchers/smart_match.rb
rspec-1.3.1 features/support/matchers/smart_match.rb
rspec-1.3.1.rc features/support/matchers/smart_match.rb
rspec-1.3.0 features/support/matchers/smart_match.rb