1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
|
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
|