Created
September 3, 2012 02:50
-
-
Save hzm-s/3606433 to your computer and use it in GitHub Desktop.
DRY'uped validator spec
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'spec_helper' | |
shared_examples "valid" do | |
it { expect { subject }.not_to raise_error(Avalon::Error) } | |
end | |
shared_examples "invalid" do | |
it { expect { subject }.to raise_error(Avalon::Error) } | |
end | |
describe Avalon::Validator do | |
let(:validator) { described_class.new candidate, pattern } | |
let(:candidate) { "target" } | |
describe "#validate" do | |
subject { validator.validate } | |
context "given pattern as String", "when match" do | |
let(:pattern) { "target" } | |
it_behaves_like "valid" | |
end | |
context "given pattern as String", "when NOT match" do | |
let(:pattern) { "not matched" } | |
it_behaves_like "invalid" | |
end | |
context "given pattern as Regexp", "when match" do | |
let(:pattern) { /target/ } | |
it_behaves_like "valid" | |
end | |
context "given pattern as Regexp", "when NOT match" do | |
let(:pattern) { /not matched/ } | |
it_behaves_like "invalid" | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment