From fffea50a0bcff552aa3277573413a3a834191f4a Mon Sep 17 00:00:00 2001 From: Nikita Esaulov Date: Tue, 20 Apr 2021 01:16:38 +0300 Subject: [PATCH] New Style/HashConversion cop --- spec/builder_spec.rb | 14 +++++++------- spec/copier_spec.rb | 2 +- spec/hash_utils_spec.rb | 8 ++++---- spec/multiple_serializers_spec.rb | 4 ++-- spec/schema_definer_spec.rb | 2 +- spec/wrapper_spec.rb | 2 +- 6 files changed, 16 insertions(+), 16 deletions(-) diff --git a/spec/builder_spec.rb b/spec/builder_spec.rb index 2a79bbe..30a53f3 100644 --- a/spec/builder_spec.rb +++ b/spec/builder_spec.rb @@ -31,14 +31,14 @@ def multi_struct let(:carrier) { nil } context 'valid schema is passed' do - let(:schema) { Hash[foo: String, bar: Array] } + let(:schema) { { foo: String, bar: Array } } it 'returns hash with correct values' do is_expected.to eq(foo: 'A string', bar: [1, 2, 4]) end context 'with hash as a type' do - let(:schema) { Hash[foo: String, baz: Hash] } + let(:schema) { { foo: String, baz: Hash } } it 'returns hash with correct values' do is_expected.to eq(foo: 'A string', baz: { key: :value }) @@ -46,7 +46,7 @@ def multi_struct end context 'with nested values' do - let(:schema) { Hash[foo: String, nested: { bar: Array, again: { baz: Hash } }] } + let(:schema) { { foo: String, nested: { bar: Array, again: { baz: Hash } } } } it 'returns hash with correct values' do is_expected.to eq(foo: 'A string', nested: { bar: [1, 2, 4], again: { baz: { key: :value } } }) @@ -54,7 +54,7 @@ def multi_struct end context 'with nested objects' do - let(:schema) { Hash[foo: String, struct: { foo: Integer, bar: Array }] } + let(:schema) { { foo: String, struct: { foo: Integer, bar: Array } } } it 'invokes nested methods on the object' do is_expected.to eq(foo: 'A string', struct: { foo: 42, bar: [1] }) @@ -62,7 +62,7 @@ def multi_struct end context 'with multi-nested objects' do - let(:schema) { Hash[foo: String, multi_struct: { foo: Integer, bar: { baz: Array } }] } + let(:schema) { { foo: String, multi_struct: { foo: Integer, bar: { baz: Array } } } } it 'invokes nested methods on the objects' do is_expected.to eq(foo: 'A string', multi_struct: { foo: 42, bar: { baz: [1] } }) @@ -72,7 +72,7 @@ def multi_struct context 'invalid schema is passed' do context 'with undefined method' do - let(:schema) { Hash[not_a_method: String] } + let(:schema) { { not_a_method: String } } let(:message) { /undefined method `not_a_method'.* You have probably defined a key in the schema that doesn't have a corresponding method/ } # rubocop:disable Layout/LineLength it 'raises UndefinedMethodError' do @@ -81,7 +81,7 @@ def multi_struct end context 'with invalid types' do - let(:schema) { Hash[foo: Integer, bar: String] } + let(:schema) { { foo: Integer, bar: String } } it 'raises TypeError' do expect { result } diff --git a/spec/copier_spec.rb b/spec/copier_spec.rb index 6f947e5..f47eb89 100644 --- a/spec/copier_spec.rb +++ b/spec/copier_spec.rb @@ -2,7 +2,7 @@ RSpec.describe Surrealist::Copier do describe '#deep_copy' do - let(:object) { Hash[animal: { kind: 'dog', name: 'Rusty' }] } + let(:object) { { animal: { kind: 'dog', name: 'Rusty' } } } it_behaves_like 'hash is cloned deeply and it`s structure is not changed' do let(:copy) { Surrealist::Copier.deep_copy(object) } diff --git a/spec/hash_utils_spec.rb b/spec/hash_utils_spec.rb index 4189a6a..8d6c28c 100644 --- a/spec/hash_utils_spec.rb +++ b/spec/hash_utils_spec.rb @@ -5,13 +5,13 @@ subject(:camelized_hash) { described_class.camelize_hash(hash) } context 'not nested hash' do - let(:hash) { Hash[snake_key: 'some value'] } + let(:hash) { { snake_key: 'some value' } } it { expect(camelized_hash.keys.first).to eq(:snakeKey) } end context 'nested hash' do - let(:hash) { Hash[snake_key: { nested_key: { one_more_level: true } }] } + let(:hash) { { snake_key: { nested_key: { one_more_level: true } } } } it 'camelizes hash recursively' do expect(camelized_hash).to eq(snakeKey: { nestedKey: { oneMoreLevel: true } }) @@ -19,7 +19,7 @@ end context 'mixed symbols and string' do - let(:hash) { Hash[snake_key: { 'nested_key' => { 'one_more_level': true } }] } + let(:hash) { { snake_key: { 'nested_key' => { 'one_more_level': true } } } } it 'camelizes hash recursively' do expect(camelized_hash).to eq(snakeKey: { 'nestedKey' => { 'oneMoreLevel': true } }) @@ -27,7 +27,7 @@ end context 'array as hash key' do - let(:hash) { Hash[['some_key'] => 'value'] } + let(:hash) { { ['some_key'] => 'value' } } it { expect(camelized_hash.keys.first).to eq(['some_key']) } end diff --git a/spec/multiple_serializers_spec.rb b/spec/multiple_serializers_spec.rb index 3b7b41a..7e6373b 100644 --- a/spec/multiple_serializers_spec.rb +++ b/spec/multiple_serializers_spec.rb @@ -42,13 +42,13 @@ def initialize(id, title, author) describe 'single item' do context 'default' do - let(:expectation) { Hash[id: 1, title: 'Ruby is dead', author: { name: 'John' }] } + let(:expectation) { { id: 1, title: 'Ruby is dead', author: { name: 'John' } } } it { expect(post.surrealize).to eq(expectation.to_json) } end context 'specific' do - let(:expectation) { Hash[id: 1, title: 'Ruby is dead'] } + let(:expectation) { { id: 1, title: 'Ruby is dead' } } it { expect(post.surrealize(for: :short)).to eq(expectation.to_json) } it { expect(post.surrealize(serializer: ShortPostSerializer)).to eq(expectation.to_json) } diff --git a/spec/schema_definer_spec.rb b/spec/schema_definer_spec.rb index 54ccb23..8fa10bd 100644 --- a/spec/schema_definer_spec.rb +++ b/spec/schema_definer_spec.rb @@ -6,7 +6,7 @@ class Person; include Surrealist; end let(:instance) { Person } context 'when hash is passed' do - let(:schema) { Hash[a: 1, b: {}] } + let(:schema) { { a: 1, b: {} } } before { described_class.call(instance, schema) } diff --git a/spec/wrapper_spec.rb b/spec/wrapper_spec.rb index d13a23a..e9723ae 100644 --- a/spec/wrapper_spec.rb +++ b/spec/wrapper_spec.rb @@ -37,7 +37,7 @@ def no_args_provided? end end - let(:object) { Hash[a: 3, nested_thing: { key: :value }] } + let(:object) { { a: 3, nested_thing: { key: :value } } } let(:klass) { 'SomeClass' } let(:error) { "Can't wrap schema in root key - class name was not passed" }