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

Andrew WC Brown omen.king at gmail.com
Mon Aug 20 13:42:37 EDT 2007


I solved my problem.

  def create
    @ticket = Ticket.new(params[:ticket])
    @ticket.user = current_user
    if @ticket.save
      redirect_to tickets_path
    else
      render new_ticket_path(params[:user_id])
    end
  end

Like my mom would nag:
"If you rspec'd from the start you wouldn't have to clean up this mess"


On 8/20/07, Andrew WC Brown <omen.king at gmail.com> wrote:
>
> Still having trouble ='(
>
>
>   def create
>     @user = User.find(params[:user_id])
>     @ticket = @user.tickets.build(params[:ticket])
>     if @ticket.save
>       redirect_to tickets_path
>     else
>       render new_usr_ticket_path(params[:user_id])
>     end
>   end
>
> describe TicketsController, "handling POST /tickets" do
>    before do
>      @ticket = mock_model(Ticket, :save => true)
>      @user = mock_model(User)
>      @user.stub!(:tickets).and_return(@user_tickets_association)
>      @params = {}
>    end
>    def do_post
>      post :create, :ticket => @params, :user_id => "user_id"
>    end
>    it "should find the user" do
>      User.should_receive(:find).with("user_id").and_return(@user)
>      do_post
> end
>
> 8)
> Spec::Mocks::MockExpectationError in 'TicketsController handling POST
> /tickets should find the user'
> Mock 'Class' expected :find with ("user_id") once, but received it 0 times
> ./spec/controllers/tickets_controller_spec.rb:19:
> script/spec:4:
>
>
> That really looks like it should pass.
>
>
> On 8/17/07, Rupert Voelcker <rupespad1 at mac.com> wrote:
> >
> > > thats pretty much what I thought, I'll give it a push around and e-
> > > mail back the results
> >
> > cool - good luck ...I'm off to bed as it's 1am here in the UK but I'm
> > sure one of the useful chaps round here 'll help you out with any probs
> >
> > btw, I just noticed I've put @ticket_params = {} in the before
> > declaration and it needs to be @params = {}
> >
> > Cheers
> >
> >
> >
> > _______________________________________________
> > rspec-users mailing list
> > rspec-users at rubyforge.org
> > http://rubyforge.org/mailman/listinfo/rspec-users
> >
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070820/b6c699e4/attachment.html 


More information about the rspec-users mailing list