[rspec-users] Spec for validation plugin

rob_twf rob.anderton at thewebfellas.com
Thu Jul 26 11:30:39 EDT 2007


I'm writing a specification for a model called Location which has a
post_code attribute which should be a valid UK postcode. I'm using the 
validates_as_uk_postcode  plugin to handle the validation but I'm not sure
how I should properly specify my model.

Heres the model code:

class Location < ActiveRecord::Base
    validates_as_uk_postcode :post_code

In my model spec I want something like this (assume @location has been setup
as a new Location instance):
  it "should be invalid if the post code is incorrectly formatted" do
    @location.post_code => 'Q1 1QQ'
    @location.should_not be_valid
    @location.should have(1).error_on(:post_code)   

But there are many examples of invalid post codes and they are already
tested in the plugin's own test cases. I only really want to test my code,
rather than retest the plugin.

So my question is how should I write the specification so that it doesn't
duplicate the tests in the plugin but at the same time expresses the correct
behaviour of the Location model?

Thanks in advance,
View this message in context: http://www.nabble.com/Spec-for-validation-plugin-tf4152378.html#a11812924
Sent from the rspec-users mailing list archive at Nabble.com.

More information about the rspec-users mailing list