From 1a31e7463d5574936b444fca3ce46ae6a45dd1e1 Mon Sep 17 00:00:00 2001 From: Adam Meehan Date: Tue, 7 Jul 2009 15:32:15 +1000 Subject: [PATCH] have to manually require matcher now because the presence of the Spec namespace caused issues for shoulda when not using rspec:wq --- README.rdoc | 10 ++++++++-- lib/validates_timeliness.rb | 1 - lib/validates_timeliness/matcher.rb | 1 + .../spec/rails/matchers/validate_timeliness.rb | 13 ++++++------- .../spec/rails/matchers/validate_timeliness_spec.rb | 1 + 5 files changed, 16 insertions(+), 10 deletions(-) create mode 100644 lib/validates_timeliness/matcher.rb diff --git a/README.rdoc b/README.rdoc index 20e401f..a311de3 100644 --- a/README.rdoc +++ b/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. diff --git a/lib/validates_timeliness.rb b/lib/validates_timeliness.rb index 149d54b..510c5c5 100644 --- a/lib/validates_timeliness.rb +++ b/lib/validates_timeliness.rb @@ -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' diff --git a/lib/validates_timeliness/matcher.rb b/lib/validates_timeliness/matcher.rb new file mode 100644 index 0000000..0c1ab8d --- /dev/null +++ b/lib/validates_timeliness/matcher.rb @@ -0,0 +1 @@ +require 'validates_timeliness/spec/rails/matchers/validate_timeliness' diff --git a/lib/validates_timeliness/spec/rails/matchers/validate_timeliness.rb b/lib/validates_timeliness/spec/rails/matchers/validate_timeliness.rb index fbc0282..d5c4e6e 100644 --- a/lib/validates_timeliness/spec/rails/matchers/validate_timeliness.rb +++ b/lib/validates_timeliness/spec/rails/matchers/validate_timeliness.rb @@ -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 diff --git a/spec/spec/rails/matchers/validate_timeliness_spec.rb b/spec/spec/rails/matchers/validate_timeliness_spec.rb index fa80e4a..bd07f23 100644 --- a/spec/spec/rails/matchers/validate_timeliness_spec.rb +++ b/spec/spec/rails/matchers/validate_timeliness_spec.rb @@ -1,4 +1,5 @@ require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') +require 'validates_timeliness/matcher' class NoValidation < Person end