[rspec-users] Spec for validation plugin
rob.anderton at thewebfellas.com
Fri Jul 27 08:27:24 EDT 2007
> it "should validate that the postcode is correctly formatted" do
> load Location.source_file
> That works nicely.
Looks like I was a bit eager. Loading the class in this way causes problems
with other validations. For example, I add a name attribute to my class and
validate it's length like this:
class Location < ActiveRecord::Base
validates_length_of :name, :in => 1..50
And have this additional specification:
it "should be invalid if the name is too long" do
@location.name => 'x' * 51
This fails because the length validation occurs twice giving two (identical)
errors on :name. Removing the post code validation specification allows the
name length validation to work correctly.
So load() is causing the validation to be defined twice - is there any way
to avoid this?
View this message in context: http://www.nabble.com/Spec-for-validation-plugin-tf4152378.html#a11828149
Sent from the rspec-users mailing list archive at Nabble.com.
More information about the rspec-users