[rspec-users] what does 'these' mean in a PUT controller spec?

Gordon anexiole at gmail.com
Mon Jan 16 05:59:17 EST 2012


hi, all,

  the spec above is found in my controller spec for a 'category'
resource.

  It's a generated spec.

----- start extract --------------------------------------------
  describe "PUT update" do
    describe "with valid params" do
      it "updates the requested category" do
        category = Category.create! valid_attributes
        # Assuming there are no other categories in the database, this
        # specifies that the Category created on the previous line
        # receives the :update_attributes message with whatever params
are
        # submitted in the request.
 
Category.any_instance.should_receive(:update_attributes).with({'these'
=> 'params'})
        put :update, :id => category.id, :category => {'these' =>
'params'}
      end
----- end extract --------------------------------------------

When the spec is run, it fails with the error below.

----- start extract --------------------------------------------

  1) CategoriesController PUT update with valid params updates the
requested category
     Failure/Error: put :update, :id => category.id, :category =>
{'these' => 'params'}
       #<Category:0x000001017cd498> received :update_attributes with
unexpected arguments
         expected: ({"these"=>"params"})
              got: ({"these"=>"params", "updated_by"=>1})
     # /Users/anexiole/projects/try_rails/app/controllers/
categories_controller.rb:72:in `block in update'
     # /Users/anexiole/projects/try_rails/app/controllers/
categories_controller.rb:71:in `update'
     # ./categories_controller_spec.rb:92:in `block (4 levels) in <top
(required)>'

Finished in 19.15 seconds
16 examples, 1 failure

Failed examples:

rspec ./categories_controller_spec.rb:85 # CategoriesController PUT
update with valid params updates the requested category

----- end extract --------------------------------------------

  My 'update' method in the categories controller file itself has one
added rule for which
I will assign the current user's id  to the updated_by attribute
before a call to update_attribute is made.

----- start extract --------------------------------------------
  # PUT /categories/1
  # PUT /categories/1.json
  def update
    # Record current user's id as he/she created the part
    params[:category][:updated_by] = current_user.id

    @category = Category.find(params[:id])

    respond_to do |format|
      if @category.update_attributes(params[:category])
        format.html { redirect_to @category, notice: 'Category was
successfully updated.' }
        format.json { head :ok }
      else
        format.html { render action: "edit" }
        format.json { render json: @category.errors,
status: :unprocessable_entity }
      end
    end
  end

----- end extract --------------------------------------------


Can someone please tell me what does 'these' refer to in the spec?
Where can I read up more about them?
I would like to fix the failing spec example.

Thank you

 Gorodn


More information about the rspec-users mailing list