[rspec-users] [rspec] looking for a simple refresher

David Chelimsky dchelimsky at gmail.com
Fri Aug 17 19:24:41 EDT 2007


def create (not de create)

On 8/17/07, David Chelimsky <dchelimsky at gmail.com> wrote:
> Sorry - totally missed the controller code in your first example.
> You're posting to create, not new:
> de create
>   Ticket.new
> end
>
> That should do the trick.
>
>
> On 8/17/07, Andrew WC Brown <omen.king at gmail.com> wrote:
> > I replaced:
> >
> > @ticket.should_receive(:new).with(@params).and_return(@ticket)
> >
> > with
> >
> > Ticket.should_receive(:new).with(@params).and_return(@ticket)
> >
> > Similar Error
> >
> > 1)
> > Spec::Mocks::MockExpectationError in 'TicketsController
> > handling POST /tickets should create a new ticket'
> > Mock 'Class' expected :new with ({}) once, but received it 0 times
> > ./spec/controllers/tickets_controller_spec.rb:16:
> >
> > If I omit @params = {} then I get the error as following
> >
> > 1)
> > Spec::Mocks::MockExpectationError in 'TicketsController
> > handling POST /tickets should create a new ticket'
> > Mock 'Class' expected :new with (any args) once, but received it 0 times
> > ./spec/controllers/tickets_controller_spec.rb:16:
> >
> > So its not receiving the new method at all even though I clearly called it.
> >  Could it be possible that the issue is with the actual Ticket model itself?
> >
> >
> > On 8/17/07, David Chelimsky <dchelimsky at gmail.com > wrote:
> > > On 8/17/07, Andrew WC Brown <omen.king at gmail.com > wrote:
> > > > I've been off the rspec for a few months and I'm trying to get back on
> > it.
> > > >
> > > > 1)
> > > >  Spec::Mocks::MockExpectationError in
> > 'TicketsController
> > > > handling POST /tickets should create a new ticket'
> > > >  Mock 'Ticket_1001' expected :new with ({}) once, but received it 0
> > times
> > > >  ./spec/controllers/tickets_controller_spec.rb:16:
> > > >  script/spec:4:
> > > >
> > > > class TicketsController < ApplicationController
> > > >
> > > >   def new
> > > >     Ticket.new
> > > >   end
> > > >
> > > > end
> > > >
> > > > describe TicketsController, "handling POST /tickets" do
> > > >
> > > >   before do
> > > >     @ticket = mock_model(Ticket, :to_param => '1', :save => true)
> > > >     Ticket.stub!(:new).and_return(@ticket)
> > > >     @params = {}
> > > >   end
> > > >
> > > >   def do_post
> > > >     post :create, :ticket => @params
> > > >   end
> > > >
> > > >   it "should create a new ticket" do
> > > >
> > > >
> > @ticket.should_receive(:new).with(@params).and_return(@ticket)
> > >
> > > This is telling the ticket object to expect new, but it's the Ticket
> > > class that will receive it:
> > >
> > >
> > Ticket.should_receive(:new).with(@params).and_return(@ticket)
> > >
> > > That should do it.
> > >
> > > >     do_post
> > > >   end
> > > >
> > > > end
> > > >
> > > > Would someone provide with an explanation what I have to do to make this
> > > > spec pass?
> > > > Peepcode hasn't released their screen cast on rspecing controllers yet
> > ='(
> > > >
> > > >
> > > >
> > > >
> > > >
> > > > _______________________________________________
> > > > 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
> > >
> >
> >
> >
> > --
> > Monsterbox Productions
> > putting small businesses on-line
> >
> > 1319 Victoria Avenue East
> > Thunder Bay, Ontario P7C 1C3
> > Canada
> >
> > Andrew WC Brown
> > web-developer and owner
> > andrew at monsterboxpro.com
> > P: 807-626-9009
> > F: 807-624-2705
> > _______________________________________________
> > rspec-users mailing list
> > rspec-users at rubyforge.org
> > http://rubyforge.org/mailman/listinfo/rspec-users
> >
>


More information about the rspec-users mailing list