mirror of
https://github.com/ditkrg/validates_timeliness.git
synced 2026-01-23 06:16:44 +00:00
have to manually require matcher now because the presence of the Spec
namespace caused issues for shoulda when not using rspec:wq
This commit is contained in:
parent
14c55e3292
commit
1a31e7463d
10
README.rdoc
10
README.rdoc
@ -355,9 +355,15 @@ To sweeten the deal that little bit more, you have an Rspec matcher available fo
|
||||
you model specs. Now you can easily test the validations you have just written
|
||||
with the plugin or better yet *before* you write them! You just use the
|
||||
validation options you want as you would with the validation method. Those
|
||||
options are then verified and reported if they fail. Use it like so:
|
||||
options are then verified and reported if they fail.
|
||||
|
||||
@person.should validate_date(:birth_date, :before => Time.now, :before_message => 'should be before today')
|
||||
First require it in your spec_helper.rb
|
||||
|
||||
require 'validates_timeliness/matcher'
|
||||
|
||||
Use it like so:
|
||||
|
||||
@person.should validate_date(:birth_date, :before => Time.now, :before_message => 'should be before today')
|
||||
|
||||
|
||||
The matcher names are just the singular of the validation methods.
|
||||
|
||||
@ -2,7 +2,6 @@ require 'validates_timeliness/formats'
|
||||
require 'validates_timeliness/parser'
|
||||
require 'validates_timeliness/validator'
|
||||
require 'validates_timeliness/validation_methods'
|
||||
require 'validates_timeliness/spec/rails/matchers/validate_timeliness' if ENV['RAILS_ENV'] == 'test'
|
||||
|
||||
require 'validates_timeliness/active_record/attribute_methods'
|
||||
require 'validates_timeliness/active_record/multiparameter_attributes'
|
||||
|
||||
1
lib/validates_timeliness/matcher.rb
Normal file
1
lib/validates_timeliness/matcher.rb
Normal file
@ -0,0 +1 @@
|
||||
require 'validates_timeliness/spec/rails/matchers/validate_timeliness'
|
||||
@ -28,13 +28,12 @@ module Spec
|
||||
|
||||
valid = test_validity
|
||||
|
||||
valid = test_option(:equal_to) if @options[:equal_to] && valid
|
||||
valid = test_option(:before) if @options[:before] && valid
|
||||
valid = test_option(:after) if @options[:after] && valid
|
||||
valid = test_option(:on_or_before) if @options[:on_or_before] && valid
|
||||
valid = test_option(:on_or_after) if @options[:on_or_after] && valid
|
||||
|
||||
valid = test_between if @options[:between] && valid
|
||||
valid = test_option(:equal_to) if valid && @options[:equal_to]
|
||||
valid = test_option(:before) if valid && @options[:before]
|
||||
valid = test_option(:after) if valid && @options[:after]
|
||||
valid = test_option(:on_or_before) if valid && @options[:on_or_before]
|
||||
valid = test_option(:on_or_after) if valid && @options[:on_or_after]
|
||||
valid = test_between if valid && @options[:between]
|
||||
|
||||
return valid
|
||||
end
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
|
||||
require 'validates_timeliness/matcher'
|
||||
|
||||
class NoValidation < Person
|
||||
end
|
||||
|
||||
Loading…
Reference in New Issue
Block a user