[rspec-users] why should_receive failure?
class PeepCode def awesome awesome end end describe PeepCode do it should fuck do PeepCode.new.should_receive(:awesome).and_return(awesome) end end - Spec::Mocks::MockExpectationError in 'PeepCode should fuck' #PeepCode:0xb7aa3bbc expected :awesome with (any args) once, but received it 0 times ./simple_spec.rb:13: Finished in 0.006159 seconds 1 example, 1 failure -- what's wrong with my code? -- Posted via http://www.ruby-forum.com/. ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users
Re: [rspec-users] why should_receive failure?
On Jul 14, 2009, at 10:59 PM, Zhenning Guan wrote: class PeepCode def awesome awesome end end describe PeepCode do it should fuck do peep = PeepCode.new peep.should_receive(:awesome).and_return(awesome) peep.awesome #this completes the expectation above # PeepCode.new.should_receive(:awesome).and_return(awesome) end end - Spec::Mocks::MockExpectationError in 'PeepCode should fuck' #PeepCode:0xb7aa3bbc expected :awesome with (any args) once, but received it 0 times ./simple_spec.rb:13: Finished in 0.006159 seconds 1 example, 1 failure -- what's wrong with my code? I think you misunderstand should_receive. It doesn't actually call the method you're describing; it creates an expectation. So your spec says that something should happen, and then you never called the method, so it received it 0 times This is a bad example though. Your code seems to say that this is the spec: describe PeepCode, awesome do it should return the string 'awesome' do PeepCode.new.awesome.should == 'awesome' end end should_receive says that in the test which is being run, the object should receive that method call... for example: class PeepCode def awesome totally_rad end def totally_rad righteous end end and your spec: describe PeepCode, awesome do it should call the totally_rad method do peep = PeepCode.new peep.should_receive(:totally_rad).and_return(...whatever...) peep.awesome end it should return the string 'righteous' do PeepCode.new.awesome.should == 'righteous' end end I haven't tried any of that, but it should work. Jim Gay http://www.saturnflyer.com ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users
Re: [rspec-users] why should_receive failure?
On Tue, Jul 14, 2009 at 9:59 PM, Zhenning Guanli...@ruby-forum.com wrote: class PeepCode def awesome awesome end end describe PeepCode do it should fuck do PeepCode.new.should_receive(:awesome).and_return(awesome) end end - Spec::Mocks::MockExpectationError in 'PeepCode should fuck' #PeepCode:0xb7aa3bbc expected :awesome with (any args) once, but received it 0 times ./simple_spec.rb:13: Finished in 0.006159 seconds 1 example, 1 failure -- what's wrong with my code? You asked a similar question yesterday and I tried to explain. Did you not receive my response? should_receive sets an expectation that a subsequent event will cause the PeepCode object to receive the :awesome message. There is no code after that expectation is set, so the message is never received, and the expectation fails. That's exactly what the error message is telling you: PeepCode:0xb7aa3bbc expected :awesome with (any args) once, but received it 0 times. If you're trying to specify that the PeepCode object should return awesome when you call the awesome() method, then the example should look like this: describe PeepCode, #awesome do it should return 'awesome' do peepcode = PeepCode.new peepcode.awesome.should == awesome end end There's no need to set a message expectation (e.g. mock) here. HTH, David ps - I think it's OK to say fuck on this list, if that's what you really mean, but I don't really understand what you're getting at with the expectation that PeepCode should fuck. Perhaps you might consider being a bit more careful about the examples you send. ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users
Re: [rspec-users] why should_receive failure?
because Peepcode.new doesn't receive the awesome message. like it says... Julian. On 15/07/2009, at 12:59 PM, Zhenning Guan wrote: class PeepCode def awesome awesome end end describe PeepCode do it should fuck do PeepCode.new.should_receive(:awesome).and_return(awesome) end end - Spec::Mocks::MockExpectationError in 'PeepCode should fuck' #PeepCode:0xb7aa3bbc expected :awesome with (any args) once, but received it 0 times ./simple_spec.rb:13: Finished in 0.006159 seconds 1 example, 1 failure -- what's wrong with my code? -- Posted via http://www.ruby-forum.com/. ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users