Sha256: 6755dfc8baf749b7498669d1f6a71c3d0923cc4dd13135e8cf732aaa1b33fb3e

Contents?: true

Size: 1.28 KB

Versions: 1

Compression:

Stored size: 1.28 KB

Contents

require 'validates_formatting_of/validation'

module ValidatesFormattingOf

  describe Validation do
    context "valid validation creation" do
      let(:validation) { Validation.new(:name, /something/i, "is an invalid value") }
      subject { validation }
      its(:name) { should == :name }
      its(:regex) { should == %r{something}i }
      its(:message) { should == 'is an invalid value' }
      its(:to_s) { should == "<Validation::name>" }
      its(:inspect) { should =~ /Validation/ }
      its(:inspect) { should =~ /\/something\/i/ }
      its(:inspect) { should =~ /\:name/ }
    end
    context "invalid validation creation" do
      it "should raise an error if the specified regex is not a Regexp objct" do
        expect { Validation.new(:name, 123, "is an invalid value") }.to raise_error
      end
      it "should not raise an error if the specified regex is a proc or a lambda" do
        expect { Validation.new(:name, lambda { "my record" }, "is an invalid value") }.not_to raise_error
        expect { Validation.new(:name, proc { "my record" }, "is an invalid value") }.not_to raise_error
      end
      it "should not raise an error if the regex if valid" do
        expect { Validation.new(:name, /something/i, "is an invalid value") }.not_to raise_error
      end
    end
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
validates_formatting_of-0.8.1 spec/validates_formatting_of/validation_spec.rb