From 2162b92e242e887cfe3855815b9d6be70c49946c Mon Sep 17 00:00:00 2001 From: Ivan Arakcheev Date: Sun, 16 Jan 2022 10:33:41 +0200 Subject: [PATCH 1/2] Convert have_id matcher argument to string. --- lib/jsonapi/rspec/id.rb | 2 +- spec/jsonapi/id_spec.rb | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/jsonapi/rspec/id.rb b/lib/jsonapi/rspec/id.rb index 504df38..ef9bfe7 100644 --- a/lib/jsonapi/rspec/id.rb +++ b/lib/jsonapi/rspec/id.rb @@ -3,7 +3,7 @@ module RSpec module Id ::RSpec::Matchers.define :have_id do |expected| match do |actual| - JSONAPI::RSpec.as_indifferent_hash(actual)['id'] == expected + JSONAPI::RSpec.as_indifferent_hash(actual)['id'].to_s == expected.to_s end end end diff --git a/spec/jsonapi/id_spec.rb b/spec/jsonapi/id_spec.rb index 96a42d0..00be9a1 100644 --- a/spec/jsonapi/id_spec.rb +++ b/spec/jsonapi/id_spec.rb @@ -5,6 +5,14 @@ expect('id' => 'foo').to have_id('foo') end + it 'succeeds when expectation is integer' do + expect('id' => '123').to have_id(123) + end + + it 'succeeds when id is symbol' do + expect('id' => :foo).to have_id('foo') + end + it 'fails when id mismatches' do expect('id' => 'foo').not_to have_id('bar') end From 27bbefdcfd97e3cd10681d9b4d65545090f518bb Mon Sep 17 00:00:00 2001 From: Ivan Arakcheev Date: Mon, 17 Jan 2022 20:08:41 +0200 Subject: [PATCH 2/2] Don't convert actual id in have_id matcher --- lib/jsonapi/rspec/id.rb | 2 +- spec/jsonapi/id_spec.rb | 4 ---- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/lib/jsonapi/rspec/id.rb b/lib/jsonapi/rspec/id.rb index ef9bfe7..150379b 100644 --- a/lib/jsonapi/rspec/id.rb +++ b/lib/jsonapi/rspec/id.rb @@ -3,7 +3,7 @@ module RSpec module Id ::RSpec::Matchers.define :have_id do |expected| match do |actual| - JSONAPI::RSpec.as_indifferent_hash(actual)['id'].to_s == expected.to_s + JSONAPI::RSpec.as_indifferent_hash(actual)['id'] == expected.to_s end end end diff --git a/spec/jsonapi/id_spec.rb b/spec/jsonapi/id_spec.rb index 00be9a1..d4e296e 100644 --- a/spec/jsonapi/id_spec.rb +++ b/spec/jsonapi/id_spec.rb @@ -9,10 +9,6 @@ expect('id' => '123').to have_id(123) end - it 'succeeds when id is symbol' do - expect('id' => :foo).to have_id('foo') - end - it 'fails when id mismatches' do expect('id' => 'foo').not_to have_id('bar') end