RSpec を使用して、値がどうなるかわからない 2 つのハッシュを比較する方法はありますか? を使用してみましinstance_of
たが、うまくいかないようです。
私のテストでは、POST 要求で新しいデバイス オブジェクトを作成しており、正しい JSON 応答が返されることを確認したいと考えています。デバイスのUUIDを作成しています(リレーショナルデータベースは使用していません)が、明らかにその値がどうなるかわかりませんし、あまり気にしません。
post "/projects/1/devices.json", name: 'New Device'
expected = {'name' => 'New Device', 'uuid' => instance_of(String), 'type' => 'Device'}
JSON.parse(body).should == expected
そして、次のエラーが表示されます。
1) DevicesController API adds a new device to a project
Failure/Error: JSON.parse(body).should == expected
expected: {"name"=>"New Device", "uuid"=>#<RSpec::Mocks::ArgumentMatchers::InstanceOf:0x5a27147d @klass=String>, "type"=>"Device"}
got: {"name"=>"New Device", "uuid"=>"ef773465-7cec-48fd-b2a7-f1da10d1595a", "type"=>"Device"} (using ==)
Diff:
@@ -1,4 +1,4 @@
"name" => "New Device",
"type" => "Device",
-"uuid" => #<RSpec::Mocks::ArgumentMatchers::InstanceOf:0x5a27147d @klass=String>
+"uuid" => "ef773465-7cec-48fd-b2a7-f1da10d1595a"
# ./spec/api/devices_spec.rb:37:in `(root)'