diff --git a/spec/requests/api/v1/admin/domain_blocks_spec.rb b/spec/requests/api/v1/admin/domain_blocks_spec.rb index 415281a93..3aa79d3ce 100644 --- a/spec/requests/api/v1/admin/domain_blocks_spec.rb +++ b/spec/requests/api/v1/admin/domain_blocks_spec.rb @@ -94,7 +94,7 @@ RSpec.describe 'Domain Blocks' do subject expect(response).to have_http_status(200) - expect(body_as_json).to eq( + expect(body_as_json).to match( { id: domain_block.id.to_s, domain: domain_block.domain, diff --git a/spec/requests/api/v1/instances/translation_languages_spec.rb b/spec/requests/api/v1/instances/translation_languages_spec.rb index 0b7dd8314..7cfb24e86 100644 --- a/spec/requests/api/v1/instances/translation_languages_spec.rb +++ b/spec/requests/api/v1/instances/translation_languages_spec.rb @@ -26,7 +26,7 @@ describe 'Translation Languages' do .to have_http_status(200) expect(body_as_json) - .to eq({ und: %w(en de), en: ['de'] }) + .to match({ und: %w(en de), en: ['de'] }) end private diff --git a/spec/requests/api/v1/lists_spec.rb b/spec/requests/api/v1/lists_spec.rb index 4635e936f..cf5ac28a5 100644 --- a/spec/requests/api/v1/lists_spec.rb +++ b/spec/requests/api/v1/lists_spec.rb @@ -60,7 +60,7 @@ RSpec.describe 'Lists' do subject expect(response).to have_http_status(200) - expect(body_as_json).to eq({ + expect(body_as_json).to match({ id: list.id.to_s, title: list.title, replies_policy: list.replies_policy, @@ -144,7 +144,7 @@ RSpec.describe 'Lists' do expect(response).to have_http_status(200) list.reload - expect(body_as_json).to eq({ + expect(body_as_json).to match({ id: list.id.to_s, title: list.title, replies_policy: list.replies_policy, diff --git a/spec/requests/api/v1/notifications/requests_spec.rb b/spec/requests/api/v1/notifications/requests_spec.rb index c385fb349..45bb71adb 100644 --- a/spec/requests/api/v1/notifications/requests_spec.rb +++ b/spec/requests/api/v1/notifications/requests_spec.rb @@ -133,7 +133,7 @@ RSpec.describe 'Requests' do subject expect(response).to have_http_status(200) - expect(body_as_json).to eq({ merged: true }) + expect(body_as_json).to match({ merged: true }) end end @@ -146,7 +146,7 @@ RSpec.describe 'Requests' do subject expect(response).to have_http_status(200) - expect(body_as_json).to eq({ merged: false }) + expect(body_as_json).to match({ merged: false }) end end end diff --git a/spec/requests/api/v1/statuses/sources_spec.rb b/spec/requests/api/v1/statuses/sources_spec.rb index 723b81905..c7b160382 100644 --- a/spec/requests/api/v1/statuses/sources_spec.rb +++ b/spec/requests/api/v1/statuses/sources_spec.rb @@ -22,7 +22,7 @@ RSpec.describe 'Sources' do subject expect(response).to have_http_status(200) - expect(body_as_json).to eq({ + expect(body_as_json).to match({ id: status.id.to_s, text: status.text, spoiler_text: status.spoiler_text, @@ -51,7 +51,7 @@ RSpec.describe 'Sources' do subject expect(response).to have_http_status(200) - expect(body_as_json).to eq({ + expect(body_as_json).to match({ id: status.id.to_s, text: status.text, spoiler_text: status.spoiler_text, diff --git a/spec/requests/api/v1/statuses_spec.rb b/spec/requests/api/v1/statuses_spec.rb index 2f99b35e7..3e91fcdd9 100644 --- a/spec/requests/api/v1/statuses_spec.rb +++ b/spec/requests/api/v1/statuses_spec.rb @@ -154,7 +154,7 @@ describe '/api/v1/statuses' do subject expect(response).to have_http_status(422) - expect(body_as_json[:unexpected_accounts].map { |a| a.slice(:id, :acct) }).to eq [{ id: bob.id.to_s, acct: bob.acct }] + expect(body_as_json[:unexpected_accounts].map { |a| a.slice(:id, :acct) }).to match [{ id: bob.id.to_s, acct: bob.acct }] end end diff --git a/spec/requests/api/v2/filters_spec.rb b/spec/requests/api/v2/filters_spec.rb index fd0483abb..8609e7dca 100644 --- a/spec/requests/api/v2/filters_spec.rb +++ b/spec/requests/api/v2/filters_spec.rb @@ -63,7 +63,7 @@ RSpec.describe 'Filters' do expect(json[:title]).to eq 'magic' expect(json[:filter_action]).to eq 'hide' expect(json[:context]).to eq ['home'] - expect(json[:keywords].map { |keyword| keyword.slice(:keyword, :whole_word) }).to eq [{ keyword: 'magic', whole_word: true }] + expect(json[:keywords].map { |keyword| keyword.slice(:keyword, :whole_word) }).to match [{ keyword: 'magic', whole_word: true }] end it 'creates a filter', :aggregate_failures do diff --git a/spec/requests/api/v2_alpha/notifications_spec.rb b/spec/requests/api/v2_alpha/notifications_spec.rb index 9d9eb34eb..7663d215e 100644 --- a/spec/requests/api/v2_alpha/notifications_spec.rb +++ b/spec/requests/api/v2_alpha/notifications_spec.rb @@ -235,7 +235,7 @@ RSpec.describe 'Notifications' do expect(response).to have_http_status(200) expect(body_as_json[:partial_accounts].size).to be > 0 - expect(body_as_json[:partial_accounts][0].keys).to contain_exactly(:acct, :avatar, :avatar_static, :bot, :id, :locked, :url) + expect(body_as_json[:partial_accounts][0].keys.map(&:to_sym)).to contain_exactly(:acct, :avatar, :avatar_static, :bot, :id, :locked, :url) expect(body_as_json[:partial_accounts].pluck(:id)).to_not include(recent_account.id.to_s) expect(body_as_json[:accounts].pluck(:id)).to include(recent_account.id.to_s) end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 496ebfd09..248c2c410 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -39,11 +39,7 @@ RSpec.configure do |config| end def body_as_json - json_str_to_hash(response.body) -end - -def json_str_to_hash(str) - JSON.parse(str, symbolize_names: true) + response.parsed_body end def serialized_record_json(record, serializer, adapter: nil) diff --git a/spec/support/matchers/json/match_json_schema.rb b/spec/support/matchers/json/match_json_schema.rb index b4ced8add..05dc1ee5a 100644 --- a/spec/support/matchers/json/match_json_schema.rb +++ b/spec/support/matchers/json/match_json_schema.rb @@ -9,7 +9,9 @@ end RSpec::Matchers.define :match_json_values do |values| match do |string| - expect(json_str_to_hash(string)) + parsed_json = JSON.parse(string, symbolize_names: true) + + expect(parsed_json) .to include(values) end