Skip to content

Commit

Permalink
Disable rspec monkeypatching
Browse files Browse the repository at this point in the history
  • Loading branch information
maxlinc committed Feb 5, 2015
1 parent 3bfdc63 commit d03759f
Show file tree
Hide file tree
Showing 26 changed files with 43 additions and 41 deletions.
2 changes: 1 addition & 1 deletion spec/hashie/clash_spec.rb
@@ -1,6 +1,6 @@
require 'spec_helper'

describe Hashie::Clash do
RSpec.describe Hashie::Clash do
subject { Hashie::Clash.new }

it 'is able to set an attribute via method_missing' do
Expand Down
12 changes: 6 additions & 6 deletions spec/hashie/dash_spec.rb
Expand Up @@ -51,7 +51,7 @@ class DeferredWithSelfTest < Hashie::Dash
property :updated_at, default: ->(test) { test.created_at }
end

describe DashTest do
RSpec.describe DashTest do
def property_required_error(property)
[ArgumentError, "The property '#{property}' is required for #{subject.class.name}."]
end
Expand Down Expand Up @@ -368,7 +368,7 @@ class DashMessageOptionWithoutRequiredTest < Hashie::Dash
end
end

describe Hashie::Dash, 'inheritance' do
RSpec.describe Hashie::Dash, 'inheritance' do
before do
@top = Class.new(Hashie::Dash)
@middle = Class.new(@top)
Expand Down Expand Up @@ -414,7 +414,7 @@ class DashMessageOptionWithoutRequiredTest < Hashie::Dash
end
end

describe SubclassedTest do
RSpec.describe SubclassedTest do
subject { SubclassedTest.new(first_name: 'Bob', last_name: 'McNob', email: 'bob@example.com') }

describe '#count' do
Expand All @@ -441,7 +441,7 @@ class ConditionallyRequiredTest < Hashie::Dash
property :password, required: -> { !username.nil? }, message: 'must be set, too.'
end

describe ConditionallyRequiredTest do
RSpec.describe ConditionallyRequiredTest do
it 'does not allow a conditionally required property to be set to nil if required' do
expect { ConditionallyRequiredTest.new(username: 'bob.smith', password: nil) }.to raise_error(ArgumentError, "The property 'password' must be set, too.")
end
Expand All @@ -460,7 +460,7 @@ class MixedPropertiesTest < Hashie::Dash
property 'string'
end

describe MixedPropertiesTest do
RSpec.describe MixedPropertiesTest do
subject { MixedPropertiesTest.new('string' => 'string', symbol: 'symbol') }

it { should respond_to('string') }
Expand Down Expand Up @@ -500,7 +500,7 @@ class MixedPropertiesTest < Hashie::Dash
end
end

context 'Dynamic Dash Class' do
RSpec.context 'Dynamic Dash Class' do
it 'define property' do
klass = Class.new(Hashie::Dash)
my_property = 'my_property'
Expand Down
2 changes: 1 addition & 1 deletion spec/hashie/extensions/autoload_spec.rb
@@ -1,7 +1,7 @@
require 'spec_helper'
require 'hashie'

describe Hashie::Extensions do
RSpec.describe Hashie::Extensions do
describe 'autloads constants' do
it { is_expected.to be_const_defined(:MethodAccess) }
it { is_expected.to be_const_defined(:Coercion) }
Expand Down
2 changes: 1 addition & 1 deletion spec/hashie/extensions/coercion_spec.rb
@@ -1,6 +1,6 @@
require 'spec_helper'

describe Hashie::Extensions::Coercion do
RSpec.describe Hashie::Extensions::Coercion do
class NotInitializable
private_class_method :new
end
Expand Down
2 changes: 1 addition & 1 deletion spec/hashie/extensions/dash/indifferent_access_spec.rb
@@ -1,6 +1,6 @@
require 'spec_helper'

describe Hashie::Extensions::Dash::IndifferentAccess do
RSpec.describe Hashie::Extensions::Dash::IndifferentAccess do
class TrashWithIndifferentAccess < Hashie::Trash
include Hashie::Extensions::Dash::IndifferentAccess
property :per_page, transform_with: ->(v) { v.to_i }
Expand Down
2 changes: 1 addition & 1 deletion spec/hashie/extensions/deep_fetch_spec.rb
Expand Up @@ -2,7 +2,7 @@

