Hello, I''m confused why the spec described below is failing. Other simple comparison specs are passing fine for the same model. The code is working accordingly when I test it through the console, I''m just having difficulty getting this spec to work. Any pointers would be appreciated. Failure message: ''Address fetch and geocode should extract department and write to address object'' FAILED expected 3, got nil (using .eql?) This spec that is failing: @address.department_id.should eql(3) before: before do @address = Address.new @address.attributes = valid_address_attributes @address.save @department = mock_model(Department) @department.stub!(:find_by_code).with("75").and_return("3") end The line of code I am writing the spec for: self.department = Department.find_by_code(self.postcode[0..1]) Many thanks, Omar -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20071203/0b8e5734/attachment.html
Department.stub!(:find_by_code).with("75").and_return("3") Nathan Sutton fowlduck at gmail.com rspec edge revision 3014 rspec_on_rails edge revision 3014 rails edge revision 8238 On Dec 3, 2007, at 12:33 PM, Sahyoun wrote:> Hello, > > I''m confused why the spec described below is failing. Other simple > comparison specs are passing fine for the same model. The code is > working accordingly when I test it through the console, I''m just > having difficulty getting this spec to work. Any pointers would be > appreciated. > > Failure message: > ''Address fetch and geocode should extract department and write to > address object'' FAILED > expected 3, got nil (using .eql?) > > This spec that is failing: > @address.department_id.should eql(3) > > before: > before do > @address = Address.new > @address.attributes = valid_address_attributes > @address.save > @department = mock_model(Department) > @department.stub! (:find_by_code).with("75").and_return("3") > end > > > The line of code I am writing the spec for: > self.department = Department.find_by_code(self.postcode[0..1]) > > > > Many thanks, > Omar > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users
On 3.12.2007, at 21.05, Nathan Sutton wrote:> Department.stub!(:find_by_code).with("75").and_return("3")You can''t use with() with stub! (only with should_receive), so just leave it away: Department.stub!(:find_by_code).and_return("3") //jarkko -- Jarkko Laine http://jlaine.net http://dotherightthing.com http://www.railsecommerce.com http://odesign.fi
On Dec 3, 2007 1:18 PM, Jarkko Laine <jarkko at jlaine.net> wrote:> > On 3.12.2007, at 21.05, Nathan Sutton wrote: > > > Department.stub!(:find_by_code).with("75").and_return("3") > > You can''t use with() with stub! (only with should_receive), so just > leave it away: > > Department.stub!(:find_by_code).and_return("3")Actually, you can now, but it''s not really documented.> > //jarkko > > -- > Jarkko Laine > http://jlaine.net > http://dotherightthing.com > http://www.railsecommerce.com > http://odesign.fi > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >
It''s worked since I started using rspec, but I started relatively recently, and only on edge. Nathan Sutton fowlduck at gmail.com rspec edge revision 3014 rspec_on_rails edge revision 3014 rails edge revision 8238 On Dec 3, 2007, at 1:23 PM, David Chelimsky wrote:> On Dec 3, 2007 1:18 PM, Jarkko Laine <jarkko at jlaine.net> wrote: >> >> On 3.12.2007, at 21.05, Nathan Sutton wrote: >> >>> Department.stub!(:find_by_code).with("75").and_return("3") >> >> You can''t use with() with stub! (only with should_receive), so just >> leave it away: >> >> Department.stub!(:find_by_code).and_return("3") > > Actually, you can now, but it''s not really documented. > >> >> //jarkko >> >> -- >> Jarkko Laine >> http://jlaine.net >> http://dotherightthing.com >> http://www.railsecommerce.com >> http://odesign.fi >> >> >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users
On 3.12.2007, at 21.23, David Chelimsky wrote:> On Dec 3, 2007 1:18 PM, Jarkko Laine <jarkko at jlaine.net> wrote: >> >> On 3.12.2007, at 21.05, Nathan Sutton wrote: >> >>> Department.stub!(:find_by_code).with("75").and_return("3") >> >> You can''t use with() with stub! (only with should_receive), so just >> leave it away: >> >> Department.stub!(:find_by_code).and_return("3") > > Actually, you can now, but it''s not really documented.Oh, cool. I take it back, then :-) //jarkko -- Jarkko Laine http://jlaine.net http://dotherightthing.com http://www.railsecommerce.com http://odesign.fi