<HTML><BODY style="word-wrap: break-word; -khtml-nbsp-mode: space; -khtml-line-break: after-white-space; ">what's in the create method of the controller?? you've only given the contents of the new method - and without knowing what you want it to do it's hard to know what will work.<DIV><BR class="khtml-block-placeholder"></DIV><DIV>Assuming it's the normal</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>def create</DIV><DIV> @ticket = Ticket.new(params(:ticket])</DIV><DIV>  if @ticket.save</DIV><DIV>   ....etc etc</DIV><DIV>end</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>then something like the following should work:</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>describe TicketsController, "handling POST /tickets" do</DIV><DIV>  before do</DIV><DIV>    @ticket = mock_model(Ticket, :save =&gt; true)</DIV><DIV>    Ticket.stub!(:new).and_return(@ticket)</DIV><DIV>    @params = {}</DIV><DIV>  end</DIV><DIV>  </DIV><DIV>  def do_post</DIV><DIV>    post :create, :ticket =&gt; @params</DIV><DIV>  end</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>  it "should create a new ticket" do</DIV><DIV>    ticket.should_receive(:new).with(@params).and_return(@ticket)</DIV><DIV>    do_post</DIV><DIV>  end</DIV><DIV>  </DIV><DIV>  it "should assign the ticket for the view" do</DIV><DIV>    do_post</DIV><DIV>    assigns[:ticket].should equal(@ticket)</DIV><DIV>  end</DIV><DIV>  </DIV><DIV>  it "should save the new ticket" do</DIV><DIV>    @ticket.should_receive(:save).with().and_return(true)</DIV><DIV>    do_post</DIV><DIV>  end</DIV><DIV>end<DIV><DIV><BR class="khtml-block-placeholder"></DIV><BR><DIV><DIV>On 18 Aug 2007, at 00:11, Andrew WC Brown wrote:</DIV><BR class="Apple-interchange-newline"><BLOCKQUOTE type="cite">I replaced:<BR><BR>@ticket.should_receive(:new).with(@params).and_return(@ticket)<BR><BR>with<BR><BR>Ticket.should_receive(:new).with(@params).and_return(@ticket)<BR><BR>Similar Error<BR><BR>1)<BR>Spec::Mocks::MockExpectationError in 'TicketsController handling POST /tickets should create a new ticket' <BR>Mock 'Class' expected :new with ({}) once, but received it 0 times<BR>./spec/controllers/tickets_controller_spec.rb:16:<BR><BR>If I omit @params = {} then I get the error as following<BR><BR>1)<BR>Spec::Mocks::MockExpectationError in 'TicketsController handling POST /tickets should create a new ticket' <BR>Mock 'Class' expected :new with (any args) once, but received it 0 times<BR>./spec/controllers/tickets_controller_spec.rb:16:<BR><BR>So its not receiving the new method at all even though I clearly called it.<BR> Could it be possible that the issue is with the actual Ticket model itself?<BR><BR><DIV><SPAN class="gmail_quote">On 8/17/07, <B class="gmail_sendername">David Chelimsky</B> &lt;<A href="mailto:dchelimsky@gmail.com">dchelimsky@gmail.com </A>&gt; wrote:</SPAN><BLOCKQUOTE class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">On 8/17/07, Andrew WC Brown &lt;<A href="mailto:omen.king@gmail.com">omen.king@gmail.com </A>&gt; wrote:<BR>&gt; I've been off the rspec for a few months and I'm trying to get back on it.<BR>&gt;<BR>&gt; 1)<BR>&gt;  Spec::Mocks::MockExpectationError in 'TicketsController<BR>&gt; handling POST /tickets should create a new ticket' <BR>&gt;  Mock 'Ticket_1001' expected :new with ({}) once, but received it 0 times<BR>&gt;  ./spec/controllers/tickets_controller_spec.rb:16:<BR>&gt;  script/spec:4:<BR>&gt;<BR>&gt; class TicketsController &lt; ApplicationController <BR>&gt;<BR>&gt;   def new<BR>&gt;     Ticket.new<BR>&gt;   end<BR>&gt;<BR>&gt; end<BR>&gt;<BR>&gt; describe TicketsController, "handling POST /tickets" do<BR>&gt;<BR>&gt;   before do<BR>&gt;     @ticket = mock_model(Ticket, :to_param =&gt; '1', :save =&gt; true) <BR>&gt;     Ticket.stub!(:new).and_return(@ticket)<BR>&gt;     @params = {}<BR>&gt;   end<BR>&gt;<BR>&gt;   def do_post<BR>&gt;     post :create, :ticket =&gt; @params<BR>&gt;   end<BR>&gt;<BR>&gt;   it "should create a new ticket" do <BR>&gt;<BR>&gt; @ticket.should_receive(:new).with(@params).and_return(@ticket)<BR><BR>This is telling the ticket object to expect new, but it's the Ticket<BR>class that will receive it:<BR><BR>Ticket.should_receive(:new).with(@params).and_return(@ticket) <BR><BR>That should do it.<BR><BR>&gt;     do_post<BR>&gt;   end<BR>&gt;<BR>&gt; end<BR>&gt;<BR>&gt; Would someone provide with an explanation what I have to do to make this<BR>&gt; spec pass?<BR>&gt; Peepcode hasn't released their screen cast on rspecing controllers yet ='( <BR>&gt;<BR>&gt;<BR>&gt;<BR>&gt;<BR>&gt;<BR>&gt; _______________________________________________<BR>&gt; rspec-users mailing list<BR>&gt; <A href="mailto:rspec-users@rubyforge.org">rspec-users@rubyforge.org</A><BR>&gt; <A href="http://rubyforge.org/mailman/listinfo/rspec-users"> http://rubyforge.org/mailman/listinfo/rspec-users</A><BR>&gt;<BR>_______________________________________________<BR>rspec-users mailing list<BR><A href="mailto:rspec-users@rubyforge.org">rspec-users@rubyforge.org</A><BR><A href="http://rubyforge.org/mailman/listinfo/rspec-users"> http://rubyforge.org/mailman/listinfo/rspec-users</A><BR></BLOCKQUOTE></DIV><BR><BR clear="all"><BR>-- <BR>Monsterbox Productions<BR>putting small businesses on-line<BR><BR>1319 Victoria Avenue East<BR>Thunder Bay, Ontario P7C 1C3 <BR>Canada<BR><BR>Andrew WC Brown<BR>web-developer and owner<BR><A href="mailto:andrew@monsterboxpro.com">andrew@monsterboxpro.com</A><BR>P: 807-626-9009<BR>F: 807-624-2705<DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">_______________________________________________</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">rspec-users mailing list</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><A href="mailto:rspec-users@rubyforge.org">rspec-users@rubyforge.org</A></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><A href="http://rubyforge.org/mailman/listinfo/rspec-users">http://rubyforge.org/mailman/listinfo/rspec-users</A></DIV> </BLOCKQUOTE></DIV><BR></DIV></DIV></BODY></HTML>