[rspec-users] Unexplainable failure...at least for me

Hans de Graaff hans at degraaff.org
Wed Nov 7 01:49:17 EST 2007


On Wed, 2007-11-07 at 06:39 +0100, Chris Olsen wrote:

> but when the specs are run I get errors saying that the country and
> province object properties are null
> 11)
> NoMethodError in 'Address additional properties should ensure spacing
> between the st/ave on the address'
> You have a nil object when you didn't expect it!
> The error occurred while evaluating nil.name
> /Users/chris/Documents/Projects/Rails/MyProject/trunk/config/../app/models/address.rb:25:in
> `full_address'
> ./spec/models/address_spec.rb:66:
> script/spec:4:
> 
> Here is one of the tests that fail:
> describe Address, "additional properties" do
> 
>   before(:each) do
>     @address = Address.new(valid_params)
>   end
> 
>   def valid_params
>     {
>       :country_id => 1,
>       :province_id => 1,
>       :region_code => "T5Z3J4",
>       :address_1 => "13245-56 st",
>       :address_2 => "NW",
>       :city => "Edmonton"
>     }
>   end

The question is where this country and province with id 1 are defined. I
don't see anything in your spec to indicate that they are ever created.
If you are using fixtures then you'll need to explicitly include them.
Otherwise they may or may not still be loaded in the test database and
at best you'll get a clear failure and at worst inconsistent results.

describe Address do
  fixtures :provinces, countries

  before ... etc

Kind regards,

Hans
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
Url : http://rubyforge.org/pipermail/rspec-users/attachments/20071107/3f85bb78/attachment.bin 


More information about the rspec-users mailing list