我正在试着让这个规范通过,但我不知道它意味着什么。这是完整的规格说明。第二个示例失败了。
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)>'发布于 2013-10-10 21:43:13
第二个示例中的以下语句:
experience_level = ExperienceLevel.create!(name: 'test'), valid_attributes与以下相同:
experience_level = [ExperienceLevel.create!(name: 'test'), valid_attributes]换句话说,它是从赋值操作符右侧的两个逗号分隔的值中创建一个数组,并将该数组赋值给experience_level。这至少是你考试失败的一个原因。
https://stackoverflow.com/questions/19306019
复制相似问题