Sha256: 14dbea2570cb688ea8aff18e0e9e914bf413afecb8f46e078509310e00563061

Contents?: true

Size: 1.68 KB

Versions: 7

Compression:

Stored size: 1.68 KB

Contents

require 'spec_helper'

describe "expect(...).to match(expected)" do
  it_behaves_like "an RSpec matcher", :valid_value => 'ab', :invalid_value => 'bc' do
    let(:matcher) { match(/a/) }
  end

  it "passes when target (String) matches expected (Regexp)" do
    expect("string").to match(/tri/)
  end

  it "passes when target (String) matches expected (String)" do
    expect("string").to match("tri")
  end

  it "fails when target (String) does not match expected (Regexp)" do
    expect {
      expect("string").to match(/rings/)
    }.to fail
  end

  it "fails when target (String) does not match expected (String)" do
    expect {
      expect("string").to match("rings")
    }.to fail
  end

  it "provides message, expected and actual on failure" do
    matcher = match(/rings/)
    matcher.matches?("string")
    expect(matcher.failure_message_for_should).to eq "expected \"string\" to match /rings/"
  end
end

describe "expect(...).to_not match(expected)" do
  it "passes when target (String) matches does not match (Regexp)" do
    expect("string").not_to match(/rings/)
  end

  it "passes when target (String) matches does not match (String)" do
    expect("string").not_to match("rings")
  end

  it "fails when target (String) matches expected (Regexp)" do
    expect {
      expect("string").not_to match(/tri/)
    }.to fail
  end

  it "fails when target (String) matches expected (String)" do
    expect {
      expect("string").not_to match("tri")
    }.to fail
  end

  it "provides message, expected and actual on failure" do
    matcher = match(/tri/)
    matcher.matches?("string")
    expect(matcher.failure_message_for_should_not).to eq "expected \"string\" not to match /tri/"
  end
end

Version data entries

7 entries across 7 versions & 5 rubygems

Version Path
judge-2.0.5 vendor/bundle/ruby/2.1.0/gems/rspec-expectations-2.13.0/spec/rspec/matchers/match_spec.rb
sshp-0.0.2 vendor/ruby/1.9.1/gems/rspec-expectations-2.13.0/spec/rspec/matchers/match_spec.rb
sshp-0.0.1 vendor/ruby/1.9.1/gems/rspec-expectations-2.13.0/spec/rspec/matchers/match_spec.rb
sidekiq-statsd-0.1.1 vendor/ruby/1.9.1/gems/rspec-expectations-2.13.0/spec/rspec/matchers/match_spec.rb
sidekiq-statsd-0.1.0 vendor/ruby/1.9.1/gems/rspec-expectations-2.13.0/spec/rspec/matchers/match_spec.rb
vagrant-actionio-0.0.9 vendor/bundle/gems/rspec-expectations-2.13.0/spec/rspec/matchers/match_spec.rb
rspec-expectations-2.13.0 spec/rspec/matchers/match_spec.rb