From 54d519e494cb64661c1eda6cd16767a817a6e4b6 Mon Sep 17 00:00:00 2001 From: Dave Spurr Date: Wed, 17 Mar 2021 21:36:23 +0000 Subject: [PATCH] Fix issue when hash has symbol value for type #29 --- lib/jsonapi/rspec/type.rb | 2 +- spec/jsonapi/type_spec.rb | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/jsonapi/rspec/type.rb b/lib/jsonapi/rspec/type.rb index 75cff4e..57541ce 100644 --- a/lib/jsonapi/rspec/type.rb +++ b/lib/jsonapi/rspec/type.rb @@ -3,7 +3,7 @@ module RSpec module Type ::RSpec::Matchers.define :have_type do |expected| match do |actual| - JSONAPI::RSpec.as_indifferent_hash(actual)['type'] == expected.to_s + JSONAPI::RSpec.as_indifferent_hash(actual)['type'].to_s == expected.to_s end end end diff --git a/spec/jsonapi/type_spec.rb b/spec/jsonapi/type_spec.rb index 1b23233..be12962 100644 --- a/spec/jsonapi/type_spec.rb +++ b/spec/jsonapi/type_spec.rb @@ -5,6 +5,14 @@ expect('type' => 'foo').to have_type('foo') end + it 'succeeds when expectation is symbol' do + expect('type' => 'foo').to have_type(:foo) + end + + it 'succeeds when type is a symbol' do + expect('type' => :foo).to have_type('foo') + end + it 'fails when type mismatches' do expect('type' => 'foo').not_to have_type('bar') end