作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
"MyString"}) got: ("MyStri-6ren">
我正在升级到 Rails 5,即使我传递了我应该传递的数据,它也破坏了我的 RSpec。
问题显然在这里:
expected: ({"name"=>"MyString"})
got: (<ActionController::Parameters {"name"=>"MyString"} permitted: true>)
expect_any_instance_of(Hospital).to receive(:update).with({ "name" => "MyString" })
expect_any_instance_of(Hospital).to receive(:update).with(params: { "name" => "MyString" }, permitted: true)
2) HospitalsController PUT update with valid params updates the requested hospital
Failure/Error: if @hospital.update(hospital_params)
#<Hospital id: 43, name: "MyString", reference_code: "RefCod", image_file_name: nil, image_content_type: nil, image_file_size: nil, image_updated_at: nil, contact_phone: "+61-000-000-000", website_link: "www.example.com", street_number: "01", street: "Somewhere St", suburb: "Suburb", state: "ACT", postcode: "1111", description: "MyText MyText MyText MyText MyText MyText MyText M...", areas_of_specialization: "MyText MyText MyText MyText MyText MyText MyText M...", created_at: "2016-07-24 22:28:24", updated_at: "2016-07-24 22:28:24"> received :update with unexpected arguments
expected: ({"name"=>"MyString"})
got: (<ActionController::Parameters {"name"=>"MyString"} permitted: true>)
Diff:
@@ -1,2 +1,2 @@
-[{"name"=>"MyString"}]
+[<ActionController::Parameters {"name"=>"MyString"} permitted: true>]
# ./app/controllers/hospitals_controller.rb:54:in `block in update'
describe "PUT update" do
describe "with valid params" do
it "updates the requested hospital" do
hospital = Hospital.create! valid_attributes
# Assuming there are no other hospitals in the database, this
# specifies that the Hospital created on the previous line
# receives the :update_attributes message with whatever params are
# submitted in the request.
expect_any_instance_of(Hospital).to receive(:update).with({ "name" => "MyString" })
put :update, {:id => hospital.to_param, :hospital => { "name" => "MyString" }}, valid_session
end
it "assigns the requested hospital as @hospital" do
hospital = Hospital.create! valid_attributes
put :update, {:id => hospital.to_param, :hospital => valid_attributes}, valid_session
expect(assigns(:hospital)).to eq(hospital)
end
it "redirects to the hospital" do
hospital = Hospital.create! valid_attributes
put :update, {:id => hospital.to_param, :hospital => valid_attributes}, valid_session
expect(response).to redirect_to(hospital)
end
end
...etc
最佳答案
您是否尝试过使用 ActionController::Parameters 对象作为您期望的值?
如:expect_any_instance_of(Hospital).to receive(:update).with(ActionController::Parameters.new('name':'MyString'))
关于ruby-on-rails - 如何在Rails 5中的RSpec中期待Params哈希?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38557529/
我是一名优秀的程序员,十分优秀!