【发布时间】:2020-02-12 00:16:50
【问题描述】:
我正在尝试测试控制器中 show 方法的 reponse.json 输出:
describe "#show" do
let!(:animal){create(:animal, name:"Cat"}
let(:params) {{id: animal.id}}
subject {get :show, params: params}
context "when animal campaign exists" do
it "should have the expected keys" do
subject
response_json = JSON.parse(response.body)
expected_keys = [
"animal_name",
"id",
]
expect(response_json).to include(*expected_keys)
输出的预期对象未与expected_keys 进行比较:
expected {"animal_name" => "Cat, "animal_id" => 6999}
Diff:
@@ -1,23 +1,23 @@
-["animal_name",
- "animal_id"]
如何查看expected_keys?
【问题讨论】:
-
试试
expect(response_json.keys).to include(*expected_keys)
标签: ruby-on-rails ruby rspec