Sha256: 9eee28843f226b6df889027116b15d9f7f9af5225a576fabf2317730136daf01

Contents?: true

Size: 1.76 KB

Versions: 17

Compression:

Stored size: 1.76 KB

Contents

require 'teststrap'

context "validates format" do
  
  should "add a validation macro" do
    WhyValidationsSuckIn96::ValidationBuilder.instance_methods
  end.includes('validates_format_of')
  
  should "raise if a :with option is not given" do
      WhyValidationsSuckIn96::ValidatesFormat.new(Object.new, :attribute => :colour)    
  end.raises(ArgumentError, "Regular expression to check against must be given as :with")
  
  context "with some default options" do
    setup do
      WhyValidationsSuckIn96::ValidatesFormat.new(Object.new, :attribute => :colour, :with => /\d{3}/)
    end
  
    should "have a message accessor with a default message" do
      topic.message
    end.equals("does not match the given format")
  end # with some default options
  
  context "validating an object" do

    should "fail if given attribute does not match the regular expression" do
      validation = WhyValidationsSuckIn96::ValidatesFormat.new(OpenStruct.new(:number => "1"), :attribute => :number,
                                                               :with => /\d{3}/)
      validation.validates?
    end.equals(false)
    
    should "pass if given attribute matches the regular expression" do
      validation = WhyValidationsSuckIn96::ValidatesFormat.new(OpenStruct.new(:number => "111"), :attribute => :number,
                                                               :with => /\d{3}/)
      validation.validates?
    end
    
    should "to_s the attribute when checking validity" do
      validation = WhyValidationsSuckIn96::ValidatesFormat.new(OpenStruct.new(:number => 333), :attribute => :number,
                                                               :with => /\d{3}/)
      validation.validates?
    end
  end   # validating an object
end     # validates format

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
whyvalidationssuckin96-1.6.1 test/macros/validates_format_test.rb
whyvalidationssuckin96-1.6.0 test/macros/validates_format_test.rb
whyvalidationssuckin96-1.5.5 test/macros/validates_format_test.rb
whyvalidationssuckin96-1.5.4 test/macros/validates_format_test.rb
whyvalidationssuckin96-1.5.3 test/macros/validates_format_test.rb
whyvalidationssuckin96-1.5.2 test/macros/validates_format_test.rb
whyvalidationssuckin96-1.5.1 test/macros/validates_format_test.rb
whyvalidationssuckin96-1.5.0 test/macros/validates_format_test.rb
whyvalidationssuckin96-1.4.0 test/macros/validates_format_test.rb
whyvalidationssuckin96-1.3.1 test/macros/validates_format_test.rb
whyvalidationssuckin96-1.3.0 test/macros/validates_format_test.rb
whyvalidationssuckin96-1.2.3 test/macros/validates_format_test.rb
whyvalidationssuckin96-1.2.2 test/macros/validates_format_test.rb
whyvalidationssuckin96-1.2.1 test/macros/validates_format_test.rb
whyvalidationssuckin96-1.2.0 test/macros/validates_format_test.rb
whyvalidationssuckin96-1.1.0 test/macros/validates_format_test.rb
whyvalidationssuckin96-1.0.0 test/macros/validates_format_test.rb