summaryrefslogtreecommitdiff
path: root/spec/hashie
diff options
context:
space:
mode:
authorMichael Herold <michael.j.herold@gmail.com>2018-02-03 10:23:14 -0600
committerMichael Herold <michael.j.herold@gmail.com>2018-06-17 11:04:56 -0500
commit5a6ffc7e2df076c266c322ae9272b098b3ab40ed (patch)
tree578b274928ce6ac710922c85d050771f52753736 /spec/hashie
parent8fc10095fc409f4db495713c92c0cf8e31d3bfc1 (diff)
downloadhashie-5a6ffc7e2df076c266c322ae9272b098b3ab40ed.tar.gz
Update Rubocop and address the addressable todos
This is a big step forward in our Rubocop setup. I addressed all of the todos from the current version of Rubocop that made sense to. The only things that remain are metrics and one cop that relies on the line length metric to work. I made some judgment calls on disabling a few cops: 1. The `Layout/IndentHeredoc` cop wants you to either use the squiggly heredoc from Ruby 2.3 or introduce a library. Since we are a low-level library that is used as a transitive dependency, we cannot introduce another library as a dependence, so that option is out. Also, we support Rubies back to 2.0 currently, so using the squiggly heredoc isn't an option. Once we remove support for Rubies older than 2.3, we can switch to the squiggly heredoc cop. 2. The `Naming/FileName` cop was reporting false positives for a few files in the repository, so I disabled it on those files. 3. The `Style/DoubleNegation` cop reports lints on a few cases where we use double negation. Given the very generic nature of Hashie, the double-negation is the easiest, clearest way to express that we want an item to be a Boolean. I disabled the cop because we exist in the gray area where this makes sense.
Diffstat (limited to 'spec/hashie')
-rw-r--r--spec/hashie/array_spec.rb2
-rw-r--r--spec/hashie/dash_spec.rb4
-rw-r--r--spec/hashie/extensions/coercion_spec.rb32
-rw-r--r--spec/hashie/extensions/deep_locate_spec.rb2
-rw-r--r--spec/hashie/extensions/deep_merge_spec.rb2
-rw-r--r--spec/hashie/extensions/indifferent_access_spec.rb14
-rw-r--r--spec/hashie/extensions/indifferent_access_with_rails_hwia_spec.rb10
-rw-r--r--spec/hashie/extensions/method_access_spec.rb6
-rw-r--r--spec/hashie/extensions/stringify_keys_spec.rb8
-rw-r--r--spec/hashie/extensions/symbolize_keys_spec.rb6
-rw-r--r--spec/hashie/mash_spec.rb17
-rw-r--r--spec/hashie/parsers/yaml_erb_parser_spec.rb6
-rw-r--r--spec/hashie/rash_spec.rb4
-rw-r--r--spec/hashie/trash_spec.rb2
14 files changed, 62 insertions, 53 deletions
diff --git a/spec/hashie/array_spec.rb b/spec/hashie/array_spec.rb
index 3aba1fb..0c35b1e 100644
--- a/spec/hashie/array_spec.rb
+++ b/spec/hashie/array_spec.rb
@@ -3,7 +3,7 @@ require 'spec_helper'
describe Array do
with_minimum_ruby('2.3.0') do
describe '#dig' do
- let(:array) { Hashie::Array.new([:a, :b, :c]) }
+ let(:array) { Hashie::Array.new(%i[a b c]) }
it 'works with a string index' do
expect(array.dig('0')).to eq(:a)
diff --git a/spec/hashie/dash_spec.rb b/spec/hashie/dash_spec.rb
index fe789de..cba42af 100644
--- a/spec/hashie/dash_spec.rb
+++ b/spec/hashie/dash_spec.rb
@@ -310,7 +310,7 @@ describe DashTest do
describe 'properties' do
it 'lists defined properties' do
- expect(described_class.properties).to eq Set.new([:first_name, :email, :count])
+ expect(described_class.properties).to eq Set.new(%i[first_name email count])
end
it 'checks if a property exists' do
@@ -348,7 +348,7 @@ describe DashTest do
end
it 'leaves only specified keys and keys with default values' do
- expect(subject.keys.sort_by(&:to_s)).to eq [:count, :first_name]
+ expect(subject.keys.sort_by(&:to_s)).to eq %i[count first_name]
expect(subject.email).to be_nil
expect(subject.count).to eq 0
end
diff --git a/spec/hashie/extensions/coercion_spec.rb b/spec/hashie/extensions/coercion_spec.rb
index 7d70ed4..31581de 100644
--- a/spec/hashie/extensions/coercion_spec.rb
+++ b/spec/hashie/extensions/coercion_spec.rb
@@ -154,7 +154,7 @@ describe Hashie::Extensions::Coercion do
it 'supports coercion for Array' do
subject.coerce_key :foo, Array[Coercable]
- instance[:foo] = %w('bar', 'bar2')
+ instance[:foo] = %w[bar bar2]
expect(instance[:foo]).to all(be_coerced)
expect(instance[:foo]).to be_a(Array)
end
@@ -162,7 +162,7 @@ describe Hashie::Extensions::Coercion do
it 'supports coercion for Set' do
subject.coerce_key :foo, Set[Coercable]
- instance[:foo] = Set.new(%w('bar', 'bar2'))
+ instance[:foo] = Set.new(%w[bar bar2])
expect(instance[:foo]).to all(be_coerced)
expect(instance[:foo]).to be_a(Set)
end
@@ -170,7 +170,7 @@ describe Hashie::Extensions::Coercion do
it 'supports coercion for Set of primitive' do
subject.coerce_key :foo, Set[Initializable]
- instance[:foo] = %w('bar', 'bar2')
+ instance[:foo] = %w[bar bar2]
expect(instance[:foo].map(&:value)).to all(eq 'String')
expect(instance[:foo]).to be_none(&:coerced?)
expect(instance[:foo]).to be_a(Set)
@@ -558,18 +558,26 @@ describe Hashie::Extensions::Coercion do
end
it 'raises a CoercionError when coercion is not possible' do
- type = if Hashie::Extensions::RubyVersion.new(RUBY_VERSION) >= Hashie::Extensions::RubyVersion.new('2.4.0')
- Integer
- else
- Fixnum
- end
+ type =
+ if Hashie::Extensions::RubyVersion.new(RUBY_VERSION) >= Hashie::Extensions::RubyVersion.new('2.4.0')
+ Integer
+ else
+ Fixnum # rubocop:disable Lint/UnifiedInteger
+ end
subject.coerce_value type, Symbol
expect { instance[:hi] = 1 }.to raise_error(Hashie::CoercionError, /Cannot coerce property :hi from #{type} to Symbol/)
end
it 'coerces Integer to String' do
- subject.coerce_value Integer, String
+ type =
+ if Hashie::Extensions::RubyVersion.new(RUBY_VERSION) >= Hashie::Extensions::RubyVersion.new('2.4.0')
+ Integer
+ else
+ Fixnum # rubocop:disable Lint/UnifiedInteger
+ end
+
+ subject.coerce_value type, String
{
fixnum: 2,
@@ -579,7 +587,7 @@ describe Hashie::Extensions::Coercion do
complex: Complex(1)
}.each do |k, v|
instance[k] = v
- if v.is_a? Integer
+ if v.is_a? type
expect(instance[k]).to be_a(String)
expect(instance[k]).to eq(v.to_s)
else
@@ -610,8 +618,8 @@ describe Hashie::Extensions::Coercion do
return !!(v =~ /^(true|t|yes|y|1)$/i)
end)
- true_values = %w(true t yes y 1)
- false_values = %w(false f no n 0)
+ true_values = %w[true t yes y 1]
+ false_values = %w[false f no n 0]
true_values.each do |v|
instance[:foo] = v
diff --git a/spec/hashie/extensions/deep_locate_spec.rb b/spec/hashie/extensions/deep_locate_spec.rb
index d174f3c..ca4b267 100644
--- a/spec/hashie/extensions/deep_locate_spec.rb
+++ b/spec/hashie/extensions/deep_locate_spec.rb
@@ -78,7 +78,7 @@ describe Hashie::Extensions::DeepLocate do
[
lambda do |_key, _value, object|
object.is_a?(Array) &&
- !object.extend(described_class).deep_locate(:match).empty?
+ !object.extend(described_class).deep_locate(:match).empty?
end,
[
hash[:query][:bool][:must],
diff --git a/spec/hashie/extensions/deep_merge_spec.rb b/spec/hashie/extensions/deep_merge_spec.rb
index aec2d7d..514176b 100644
--- a/spec/hashie/extensions/deep_merge_spec.rb
+++ b/spec/hashie/extensions/deep_merge_spec.rb
@@ -28,7 +28,7 @@ describe Hashie::Extensions::DeepMerge do
it 'merges new nested hash entries by value, not by reference' do
h1.deep_merge!(h2)
- expect { h1[:e][:e1] = 'changed' }.not_to change { h2[:e][:e1] }
+ expect { h1[:e][:e1] = 'changed' }.not_to(change { h2[:e][:e1] })
end
end
diff --git a/spec/hashie/extensions/indifferent_access_spec.rb b/spec/hashie/extensions/indifferent_access_spec.rb
index 46b2a65..fc03bc2 100644
--- a/spec/hashie/extensions/indifferent_access_spec.rb
+++ b/spec/hashie/extensions/indifferent_access_spec.rb
@@ -6,7 +6,7 @@ describe Hashie::Extensions::IndifferentAccess do
include Hashie::Extensions::IndifferentAccess
class << self
- alias_method :build, :new
+ alias build new
end
end
@@ -14,7 +14,7 @@ describe Hashie::Extensions::IndifferentAccess do
include Hashie::Extensions::IndifferentAccess
class << self
- alias_method :build, :[]
+ alias build []
end
end
@@ -22,7 +22,7 @@ describe Hashie::Extensions::IndifferentAccess do
include Hashie::Extensions::IndifferentAccess
class << self
- alias_method :build, :try_convert
+ alias build try_convert
end
end
@@ -44,7 +44,7 @@ describe Hashie::Extensions::IndifferentAccess do
include Hashie::Extensions::IndifferentAccess
end.new
- merged_hash = indifferent_hash.merge(:cat => 'meow')
+ merged_hash = indifferent_hash.merge(cat: 'meow')
expect(merged_hash[:cat]).to eq('meow')
expect(merged_hash['cat']).to eq('meow')
@@ -70,7 +70,7 @@ describe Hashie::Extensions::IndifferentAccess do
include Hashie::Extensions::IndifferentAccess
end.new
- indifferent_hash.merge!(:cat => 'meow')
+ indifferent_hash[:cat] = 'meow'
expect(indifferent_hash[:cat]).to eq('meow')
expect(indifferent_hash['cat']).to eq('meow')
@@ -126,7 +126,7 @@ describe Hashie::Extensions::IndifferentAccess do
describe '#values_at' do
it 'indifferently finds values' do
h = subject.build(:foo => 'bar', 'baz' => 'qux')
- expect(h.values_at('foo', :baz)).to eq %w(bar qux)
+ expect(h.values_at('foo', :baz)).to eq %w[bar qux]
end
it 'returns the same instance of the hash that was set' do
@@ -208,7 +208,7 @@ describe Hashie::Extensions::IndifferentAccess do
expect(h).to be_key('foo')
end
- %w(include? member? has_key?).each do |key_alias|
+ %w[include? member? has_key?].each do |key_alias|
it "is aliased as #{key_alias}" do
expect(h.send(key_alias.to_sym, :foo)).to be(true)
expect(h.send(key_alias.to_sym, 'foo')).to be(true)
diff --git a/spec/hashie/extensions/indifferent_access_with_rails_hwia_spec.rb b/spec/hashie/extensions/indifferent_access_with_rails_hwia_spec.rb
index b11f315..c53c531 100644
--- a/spec/hashie/extensions/indifferent_access_with_rails_hwia_spec.rb
+++ b/spec/hashie/extensions/indifferent_access_with_rails_hwia_spec.rb
@@ -11,7 +11,7 @@ describe Hashie::Extensions::IndifferentAccess do
include Hashie::Extensions::IndifferentAccess
class << self
- alias_method :build, :new
+ alias build new
end
end
@@ -19,7 +19,7 @@ describe Hashie::Extensions::IndifferentAccess do
include Hashie::Extensions::IndifferentAccess
class << self
- alias_method :build, :[]
+ alias build []
end
end
@@ -27,7 +27,7 @@ describe Hashie::Extensions::IndifferentAccess do
include Hashie::Extensions::IndifferentAccess
class << self
- alias_method :build, :try_convert
+ alias build try_convert
end
end
@@ -54,7 +54,7 @@ describe Hashie::Extensions::IndifferentAccess do
:foo => 'bar', 'baz' => 'qux'
)
h = subject.build(indifferent_hash)
- expect(h.values_at('foo', :baz)).to eq %w(bar qux)
+ expect(h.values_at('foo', :baz)).to eq %w[bar qux]
end
end
@@ -91,7 +91,7 @@ describe Hashie::Extensions::IndifferentAccess do
expect(h).to be_key('foo')
end
- %w(include? member? has_key?).each do |key_alias|
+ %w[include? member? has_key?].each do |key_alias|
it "is aliased as #{key_alias}" do
expect(h.send(key_alias.to_sym, :foo)).to be(true)
expect(h.send(key_alias.to_sym, 'foo')).to be(true)
diff --git a/spec/hashie/extensions/method_access_spec.rb b/spec/hashie/extensions/method_access_spec.rb
index 03528e4..9ad09c7 100644
--- a/spec/hashie/extensions/method_access_spec.rb
+++ b/spec/hashie/extensions/method_access_spec.rb
@@ -20,7 +20,7 @@ describe Hashie::Extensions::MethodReader do
end
it 'reads nil and false values out properly' do
- h = subject.new(nil: nil, false: false)
+ h = subject.new(nil: nil, false: false) # rubocop:disable Lint/BooleanSymbol
expect(h.nil).to eq nil
expect(h.false).to eq false
end
@@ -168,13 +168,13 @@ describe Hashie::Extensions::MethodOverridingWriter do
end
it 'aliases the method with two leading underscores' do
- expect(subject.__zip).to eq [[%w(zip a-dee-doo-dah)]]
+ expect(subject.__zip).to eq [[%w[zip a-dee-doo-dah]]]
end
it 'does not re-alias when overriding an already overridden method' do
subject.zip = 'test'
expect(subject.zip).to eq 'test'
- expect(subject.__zip).to eq [[%w(zip test)]]
+ expect(subject.__zip).to eq [[%w[zip test]]]
end
end
end
diff --git a/spec/hashie/extensions/stringify_keys_spec.rb b/spec/hashie/extensions/stringify_keys_spec.rb
index f5f78d8..5d3269e 100644
--- a/spec/hashie/extensions/stringify_keys_spec.rb
+++ b/spec/hashie/extensions/stringify_keys_spec.rb
@@ -14,7 +14,7 @@ shared_examples 'stringify_keys!' do
object[:abc] = 'abc'
object[123] = '123'
invoke :stringify_keys!
- expect((object.keys & %w(abc 123)).size).to eq 2
+ expect((object.keys & %w[abc 123]).size).to eq 2
end
it 'converts nested instances of the same class' do
@@ -53,7 +53,7 @@ shared_examples 'stringify_keys' do
object[:abc] = 'def'
copy = invoke :stringify_keys
expect(object.keys).to eq [:abc]
- expect(copy.keys).to eq %w(abc)
+ expect(copy.keys).to eq %w[abc]
end
end
@@ -71,7 +71,7 @@ describe Hashie::Extensions::StringifyKeys do
context 'class methods' do
subject { described_class }
- let(:object) { Hash.new }
+ let(:object) { {} }
describe '.stringify_keys' do
include_examples 'stringify_keys'
@@ -113,7 +113,7 @@ describe Hashie do
end
subject { described_class }
- let(:object) { Hash.new }
+ let(:object) { {} }
describe '.stringify_keys' do
include_examples 'stringify_keys'
diff --git a/spec/hashie/extensions/symbolize_keys_spec.rb b/spec/hashie/extensions/symbolize_keys_spec.rb
index b62fbe4..1b4e978 100644
--- a/spec/hashie/extensions/symbolize_keys_spec.rb
+++ b/spec/hashie/extensions/symbolize_keys_spec.rb
@@ -14,7 +14,7 @@ shared_examples 'symbolize_keys!' do
object['abc'] = 'abc'
object['def'] = 'def'
invoke :symbolize_keys!
- expect((object.keys & [:abc, :def]).size).to eq 2
+ expect((object.keys & %i[abc def]).size).to eq 2
end
it 'converts nested instances of the same class' do
@@ -76,7 +76,7 @@ describe Hashie::Extensions::SymbolizeKeys do
context 'class methods' do
subject { described_class }
- let(:object) { Hash.new }
+ let(:object) { {} }
describe '.symbolize_keys' do
include_examples 'symbolize_keys'
@@ -118,7 +118,7 @@ describe Hashie do
end
subject { described_class }
- let(:object) { Hash.new }
+ let(:object) { {} }
describe '.symbolize_keys' do
include_examples 'symbolize_keys'
diff --git a/spec/hashie/mash_spec.rb b/spec/hashie/mash_spec.rb
index 1a0ad4f..680f403 100644
--- a/spec/hashie/mash_spec.rb
+++ b/spec/hashie/mash_spec.rb
@@ -184,7 +184,8 @@ describe Hashie::Mash do
details: {
email: 'michael@asf.com',
address: 'Nowhere road'
- })
+ }
+ )
end
describe '#deep_update' do
@@ -284,7 +285,7 @@ describe Hashie::Mash do
end
it 'leaves only specified keys' do
- expect(subject.keys.sort).to eq %w(details middle_name)
+ expect(subject.keys.sort).to eq %w[details middle_name]
expect(subject.first_name?).to be_falsy
expect(subject).not_to respond_to(:first_name)
expect(subject.last_name?).to be_falsy
@@ -386,28 +387,28 @@ describe Hashie::Mash do
end
it 'responds to a set key with a suffix' do
- %w(= ? ! _).each do |suffix|
+ %w[= ? ! _].each do |suffix|
expect(subject).to be_respond_to(:"abc#{suffix}")
end
end
it 'is able to access the suffixed key as a method' do
- %w(= ? ! _).each do |suffix|
+ %w[= ? ! _].each do |suffix|
expect(subject.method(:"abc#{suffix}")).to_not be_nil
end
end
it 'responds to an unknown key with a suffix' do
- %w(= ? ! _).each do |suffix|
+ %w[= ? ! _].each do |suffix|
expect(subject).to be_respond_to(:"xyz#{suffix}")
end
end
it 'is able to access an unknown suffixed key as a method' do
# See https://github.com/intridea/hashie/pull/285 for more information
- pending_for(engine: 'ruby', versions: %w(2.2.0 2.2.1 2.2.2))
+ pending_for(engine: 'ruby', versions: %w[2.2.0 2.2.1 2.2.2])
- %w(= ? ! _).each do |suffix|
+ %w[= ? ! _].each do |suffix|
expect(subject.method(:"xyz#{suffix}")).to_not be_nil
end
end
@@ -560,7 +561,7 @@ describe Hashie::Mash do
end
it 'includes all keys' do
- expect(mash.to_hash.keys).to eql(%w(outer testing))
+ expect(mash.to_hash.keys).to eql(%w[outer testing])
end
it 'converts keys to symbols when symbolize_keys option is true' do
diff --git a/spec/hashie/parsers/yaml_erb_parser_spec.rb b/spec/hashie/parsers/yaml_erb_parser_spec.rb
index 72ea1f1..aeef25a 100644
--- a/spec/hashie/parsers/yaml_erb_parser_spec.rb
+++ b/spec/hashie/parsers/yaml_erb_parser_spec.rb
@@ -4,12 +4,12 @@ describe Hashie::Extensions::Parsers::YamlErbParser do
describe '.perform' do
context 'a file' do
let(:config) do
- <<-EOF
+ <<-CONFIG
---
foo: verbatim
bar: <%= "erb" %>
baz: "<%= __FILE__ %>"
- EOF
+ CONFIG
end
let(:path) { 'template.yml' }
@@ -36,7 +36,7 @@ baz: "<%= __FILE__ %>"
file
end
- subject { described_class.new(Pathname tempfile.path) }
+ subject { described_class.new(Pathname(tempfile.path)) }
it '"#perform" can be done in case of path is a Pathname object.' do
expect(subject.perform).to eq 'foo' => 'hello'
diff --git a/spec/hashie/rash_spec.rb b/spec/hashie/rash_spec.rb
index 8e3d4a2..11fed92 100644
--- a/spec/hashie/rash_spec.rb
+++ b/spec/hashie/rash_spec.rb
@@ -10,7 +10,7 @@ describe Hashie::Rash do
1 => 'awesome',
1..1000 => 'rangey',
/(bcd)/ => proc { |m| m[1] }
- # /.+/ => "EVERYTHING"
+ # /.+/ => "EVERYTHING"
)
end
@@ -18,7 +18,7 @@ describe Hashie::Rash do
expect(subject['other']).to eq 'whee'
expect(subject['well hello there']).to eq 'hello'
expect(subject['the world is round']).to eq 'world'
- expect(subject.all('hello world').sort).to eq %w(hello world)
+ expect(subject.all('hello world').sort).to eq %w[hello world]
end
it 'finds regexps' do
diff --git a/spec/hashie/trash_spec.rb b/spec/hashie/trash_spec.rb
index 80b093e..20b717c 100644
--- a/spec/hashie/trash_spec.rb
+++ b/spec/hashie/trash_spec.rb
@@ -153,7 +153,7 @@ describe Hashie::Trash do
end
it 'maintains translations hash mapping from the original to the translated name' do
- expect(SomeDataModel.translations).to eq(config: [:value_a, :value_b])
+ expect(SomeDataModel.translations).to eq(config: %i[value_a value_b])
end
end