module Hashie
module Extensions
describe DeepFetch do
RSpec.describe DeepFetch do
subject { Class.new(Hash) { include Hashie::Extensions::DeepFetch } }
let(:hash) do
{
Expand Down
2 changes: 1 addition & 1 deletion spec/hashie/extensions/deep_find_spec.rb
@@ -1,6 +1,6 @@
require 'spec_helper'

describe Hashie::Extensions::DeepFind do
RSpec.describe Hashie::Extensions::DeepFind do
subject { Class.new(Hash) { include Hashie::Extensions::DeepFind } }
let(:hash) do
{
Expand Down
2 changes: 1 addition & 1 deletion spec/hashie/extensions/deep_locate_spec.rb
@@ -1,6 +1,6 @@
require 'spec_helper'

describe Hashie::Extensions::DeepLocate do
RSpec.describe Hashie::Extensions::DeepLocate do
let(:hash) do
{
from: 0,
Expand Down
2 changes: 1 addition & 1 deletion spec/hashie/extensions/deep_merge_spec.rb
@@ -1,6 +1,6 @@
require 'spec_helper'

describe Hashie::Extensions::DeepMerge do
RSpec.describe Hashie::Extensions::DeepMerge do
class DeepMergeHash < Hash
include Hashie::Extensions::DeepMerge
end
Expand Down
2 changes: 1 addition & 1 deletion spec/hashie/extensions/ignore_undeclared_spec.rb
@@ -1,6 +1,6 @@
require 'spec_helper'

describe Hashie::Extensions::IgnoreUndeclared do
RSpec.describe Hashie::Extensions::IgnoreUndeclared do
context 'included in Trash' do
class ForgivingTrash < Hashie::Trash
include Hashie::Extensions::IgnoreUndeclared
Expand Down
2 changes: 1 addition & 1 deletion spec/hashie/extensions/indifferent_access_spec.rb
@@ -1,6 +1,6 @@
require 'spec_helper'

describe Hashie::Extensions::IndifferentAccess do
RSpec.describe Hashie::Extensions::IndifferentAccess do
class IndifferentHashWithMergeInitializer < Hash
include Hashie::Extensions::MergeInitializer
include Hashie::Extensions::IndifferentAccess
Expand Down
Expand Up @@ -4,7 +4,7 @@
require 'spec_helper'
require 'active_support/hash_with_indifferent_access'

describe Hashie::Extensions::IndifferentAccess do
RSpec.describe Hashie::Extensions::IndifferentAccess do
class IndifferentHashWithMergeInitializer < Hash
include Hashie::Extensions::MergeInitializer
include Hashie::Extensions::IndifferentAccess
Expand Down
2 changes: 1 addition & 1 deletion spec/hashie/extensions/key_conversion_spec.rb
@@ -1,7 +1,7 @@
require 'spec_helper'
require 'support/module_context'

describe Hashie::Extensions::KeyConversion do
RSpec.describe Hashie::Extensions::KeyConversion do
include_context 'included hash module'

it { should respond_to(:stringify_keys) }
Expand Down
2 changes: 1 addition & 1 deletion spec/hashie/extensions/mash/safe_assignment_spec.rb
@@ -1,6 +1,6 @@
require 'spec_helper'

describe Hashie::Extensions::Mash::SafeAssignment do
RSpec.describe Hashie::Extensions::Mash::SafeAssignment do
class MashWithSafeAssignment < Hashie::Mash
include Hashie::Extensions::Mash::SafeAssignment
end
Expand Down
2 changes: 1 addition & 1 deletion spec/hashie/extensions/merge_initializer_spec.rb
@@ -1,6 +1,6 @@
require 'spec_helper'

describe Hashie::Extensions::MergeInitializer do
RSpec.describe Hashie::Extensions::MergeInitializer do
class MergeInitializerHash < Hash
include Hashie::Extensions::MergeInitializer
end
Expand Down
12 changes: 6 additions & 6 deletions spec/hashie/extensions/method_access_spec.rb
@@ -1,6 +1,6 @@
require 'spec_helper'

describe Hashie::Extensions::MethodReader do
RSpec.describe Hashie::Extensions::MethodReader do
class ReaderHash < Hash
include Hashie::Extensions::MethodReader

Expand Down Expand Up @@ -52,7 +52,7 @@ def initialize(hash = {})
end
end

describe Hashie::Extensions::MethodWriter do
RSpec.describe Hashie::Extensions::MethodWriter do
class WriterHash < Hash
include Hashie::Extensions::MethodWriter
end
Expand Down Expand Up @@ -80,7 +80,7 @@ class WriterHash < Hash
end
end

describe Hashie::Extensions::MethodQuery do
RSpec.describe Hashie::Extensions::MethodQuery do
class QueryHash < Hash
include Hashie::Extensions::MethodQuery

Expand Down Expand Up @@ -120,15 +120,15 @@ def initialize(hash = {})
end
end

describe Hashie::Extensions::MethodAccess do
RSpec.describe Hashie::Extensions::MethodAccess do
it 'includes all of the other method mixins' do
klass = Class.new(Hash)
klass.send :include, Hashie::Extensions::MethodAccess
expect((klass.ancestors & [Hashie::Extensions::MethodReader, Hashie::Extensions::MethodWriter, Hashie::Extensions::MethodQuery]).size).to eq 3
end
end

describe Hashie::Extensions::MethodOverridingWriter do
RSpec.describe Hashie::Extensions::MethodOverridingWriter do
class OverridingHash < Hash
include Hashie::Extensions::MethodOverridingWriter
end
Expand Down Expand Up @@ -175,7 +175,7 @@ class OverridingHash < Hash
end
end

describe Hashie::Extensions::MethodAccessWithOverride do
RSpec.describe Hashie::Extensions::MethodAccessWithOverride do
it 'includes all of the other method mixins' do
klass = Class.new(Hash)
klass.send :include, Hashie::Extensions::MethodAccessWithOverride
Expand Down
8 changes: 4 additions & 4 deletions spec/hashie/extensions/stringify_keys_spec.rb
Expand Up @@ -9,7 +9,7 @@ def invoke(method)
end
end

shared_examples 'stringify_keys!' do
RSpec.shared_examples 'stringify_keys!' do
it 'converts keys to strings' do
object[:abc] = 'abc'
object[123] = '123'
Expand Down Expand Up @@ -42,7 +42,7 @@ def invoke(method)
end
end

shared_examples 'stringify_keys' do
RSpec.shared_examples 'stringify_keys' do
it 'converts keys to strings' do
object[:abc] = 'def'
copy = invoke :stringify_keys
Expand All @@ -57,7 +57,7 @@ def invoke(method)
end
end

describe Hashie::Extensions::StringifyKeys do
RSpec.describe Hashie::Extensions::StringifyKeys do
include_context 'included hash module'
let(:object) { subject }

Expand All @@ -82,7 +82,7 @@ def invoke(method)
end
end

describe Hashie do
RSpec.describe Hashie do
let!(:dummy_class) do
klass = Class.new(::Hash)
klass.send :include, Hashie::Extensions::StringifyKeys
Expand Down
8 changes: 4 additions & 4 deletions spec/hashie/extensions/symbolize_keys_spec.rb
Expand Up @@ -9,7 +9,7 @@ def invoke(method)
end
end

shared_examples 'symbolize_keys!' do
RSpec.shared_examples 'symbolize_keys!' do
it 'converts keys to symbols' do
object['abc'] = 'abc'
object['def'] = 'def'
Expand Down Expand Up @@ -42,7 +42,7 @@ def invoke(method)
end
end

shared_examples 'symbolize_keys' do
RSpec.shared_examples 'symbolize_keys' do
it 'converts keys to symbols' do
object['abc'] = 'def'
copy = invoke :symbolize_keys
Expand All @@ -57,7 +57,7 @@ def invoke(method)
end
end

describe Hashie::Extensions::SymbolizeKeys do
RSpec.describe Hashie::Extensions::SymbolizeKeys do
include_context 'included hash module'
let(:object) { subject }

Expand Down Expand Up @@ -87,7 +87,7 @@ def invoke(method)
end
end

describe Hashie do
RSpec.describe Hashie do
let!(:dummy_class) do
klass = Class.new(::Hash)
klass.send :include, Hashie::Extensions::StringifyKeys
Expand Down
2 changes: 1 addition & 1 deletion spec/hashie/hash_spec.rb
@@ -1,6 +1,6 @@
require 'spec_helper'

describe Hash do
RSpec.describe Hash do
it 'is convertible to a Hashie::Mash' do
mash = Hashie::Hash[some: 'hash'].to_mash
expect(mash.is_a?(Hashie::Mash)).to be_truthy
Expand Down
2 changes: 1 addition & 1 deletion spec/hashie/mash_spec.rb
@@ -1,7 +1,7 @@
require 'spec_helper'
require 'delegate'

describe Hashie::Mash do
RSpec.describe Hashie::Mash do
subject { Hashie::Mash.new }

it 'inherits from Hash' do
Expand Down
2 changes: 1 addition & 1 deletion spec/hashie/parsers/yaml_erb_parser_spec.rb
@@ -1,6 +1,6 @@
require 'spec_helper'

describe Hashie::Extensions::Parsers::YamlErbParser do
RSpec.describe Hashie::Extensions::Parsers::YamlErbParser do
describe '.perform' do
let(:config) do
<<-EOF
Expand Down
2 changes: 1 addition & 1 deletion spec/hashie/rash_spec.rb
@@ -1,6 +1,6 @@
require 'spec_helper'

describe Hashie::Rash do
RSpec.describe Hashie::Rash do
subject do
Hashie::Rash.new(
/hello/ => 'hello',
Expand Down
2 changes: 1 addition & 1 deletion spec/hashie/trash_spec.rb
@@ -1,6 +1,6 @@
require 'spec_helper'

describe Hashie::Trash do
RSpec.describe Hashie::Trash do
class TrashTest < Hashie::Trash
property :first_name, from: :firstName
end
Expand Down
2 changes: 1 addition & 1 deletion spec/hashie/version_spec.rb
@@ -1,6 +1,6 @@
require 'spec_helper'

describe Hashie do
RSpec.describe do
it 'has a version' do
expect(Hashie::VERSION).not_to be_nil
end
Expand Down
2 changes: 2 additions & 0 deletions spec/spec_helper.rb
Expand Up @@ -9,6 +9,8 @@
require 'hashie'

RSpec.configure do |config|
config.disable_monkey_patching!

config.expect_with :rspec do |expect|
expect.syntax = :expect
end
Expand Down
2 changes: 1 addition & 1 deletion spec/support/module_context.rb
@@ -1,4 +1,4 @@
shared_context 'included hash module' do
RSpec.shared_context 'included hash module' do
let!(:dummy_class) do
klass = Class.new(::Hash)
klass.send :include, described_class
Expand Down

1 comment on commit d03759f

@maxlinc
Copy link
Contributor Author

@maxlinc maxlinc commented on d03759f Mar 8, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixes #276.

Don't be too scared by the number of files changed. There are two rather trivial changes, but that crossed many files:

  • RSpec no-monkey-patching mode: RSpec adds methods to Object by default. I wanted to get rspec out of the way to make it easier to review the method names on each class. When zero-monkey-patching mode was announced as part of the RSpec 3 plans, they wrote: "We plan for these config options to become the defaults in RSpec 4.0, so that RSpec 4.0 will have zero monkey patching out of the box." So might as well get a headstart anyways.
  • Renaming private methods: I went through and used the triple-underscore convention for private method names.

Notes:

  • Currently trying to define a property with a reserved name will cause an error. Perhaps an option to omit a warning makes sense.
  • I only applied the triple-underscore convention to Dash and extensions currently known to work with Dash. It would probably be good to make this convention Hashie-wide.
  • I ensured existing protected/private methods followed the convention, but I didn't review public methods to see if any of them are unnecessarily public.
  • The test is setup so it will not only catch private/protected methods that don't follow the convention, but will also find new public methods that haven't been previously marked as reserved.
  • It doesn't make a distinction between hashie and non-hashie methods private/protected methods. This only seems to be an issue for ActiveRecord private methods (really just '_deep_transform_keys_in_object'), which need to be granted an exception to the naming convention.

Please sign in to comment.