Hello, I''m still pretty new to Rails, and I''ve used rspec on all of my models with success. Now I''m working on the controllers, but I''m having difficulty. Everything I try is giving me a response of false, and I was hoping to get some insight from this community. All code can be viewed in this pastie: http://pastie.org/private/rn7vhzvmamn9tuytuuqq Please let me know if you need anything else! Thanks in advance! Andrew Davis -- Posted via http://www.ruby-forum.com/.
On Nov 17, 2010, at 2:16 PM, Andrew Davis wrote:> Hello, I''m still pretty new to Rails, and I''ve used rspec on all of my > models with success.Welcome!> Now I''m working on the controllers, but I''m having > difficulty. Everything I try is giving me a response of false,Please post backtraces when you have failures. "response of false" could mean too many different things.> and I was > hoping to get some insight from this community. > > All code can be viewed in this pastie: > http://pastie.org/private/rn7vhzvmamn9tuytuuqqNot sure if it''s related, but I notice this line in the pastie: TaskOrder.stub!(:find, @task_order.id).and_return(@task_order) This is incorrect usage of stub. If you''re trying to constraint the stub to the id, you have to use the "with" method, which would also need something to account for the hash with :include => "criteria": TaskOrder.stub!(:find).with(@task_order.id, anything).and_return(@task_order) The "anything" method is an argument matcher that will match against anything passed in. If you want to be specific about the hash as well, you could do this: TaskOrder.stub(:find).with(@task_order.id, "include" => "criteria").and_return(@task_order) But I''d recommend against this level of detail and stick to either "anything" or perhaps defining a named scope or a wrapper method for including the criteria: TaskOrder.stub_chain("with_criteria.find").with(@task_order.id).and_return(@task_order) TaskOrder.stub(:find_with_criteria).with(@task_order.id).and_return(@task_order) I don''t really like the name "find_with_criteria" but hopefully you''ll come up with something better :) HTH, David> > Please let me know if you need anything else! > > Thanks in advance! > Andrew Davis
Thank you very much for your response. I''ll give it a go this afternoon! Now, you mentioned, "Please post backtraces when you have failures." Do you mean a section of the test.log? Because RSpec only informed that that it expected true but was false. Or is there a condition I need to pass to get a backtrace, that sounds extremely helpful! Thanks again for your thorough response! Thank you, Andrew Davis -- Posted via http://www.ruby-forum.com/.
On Nov 18, 2010, at 8:38 AM, Andrew Davis wrote:> Thank you very much for your response. I''ll give it a go this afternoon! > > Now, you mentioned, "Please post backtraces when you have failures." > > Do you mean a section of the test.log? Because RSpec only informed that > that it expected true but was false. Or is there a condition I need to > pass to get a backtrace, that sounds extremely helpful!At the very least copy the failure message verbatim rather than describing it. You said "false responses", which sounds like the response object was false. Now you say "expected true but it was false" but I think the actual message would be "expected true, got false". Precision is important to make it easier for those who want to help to do so. If you run "rspec spec --backtrace" you''ll get the full backtrace, and you can copy that into the email or https://gist.github.com/ or https://gist.github.com/. Run "rspec --help" to see all of the command line options. Cheers, David> > Thanks again for your thorough response! > > Thank you, > Andrew Davis > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users