spec/cfoundry/validator_spec.rb in cfoundry-1.5.3 vs spec/cfoundry/validator_spec.rb in cfoundry-2.0.0

- old
+ new

@@ -1,92 +1,94 @@ -require 'spec_helper' +require "spec_helper" -describe CFoundry::Validator do - subject { described_class } +module CFoundry + describe Validator do + let(:validator) { described_class } - describe 'value_matches?' do - it 'returns true on nil values' do - subject.value_matches?(nil, :something).should be_true - end + describe "value_matches?" do + it "returns true on nil values" do + validator.value_matches?(nil, :something).should be_true + end - context 'with a type of Class' do - it 'returns true when value is of type class' do - subject.value_matches?(1, Integer).should be_true + context "with a type of Class" do + it "returns true when value is of type class" do + validator.value_matches?(1, Integer).should be_true + end end - end - context 'with a Regex' do - it 'returns true when the regex matches' do - subject.value_matches?('value', /lue/).should == true + context "with a Regex" do + it "returns true when the regex matches" do + validator.value_matches?("value", /lue/).should == true + end end - end - context 'with type of url' do - it 'requires http or https urls' do - subject.value_matches?('http:whatever', :url).should be_true - subject.value_matches?('https:whatever', :url).should be_true - subject.value_matches?('htt_no:whatever', :url).should be_false + context "with type of url" do + it "requires http or https urls" do + validator.value_matches?("http:whatever", :url).should be_true + validator.value_matches?("https:whatever", :url).should be_true + validator.value_matches?("htt_no:whatever", :url).should be_false + end end - end - context 'with type of https_url' do - it 'requires http or https urls' do - subject.value_matches?('https:whatever', :https_url).should be_true - subject.value_matches?('http:whatever', :https_url).should be_false + context "with type of https_url" do + it "requires http or https urls" do + validator.value_matches?("https:whatever", :https_url).should be_true + validator.value_matches?("http:whatever", :https_url).should be_false + end end - end - context 'with type boolean' do - it 'returns true on presence of true or false' do - subject.value_matches?(true, :boolean).should be_true - subject.value_matches?(false, :boolean).should be_true - subject.value_matches?('no boolean', :boolean).should be_false + context "with type boolean" do + it "returns true on presence of true or false" do + validator.value_matches?(true, :boolean).should be_true + validator.value_matches?(false, :boolean).should be_true + validator.value_matches?("no boolean", :boolean).should be_false + end end - end - context 'with an Array' do - it 'returns true when all elements are of same type' do - subject.value_matches?(['https:whatever'], [String]).should be_true - subject.value_matches?(['https:whatever'], [Integer]).should be_false + context "with an Array" do + it "returns true when all elements are of same type" do + validator.value_matches?(["https:whatever"], [String]).should be_true + validator.value_matches?(["https:whatever"], [Integer]).should be_false + end end - end - context 'with a hash' do - it 'returns true when specified types match' do - subject.value_matches?({:name => "thing"}, {:name => String}).should be_true - subject.value_matches?({:name => "thing", :unspecified => 1}, {:name => String}).should be_true - subject.value_matches?({:name => 1}, {:name => String}).should be_false + context "with a hash" do + it "returns true when specified types match" do + validator.value_matches?({:name => "thing"}, {:name => String}).should be_true + validator.value_matches?({:name => "thing", :unspecified => 1}, {:name => String}).should be_true + validator.value_matches?({:name => 1}, {:name => String}).should be_false + end end - end - it 'returns true when type is nil' do - subject.value_matches?('some value', nil).should be_true - end + it "returns true when type is nil" do + validator.value_matches?("some value", nil).should be_true + end - context 'with a symbol' do - it 'returns true when the value is of specified type' do - subject.value_matches?('some value', :string).should be_true - subject.value_matches?('some value', :integer).should be_false + context "with a symbol" do + it "returns true when the value is of specified type" do + validator.value_matches?("some value", :string).should be_true + validator.value_matches?("some value", :integer).should be_false + end end end - end - describe 'validate_type' do - it 'passes validation with a nil value' do - expect { - subject.validate_type(nil, :whatever) - }.to_not raise_error - end + describe "validate_type" do + it "passes validation with a nil value" do + expect { + validator.validate_type(nil, :whatever) + }.to_not raise_error + end - it 'passes validation when the value matches' do - expect { - subject.validate_type('string', :string) - }.to_not raise_error - end + it "passes validation when the value matches" do + expect { + validator.validate_type("string", :string) + }.to_not raise_error + end - it 'raises a validation error when value does not match' do - expect { - subject.validate_type('string', :integer) - }.to raise_error(CFoundry::Mismatch) + it "raises a validation error when value does not match" do + expect { + validator.validate_type("string", :integer) + }.to raise_error(CFoundry::Mismatch) + end end end -end +end \ No newline at end of file