0
我有一個端點,它使用從ActiveModelSerializer添加的對象的屬性+屬性進行響應。我想編寫一個測試來檢查響應是否有密鑰。如何測試API響應在RSpec中具有密鑰
讓我們假設說對象(比如一棵樹)具有這些鍵
expected_tree_attributes = [:height, :age, :color]
如何正確寫這個測試?我可以寫:
subject { post :obtain_tree_info, { id: tree.id } }
response = JSON.parse(subject.body)
expected(response).to include(*expected_tree_attributes)
那是......可以接受嗎?