Sha256: 03452742a2a84df471308e57b69d65f2088ff26de04505786f4d5d0f2cc0d14e

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(...).not_to 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 & 3 rubygems

Version Path
rspec-expectations-2.14.3 spec/rspec/matchers/match_spec.rb
clickable_link-0.0.2 vendor/bundle/ruby/1.9.1/gems/rspec-expectations-2.14.2/spec/rspec/matchers/match_spec.rb
syllable_counter-1.0.0 vendor/bundle/gems/rspec-expectations-2.14.2/spec/rspec/matchers/match_spec.rb
rspec-expectations-2.14.2 spec/rspec/matchers/match_spec.rb
rspec-expectations-2.14.1 spec/rspec/matchers/match_spec.rb
rspec-expectations-2.14.0 spec/rspec/matchers/match_spec.rb
rspec-expectations-2.14.0.rc1 spec/rspec/matchers/match_spec.rb