ben rooney
2010-May-06 09:02 UTC
[rspec-users] Failing test despite "expected" and "got" being identical ...
Slightly flummoxed on this one. Spec::Mocks::MockExpectationError in ''ChartEventsController handling GET /chart_events should find all chart_events given a value'' expected: ([:all, {:conditions=>["value LIKE ?", "%chart_event%"]}]) got: ([:all, {:conditions=>["value LIKE ?", "%chart_event%"]}]) In other words it got exactly what it expected, but, er, failed? Controller: if params[:q] @chart_events = ChartEvent.find(:all, :conditions =>[''value LIKE ?'', "%#{(params[:q])}%"]) else @chart_events = ChartEvent.all(:order=>''value'') end controller_spec before do @chart_event = mock_model(ChartEvent, :value => "chart_event") ChartEvent.stub!(:find).and_return([@chart_event]) end it "should find all chart_events given a value" do ChartEvent.should_receive(:find).with([:all, {:conditions=>["value LIKE ?", "%#{@chart_event.value}%"]}]).and_return([@chart_event]) get :index, :q => @chart_event.value end
Rick DeNatale
2010-May-06 13:47 UTC
[rspec-users] Failing test despite "expected" and "got" being identical ...
On Thu, May 6, 2010 at 5:02 AM, ben rooney <ben.rooney62 at googlemail.com> wrote:> Slightly flummoxed on this one. > > Spec::Mocks::MockExpectationError in ''ChartEventsController handling > GET /chart_events should find all chart_events given a value'' > ?expected: ([:all, {:conditions=>["value LIKE ?", "%chart_event%"]}]) > ? ? ? got: ([:all, {:conditions=>["value LIKE ?", "%chart_event%"]}]) > > In other words it got exactly what it expected, but, er, failed? > > Controller: > ? ?if params[:q] > ? ? ?@chart_events = ChartEvent.find(:all, :conditions =>[''value LIKE > ?'', "%#{(params[:q])}%"]) > ? ?else > ? ? ?@chart_events = ChartEvent.all(:order=>''value'') > ? ?end > > > controller_spec > ?before do > ? ?@chart_event ? ? = mock_model(ChartEvent, :value => "chart_event") > ? ?ChartEvent.stub!(:find).and_return([@chart_event]) > ?end > > ?it "should find all chart_events given a value" do > ? ?ChartEvent.should_receive(:find).with([:all, {:conditions=>["value > LIKE ?", "%#{@chart_event.value}%"]}]).and_return([@chart_event]) > ? ?get :index, :q => @chart_event.value > ?endI think you want ChartEvent.should_receive(:find).with(:all, {:conditions=>["value LIKE ?", "%#{@chart_event.value}%"]})... The output from the message expectation failure is a bit confusing, but the argument list to the with method should look like the argument list to the expected method. The expectation here is that find should get one argument, an array with a symbol and a hash, rather than two parameters, a symbol and a hash. It would be better if the failure were reported like this: expected: ([:all, {:conditions=>["value LIKE ?", "%chart_event%"]}]) got: (:all, {:conditions=>["value LIKE ?", "%chart_event%"]}) -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Github: http://github.com/rubyredrick Twitter: @RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale
David Chelimsky
2010-May-06 15:04 UTC
[rspec-users] Failing test despite "expected" and "got" being identical ...
On May 6, 2010, at 8:47 AM, Rick DeNatale wrote:> On Thu, May 6, 2010 at 5:02 AM, ben rooney <ben.rooney62 at googlemail.com> wrote: >> Slightly flummoxed on this one. >> >> Spec::Mocks::MockExpectationError in ''ChartEventsController handling >> GET /chart_events should find all chart_events given a value'' >> expected: ([:all, {:conditions=>["value LIKE ?", "%chart_event%"]}]) >> got: ([:all, {:conditions=>["value LIKE ?", "%chart_event%"]}]) >> >> In other words it got exactly what it expected, but, er, failed? >> >> Controller: >> if params[:q] >> @chart_events = ChartEvent.find(:all, :conditions =>[''value LIKE >> ?'', "%#{(params[:q])}%"]) >> else >> @chart_events = ChartEvent.all(:order=>''value'') >> end >> >> >> controller_spec >> before do >> @chart_event = mock_model(ChartEvent, :value => "chart_event") >> ChartEvent.stub!(:find).and_return([@chart_event]) >> end >> >> it "should find all chart_events given a value" do >> ChartEvent.should_receive(:find).with([:all, {:conditions=>["value >> LIKE ?", "%#{@chart_event.value}%"]}]).and_return([@chart_event]) >> get :index, :q => @chart_event.value >> end > > I think you want ChartEvent.should_receive(:find).with(:all, > {:conditions=>["value LIKE ?", "%#{@chart_event.value}%"]})... > > The output from the message expectation failure is a bit confusing, > but the argument list to the with method should look like the argument > list to the expected method. The expectation here is that find should > get one argument, an array with a symbol and a hash, rather than two > parameters, a symbol and a hash. > > It would be better if the failure were reported like this: > > expected: ([:all, {:conditions=>["value LIKE ?", "%chart_event%"]}]) > got: (:all, {:conditions=>["value LIKE ?", "%chart_event%"]}) >FYI - it _is_ reported this way in rspec-2.
ben rooney
2010-May-06 15:54 UTC
[rspec-users] Failing test despite "expected" and "got" being identical ...
Thanks guys The law of posting questions came into force. About three minutes after posting my q, I found my mistake (which was exactly as you said). I figured I must have done something wrong, so went back and started again, but it was the reporting that was baffling me - and that is already being sorted. Many thanks Ben