Ruby on rails RSpec生成的测试有什么作用;将要求的经验“U级”指定为@experience“U级”;什么意思?

Ruby on rails RSpec生成的测试有什么作用;将要求的经验“U级”指定为@experience“U级”;什么意思?,ruby-on-rails,rspec,Ruby On Rails,Rspec,我试图通过这个规范,但我不知道它意味着什么。这是完整的规范。第二个示例是失败的 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

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

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)>'
1)experiencelevels控制器PUT update使用有效参数将请求的体验级别指定为@experience\u级别
失败/错误:分配(:经验\级别)。应均衡(经验\级别)
应为:[#,{“name”=>“MyString”}]
得到:#
(使用==进行比较)
差异:
@@ -1,3 +1,2 @@
-[#,
-{“name”=>“MyString”}]
+#
#./spec/controller/experience\u levels\u controller\u spec.rb:100:in‘block(4层)in’

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

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

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

换句话说,它是从赋值运算符右侧的两个逗号分隔的值创建一个数组,并将该数组赋值到
体验级别
。这至少是测试失败的一个原因。

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

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
experience_level = ExperienceLevel.create!(name: 'test'), valid_attributes
同:

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

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

您正在使用一个名为test的名称设置体验级别,但是在调用put时使用了有效的属性,其中的名称可能是MyString?起初我认为这也是问题所在,但将test更改为MyString并不会导致其通过。您正在使用test的名称设置体验级别,但在调用put时使用了有效的_属性,其中的名称可能是MyString?我起初认为这也是问题所在,但将test更改为MyString并不会导致其通过。
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