1

我试图让这个规范通过,但我不知道这意味着什么。这是完整的规格。第二例子是失败的例子。

describe "PUT update" do
    describe "with valid params" do
      it "updates the requested experience_level" do
        experience_level = ExperienceLevel.create! valid_attributes
        # Assuming there are no other experience_levels in the database, this
        # specifies that the ExperienceLevel created on the previous line
        # receives the :update_attributes message with whatever params are
        # submitted in the request.
        ExperienceLevel.any_instance.should_receive(:update_attributes).with({ "name" => "MyString" })
        put :update, {:id => experience_level.to_param, :experience_level => { "name" => "MyString" }}
      end

      it "assigns the requested experience_level as @experience_level" do
        experience_level = ExperienceLevel.create!(name: 'test'), valid_attributes
        put :update, {:id => experience_level.to_param, :experience_level => valid_attributes}
        assigns(:experience_level).should eq(experience_level)
      end

      it "redirects to the experience_level" do
        experience_level = ExperienceLevel.create! valid_attributes
        put :update, {:id => experience_level.to_param, :experience_level => valid_attributes}
        response.should redirect_to(experience_level)
      end
    end

这是终端中的消息:

1) ExperienceLevelsController PUT update with valid params assigns the requested experience_level as @experience_level
     Failure/Error: assigns(:experience_level).should eq(experience_level)

       expected: [#<ExperienceLevel id: 1, name: "test", description: nil, created_at: "2013-10-10 20:40:05", updated_at: "2013-10-10 20:40:05">, {"name"=>"MyString"}]
            got: #<ExperienceLevel id: 1, name: "MyString", description: nil, created_at: "2013-10-10 20:40:05", updated_at: "2013-10-10 20:40:05">

       (compared using ==)

       Diff:
       @@ -1,3 +1,2 @@
       -[#<ExperienceLevel id: 1, name: "test", description: nil, created_at: "2013-10-10 20:40:05", updated_at: "2013-10-10 20:40:05">,
       - {"name"=>"MyString"}]
       +#<ExperienceLevel id: 1, name: "MyString", description: nil, created_at: "2013-10-10 20:40:05", updated_at: "2013-10-10 20:40:05">

     # ./spec/controllers/experience_levels_controller_spec.rb:100:in `block (4 levels) in <top (required)>'
4

1 回答 1

1

第二个示例中的以下语句:

experience_level = ExperienceLevel.create!(name: 'test'), valid_attributes

是相同的:

experience_level = [ExperienceLevel.create!(name: 'test'), valid_attributes]

换句话说,它从赋值运算符右侧的两个逗号分隔值创建一个数组,并将该数组分配给experience_level. 这至少是您的测试失败的原因之一。

于 2013-10-10T21:43:13.680 回答