Forum: RSpec Rspec weird behaviour

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
19915e24392ea1dc8917eb4f69709b25?d=identicon&s=25 andrea (Guest)
on 2009-03-23 11:34
(Received via mailing list)
Hi,
I recently migrated from classic rails testing to Rspec, so I am
pretty new to the framework and still learning. I am getting weird
errors on an ActiveRecord model test, here is the basic class model
definition:

class Size < ActiveRecord::Base
  has_many :quantities, :dependent => :destroy
  validates_presence_of :name
  validates_uniqueness_of :name, :case_sensitive => false
end

and this is the faulty spec:
  it 'new size should have an error on name' do
    Size.new.should have(1).error_on(:name)
  end

the red response is:
 'new size should have an error on name' FAILED
 expected 1 error on :name, got 0

if I change the spec to read like this:
 Size.new.should have(:no).error_on(:name)

I still get a red response:
 'new size should have an error on name' FAILED
 expected 0 error on :name, got 1

Guess the problem is the model class name (Size) as I don't get such
weird stuff from other classes... can I fix this somehow?

Thanks

Andrea
19915e24392ea1dc8917eb4f69709b25?d=identicon&s=25 andrea (Guest)
on 2009-03-23 11:55
(Received via mailing list)
On 23 Mar, 10:41, andrea <longhiand...@gmail.com> wrote:

[cut]

BTW I am using rails 2.3.2, rspec and rails-spec version 1.2.0

Andrea
5d38ab152e1e3e219512a9859fcd93af?d=identicon&s=25 David Chelimsky (Guest)
on 2009-03-23 13:29
(Received via mailing list)
On Mon, Mar 23, 2009 at 4:41 AM, andrea <longhiandrea@gmail.com> wrote:
> end
> if I change the spec to read like this:
>  Size.new.should have(:no).error_on(:name)
>
> I still get a red response:
>  'new size should have an error on name' FAILED
>  expected 0 error on :name, got 1
>
> Guess the problem is the model class name (Size) as I don't get such
> weird stuff from other classes... can I fix this somehow?

Hi Andrea,

I just tried this myself (because I wanted to see if the class name
was really the problem) and "Size.new.should have(1).error_on(:name)"
passed for me. I also tried "Size.new.should
have(:no).errors_on(:name)" and that failed correctly. So something
else is amiss in this case.

If this persists, please submit a bug report to
http://rspec.lighthouseapp.com and include a zipped up app that I can
run to see the problem.

Thanks,
David
369b9fd2a0d9e7cdbc60907a2a056ad9?d=identicon&s=25 Scott Taylor (Guest)
on 2009-03-23 16:23
(Received via mailing list)
andrea wrote:
> end
> if I change the spec to read like this:
>  Size.new.should have(:no).error_on(:name)
>

It should be have(0).errors_on(:name), AFAIK
5d38ab152e1e3e219512a9859fcd93af?d=identicon&s=25 David Chelimsky (Guest)
on 2009-03-23 16:26
(Received via mailing list)
On Mon, Mar 23, 2009 at 9:45 AM, Scott Taylor <scott@railsnewbie.com>
wrote:
>>  validates_presence_of :name
>>  expected 1 error on :name, got 0
>>
>> if I change the spec to read like this:
>>  Size.new.should have(:no).error_on(:name)
>>
>
> It should be have(0).errors_on(:name), AFAIK

have(:no).errors_on ... actually works as advertised (converts to 0).
19915e24392ea1dc8917eb4f69709b25?d=identicon&s=25 andrea (Guest)
on 2009-03-24 14:10
(Received via mailing list)
On 23 Mar, 13:10, David Chelimsky <dchelim...@gmail.com> wrote:

> If this persists, please submit a bug report tohttp://rspec.lighthouseapp.comand include 
a zipped up app that I can
> run to see the problem.

Thanks Dave, now everything works as expected, but I still don't know
what was the problem.
First I duplicated the app, tested it and got the same bad results as
the original one. Then I started to remove stuff from the duplicated
app until I got the Size model specs pass. This happened when I
removed the Size controller specs file. Weird.
I went back to the original app, cut the code from the Size controller
specs file and run the specs.. this time everything passed. I pasted
back the content to the Size controller file, saved and again all
specs run as they should... I feel really confused :-)

Regards
Andrea
This topic is locked and can not be replied to.