method_disabling 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.rspec +2 -0
- data/.travis.yml +10 -0
- data/Gemfile +9 -0
- data/Gemfile.lock +33 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +58 -0
- data/Rakefile +42 -0
- data/VERSION +1 -0
- data/lib/method_disabling.rb +206 -0
- data/spec/method_disabling_spec.rb +178 -0
- data/spec/spec_helper.rb +20 -0
- metadata +118 -0
data/.document
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
diff-lcs (1.1.3)
|
5
|
+
git (1.2.5)
|
6
|
+
jeweler (1.8.3)
|
7
|
+
bundler (~> 1.0)
|
8
|
+
git (>= 1.2.5)
|
9
|
+
rake
|
10
|
+
rdoc
|
11
|
+
json (1.6.5)
|
12
|
+
rake (0.9.2.2)
|
13
|
+
rdoc (3.12)
|
14
|
+
json (~> 1.4)
|
15
|
+
rspec (2.8.0)
|
16
|
+
rspec-core (~> 2.8.0)
|
17
|
+
rspec-expectations (~> 2.8.0)
|
18
|
+
rspec-mocks (~> 2.8.0)
|
19
|
+
rspec-core (2.8.0)
|
20
|
+
rspec-expectations (2.8.0)
|
21
|
+
diff-lcs (~> 1.1.2)
|
22
|
+
rspec-mocks (2.8.0)
|
23
|
+
yard (0.7.5)
|
24
|
+
|
25
|
+
PLATFORMS
|
26
|
+
ruby
|
27
|
+
|
28
|
+
DEPENDENCIES
|
29
|
+
bundler (~> 1.0.0)
|
30
|
+
jeweler (~> 1.8.3)
|
31
|
+
rdoc (~> 3.12)
|
32
|
+
rspec (~> 2.8.0)
|
33
|
+
yard (~> 0.7)
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2012 David Cuddeback
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
= method_disabling
|
2
|
+
|
3
|
+
Allows disabling methods at runtime. It can be used to raise an error whenever a certain method is
|
4
|
+
called from within your test suite to ensure the developers on your team don't accidentally write
|
5
|
+
fragile tests. For example, you might want to disable access to a shared resource.
|
6
|
+
|
7
|
+
== Getting Started
|
8
|
+
|
9
|
+
Add +method_disabling+ to your Gemfile (probably under the +test+ group):
|
10
|
+
|
11
|
+
group :test do
|
12
|
+
gem "method_disabling"
|
13
|
+
end
|
14
|
+
|
15
|
+
Use <tt>Module#disable_method</tt> and <tt>Module#disable_class_method</tt> to disable methods that
|
16
|
+
you don't want called during your test suite. For example, to disable access to <tt>Net::HTTP</tt>:
|
17
|
+
|
18
|
+
# spec/spec_helper.rb
|
19
|
+
config.before do
|
20
|
+
Net::HTTP.disable_method :initialize
|
21
|
+
end
|
22
|
+
|
23
|
+
When developers inadvertantly write unit tests that access the disabled method, they will see an error message:
|
24
|
+
|
25
|
+
NoMethodError: Net::HTTP#initialize is disabled
|
26
|
+
|
27
|
+
You can set a custom error message by adding a second parameter to +disable_method+:
|
28
|
+
|
29
|
+
# spec/spec_helper.rb
|
30
|
+
config.before do
|
31
|
+
Net::HTTP.disable_method :initialize, "You were about to access an external resource. Please mock or stub instead."
|
32
|
+
end
|
33
|
+
|
34
|
+
A disabled method can be restored to its original behavior with +restore_method+:
|
35
|
+
|
36
|
+
Net::HTTP.restore_method :initialize
|
37
|
+
|
38
|
+
The same can be done for class methods with +disable_class_method+ and +restore_class_method+.
|
39
|
+
|
40
|
+
== Status {<img src="https://secure.travis-ci.org/dcuddeback/method_disabling.png" />}[http://travis-ci.org/dcuddeback/method_disabling]
|
41
|
+
|
42
|
+
+method_disabling+ is tested on Ruby 1.8.7, 1.9.2, 1.9.3, REE, Rubnius (1.8 and 1.9 mode), and JRuby (1.8 and 1.9 mode).
|
43
|
+
|
44
|
+
== Contributing to method_disabling
|
45
|
+
|
46
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
47
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
|
48
|
+
* Fork the project.
|
49
|
+
* Start a feature/bugfix branch.
|
50
|
+
* Commit and push until you are happy with your contribution.
|
51
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
52
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
53
|
+
|
54
|
+
== Copyright
|
55
|
+
|
56
|
+
Copyright (c) 2012 David Cuddeback. See LICENSE.txt for
|
57
|
+
further details.
|
58
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
+
gem.name = "method_disabling"
|
18
|
+
gem.homepage = "http://github.com/dcuddeback/method_disabling"
|
19
|
+
gem.license = "MIT"
|
20
|
+
gem.summary = %Q{Allows disabling methods at run-time}
|
21
|
+
gem.description = %Q{Allows you to disable methods at run-time, such as when you want to ensure that certain methods are never called during a test suite.}
|
22
|
+
gem.email = "david.cuddeback@gmail.com"
|
23
|
+
gem.authors = ["David Cuddeback"]
|
24
|
+
# dependencies defined in Gemfile
|
25
|
+
end
|
26
|
+
Jeweler::RubygemsDotOrgTasks.new
|
27
|
+
|
28
|
+
require 'rspec/core'
|
29
|
+
require 'rspec/core/rake_task'
|
30
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
31
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
32
|
+
end
|
33
|
+
|
34
|
+
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
35
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
36
|
+
spec.rcov = true
|
37
|
+
end
|
38
|
+
|
39
|
+
task :default => :spec
|
40
|
+
|
41
|
+
require 'yard'
|
42
|
+
YARD::Rake::YardocTask.new
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
@@ -0,0 +1,206 @@
|
|
1
|
+
# MethodDisabling allows a programmer to programatically disable existing methods, causing them to
|
2
|
+
# raise a NoMethodError, and restore the methods to their original behavior.
|
3
|
+
#
|
4
|
+
# The most obvious use case for disabling messages is when you want to ensure that your unit tests
|
5
|
+
# don't do anything unexpected, such as connecting to external resources.
|
6
|
+
module MethodDisabling
|
7
|
+
|
8
|
+
# Provides class-level macros for managing disabled methods.
|
9
|
+
#
|
10
|
+
# @example Disabling an instance method
|
11
|
+
# class Foo
|
12
|
+
# def bar
|
13
|
+
# 42
|
14
|
+
# end
|
15
|
+
# end
|
16
|
+
#
|
17
|
+
# Foo.new.bar # => 42
|
18
|
+
# Foo.disable_method :bar
|
19
|
+
# Foo.new.bar # => NoMethodError: Foo#bar is disabled
|
20
|
+
# Foo.restore_method :bar
|
21
|
+
# Foo.new.bar # => 42
|
22
|
+
#
|
23
|
+
# @example Disabling a class method
|
24
|
+
# class Foo
|
25
|
+
# def self.bar
|
26
|
+
# 42
|
27
|
+
# end
|
28
|
+
# end
|
29
|
+
#
|
30
|
+
# Foo.bar # => 42
|
31
|
+
# Foo.disable_class_method :bar
|
32
|
+
# Foo.bar # => NoMethodError: #<Class:Foo>#bar is disabled
|
33
|
+
# Foo.restore_class_method :bar
|
34
|
+
# Foo.bar # => 42
|
35
|
+
#
|
36
|
+
module ClassMethods
|
37
|
+
|
38
|
+
# Disables an instance method.
|
39
|
+
#
|
40
|
+
# @param [Symbol,String] method_name The name of the method to disable.
|
41
|
+
# @param [String] message An error message. Defaults to "Class#method is disabled".
|
42
|
+
def disable_method(method_name, message = nil)
|
43
|
+
disabled_methods[method_name] ||= DisabledMethod.new(self, method_name, message)
|
44
|
+
disabled_methods[method_name].disable!
|
45
|
+
end
|
46
|
+
|
47
|
+
# Restores a previously disabled instance method.
|
48
|
+
#
|
49
|
+
# @param [Symbol,String] method_name The name of the method to restore.
|
50
|
+
def restore_method(method_name)
|
51
|
+
disabled_methods[method_name].restore!
|
52
|
+
end
|
53
|
+
|
54
|
+
# A collection of the methods that have been disabled.
|
55
|
+
#
|
56
|
+
# @return [Hash]
|
57
|
+
def disabled_methods
|
58
|
+
@disabled_methods ||= {}
|
59
|
+
end
|
60
|
+
private :disabled_methods
|
61
|
+
|
62
|
+
# Disables a class method.
|
63
|
+
#
|
64
|
+
# @param [Symbol,String] method_name The name of the method to disable.
|
65
|
+
# @param [String] message An error message. Defaults to "Class#method is disabled".
|
66
|
+
def disable_class_method(method_name, message = nil)
|
67
|
+
(class << self; self; end).disable_method(method_name, message)
|
68
|
+
end
|
69
|
+
|
70
|
+
# Restores a previously disabled class method.
|
71
|
+
#
|
72
|
+
# @param [Symbol,String] method_name The name of the method to restore.
|
73
|
+
def restore_class_method(method_name)
|
74
|
+
(class << self; self; end).restore_method(method_name)
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
78
|
+
|
79
|
+
|
80
|
+
# A DisabledMethod is an existing class or instance method that has been disabled. The method can
|
81
|
+
# be disabled and restored as necessary. When the method is disabled, calling the method will
|
82
|
+
# raise a NoMethodError, optionally with a custom message. When the method is restored, the method
|
83
|
+
# will behave as normal.
|
84
|
+
#
|
85
|
+
# Although this class *could* be used directly, the intention is that you would use the methods in
|
86
|
+
# {MethodDisabling::ClassMethods} to disable and restore methods.
|
87
|
+
class DisabledMethod
|
88
|
+
|
89
|
+
attr_reader :klass, :method_name, :message
|
90
|
+
|
91
|
+
# Disables a instance method. To disable a class method, pass the class's singleton class as the
|
92
|
+
# first argument.
|
93
|
+
#
|
94
|
+
# @param [Module] klass The module or class whose method should be disabled.
|
95
|
+
# @param [Symbol,String] method_name The name of the method to disable.
|
96
|
+
# @param [String] message The exception message to be shown when the method is
|
97
|
+
# called.
|
98
|
+
def initialize(klass, method_name, message = nil)
|
99
|
+
@klass = klass
|
100
|
+
@method_name = method_name
|
101
|
+
@message = message || "#{klass.inspect}##{method_name} is disabled"
|
102
|
+
|
103
|
+
alias_method!
|
104
|
+
disable!
|
105
|
+
end
|
106
|
+
|
107
|
+
# Disables the method.
|
108
|
+
def disable!
|
109
|
+
@disabled = true
|
110
|
+
end
|
111
|
+
|
112
|
+
# Restores the method.
|
113
|
+
def restore!
|
114
|
+
@disabled = false
|
115
|
+
end
|
116
|
+
|
117
|
+
# Returns a Proc that acts as a replacement for the disabled method.
|
118
|
+
def to_proc
|
119
|
+
disabled_method = self
|
120
|
+
|
121
|
+
# This proc will be evaluated with "self" set to the original object.
|
122
|
+
Proc.new do |*args, &block|
|
123
|
+
disabled_method.execute(self, *args, &block)
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
# The replacement for the original method. It will raise a NoMethodError if the method is
|
128
|
+
# disabled. Otherwise, it will execute the original method.
|
129
|
+
#
|
130
|
+
# @param [Object] object The "self" object of the method being called.
|
131
|
+
# @param [Array] args The arguments that were passed to the method.
|
132
|
+
# @param [Proc] block The block that was passed to the method.
|
133
|
+
#
|
134
|
+
# @return Whatever the original method returns.
|
135
|
+
def execute(object, *args, &block)
|
136
|
+
if disabled?
|
137
|
+
raise NoMethodError, message
|
138
|
+
else
|
139
|
+
object.send(aliased_name, *args, &block)
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
private
|
144
|
+
|
145
|
+
# Indicates whether or not the method is disabled.
|
146
|
+
#
|
147
|
+
# @return [Boolean]
|
148
|
+
def disabled?
|
149
|
+
@disabled
|
150
|
+
end
|
151
|
+
|
152
|
+
# Replaces the original implementation of the method with an implementation that allows
|
153
|
+
# disabling.
|
154
|
+
def alias_method!
|
155
|
+
klass.send(:define_method, replacement_name, &self)
|
156
|
+
klass.send(:alias_method, aliased_name, method_name)
|
157
|
+
klass.send(:alias_method, method_name, replacement_name)
|
158
|
+
end
|
159
|
+
|
160
|
+
# The name of the replacement method.
|
161
|
+
#
|
162
|
+
# @return [String]
|
163
|
+
def replacement_name
|
164
|
+
"#{base_method_name}_with_disable#{method_suffix}"
|
165
|
+
end
|
166
|
+
|
167
|
+
# The aliased name of the original method.
|
168
|
+
#
|
169
|
+
# @return [String]
|
170
|
+
def aliased_name
|
171
|
+
"#{base_method_name}_without_disable#{method_suffix}"
|
172
|
+
end
|
173
|
+
|
174
|
+
# The original method name with any suffix ("!" or "?") removed.
|
175
|
+
#
|
176
|
+
# @return [String]
|
177
|
+
def base_method_name
|
178
|
+
method_name_parts[:base_name]
|
179
|
+
end
|
180
|
+
|
181
|
+
# The original method name's suffix ("!" or "?"), if any.
|
182
|
+
#
|
183
|
+
# @return [String]
|
184
|
+
def method_suffix
|
185
|
+
method_name_parts[:suffix]
|
186
|
+
end
|
187
|
+
|
188
|
+
# The original method name broken into parts. The returned value can is a hash with the keys
|
189
|
+
# `:base_name` and `:suffix`, which return the original method name's base name and suffix,
|
190
|
+
# respectively.
|
191
|
+
#
|
192
|
+
# @return [Hash]
|
193
|
+
def method_name_parts
|
194
|
+
@parts ||= begin
|
195
|
+
base_name, suffix = method_name.to_s.sub(/([?!=]?)$/, ""), $1
|
196
|
+
{ :base_name => base_name, :suffix => suffix }
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
200
|
+
end
|
201
|
+
|
202
|
+
end
|
203
|
+
|
204
|
+
# Yeah, it's including ClassMethods, which isn't usual, but that's because it's being included on
|
205
|
+
# the Module class, which effectively makes them class methods in other classes and modules.
|
206
|
+
Module.send(:include, MethodDisabling::ClassMethods)
|
@@ -0,0 +1,178 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
|
4
|
+
shared_examples "enabled method" do
|
5
|
+
|
6
|
+
it "should call the original implementation" do
|
7
|
+
object.should_receive(:original_implementation)
|
8
|
+
object.the_method rescue nil
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should pass through the method parameters" do
|
12
|
+
args = [:foo, 42]
|
13
|
+
object.should_receive(:original_implementation).with(*args)
|
14
|
+
object.the_method(*args) rescue nil
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should pass through any block parameters" do
|
18
|
+
yielded = nil
|
19
|
+
the_block = Proc.new { |*args| yielded = args }
|
20
|
+
|
21
|
+
object.should_receive(:original_implementation).and_yield(42)
|
22
|
+
object.the_method(&the_block)
|
23
|
+
|
24
|
+
yielded.should == [42]
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should return the original implementation's return value" do
|
28
|
+
return_value = rand
|
29
|
+
object.should_receive(:original_implementation).and_return(return_value)
|
30
|
+
object.the_method.should == return_value
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should not raise an error" do
|
34
|
+
expect {
|
35
|
+
object.the_method
|
36
|
+
}.to_not raise_error
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
|
42
|
+
shared_examples "disabled method" do
|
43
|
+
|
44
|
+
it "should not call the original implementation" do
|
45
|
+
object.should_not_receive(:original_implementation)
|
46
|
+
object.the_method rescue nil
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should raise NoMethodError with default message" do
|
50
|
+
expect {
|
51
|
+
object.the_method
|
52
|
+
}.to raise_error(NoMethodError, "#{klass_inspect}#the_method is disabled")
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
|
58
|
+
shared_examples "method disabling" do
|
59
|
+
|
60
|
+
context "untouched" do
|
61
|
+
it_should_behave_like "enabled method"
|
62
|
+
end
|
63
|
+
|
64
|
+
context "disabled" do
|
65
|
+
context "with default message" do
|
66
|
+
before do
|
67
|
+
klass.send(disabler, :the_method)
|
68
|
+
end
|
69
|
+
|
70
|
+
it_should_behave_like "disabled method"
|
71
|
+
end
|
72
|
+
|
73
|
+
context "with custom message" do
|
74
|
+
let(:message) { "Custom Message" }
|
75
|
+
|
76
|
+
before do
|
77
|
+
klass.send(disabler, :the_method, message)
|
78
|
+
end
|
79
|
+
|
80
|
+
it "should raise NoMethodError with custom message" do
|
81
|
+
expect {
|
82
|
+
object.the_method
|
83
|
+
}.to raise_error(NoMethodError, message)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
context "restored" do
|
89
|
+
before do
|
90
|
+
klass.send(disabler, :the_method)
|
91
|
+
klass.send(restorer, :the_method)
|
92
|
+
end
|
93
|
+
|
94
|
+
it_should_behave_like "enabled method"
|
95
|
+
end
|
96
|
+
|
97
|
+
context "re-disabled" do
|
98
|
+
context "with default message" do
|
99
|
+
before do
|
100
|
+
klass.send(disabler, :the_method)
|
101
|
+
klass.send(restorer, :the_method)
|
102
|
+
klass.send(disabler, :the_method)
|
103
|
+
end
|
104
|
+
|
105
|
+
it_should_behave_like "disabled method"
|
106
|
+
end
|
107
|
+
|
108
|
+
context "with custom message" do
|
109
|
+
let(:message) { "Custom Message" }
|
110
|
+
|
111
|
+
before do
|
112
|
+
klass.send(disabler, :the_method, message)
|
113
|
+
klass.send(restorer, :the_method)
|
114
|
+
klass.send(disabler, :the_method)
|
115
|
+
end
|
116
|
+
|
117
|
+
it "should raise NoMethodError with custom message" do
|
118
|
+
expect {
|
119
|
+
object.the_method
|
120
|
+
}.to raise_error(NoMethodError, message)
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
end
|
126
|
+
|
127
|
+
|
128
|
+
describe "MethodDisabling" do
|
129
|
+
|
130
|
+
describe "instance methods" do
|
131
|
+
let(:klass) do
|
132
|
+
suppress_warnings do
|
133
|
+
::TheClass = Class.new do
|
134
|
+
def the_method(*args, &block)
|
135
|
+
original_implementation(*args, &block)
|
136
|
+
end
|
137
|
+
|
138
|
+
private
|
139
|
+
|
140
|
+
def original_implementation(*args, &block)
|
141
|
+
42
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
let(:object) { klass.new }
|
148
|
+
let(:disabler) { :disable_method }
|
149
|
+
let(:restorer) { :restore_method }
|
150
|
+
let(:klass_inspect) { klass.inspect }
|
151
|
+
|
152
|
+
include_examples "method disabling"
|
153
|
+
end
|
154
|
+
|
155
|
+
describe "class methods" do
|
156
|
+
let(:klass) do
|
157
|
+
suppress_warnings do
|
158
|
+
::TheClass = Class.new do
|
159
|
+
def self.the_method(*args, &block)
|
160
|
+
original_implementation(*args, &block)
|
161
|
+
end
|
162
|
+
|
163
|
+
def self.original_implementation(*args, &block)
|
164
|
+
end
|
165
|
+
private_class_method :original_implementation
|
166
|
+
end
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
let(:object) { klass }
|
171
|
+
let(:disabler) { :disable_class_method }
|
172
|
+
let(:restorer) { :restore_class_method }
|
173
|
+
let(:klass_inspect) { class << klass; inspect; end }
|
174
|
+
|
175
|
+
include_examples "method disabling"
|
176
|
+
end
|
177
|
+
|
178
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
require 'rspec'
|
4
|
+
require 'method_disabling'
|
5
|
+
|
6
|
+
# Requires supporting files with custom matchers and macros, etc,
|
7
|
+
# in ./support/ and its subdirectories.
|
8
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
9
|
+
|
10
|
+
RSpec.configure do |config|
|
11
|
+
|
12
|
+
end
|
13
|
+
|
14
|
+
def suppress_warnings
|
15
|
+
original_verbosity = $VERBOSE
|
16
|
+
$VERBOSE = nil
|
17
|
+
yield
|
18
|
+
ensure
|
19
|
+
$VERBOSE = original_verbosity
|
20
|
+
end
|
metadata
ADDED
@@ -0,0 +1,118 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: method_disabling
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- David Cuddeback
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-03-02 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: &12456960 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 2.8.0
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *12456960
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: yard
|
27
|
+
requirement: &12455480 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ~>
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0.7'
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *12455480
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: rdoc
|
38
|
+
requirement: &12469180 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ~>
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '3.12'
|
44
|
+
type: :development
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *12469180
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: bundler
|
49
|
+
requirement: &12465440 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 1.0.0
|
55
|
+
type: :development
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *12465440
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: jeweler
|
60
|
+
requirement: &12464460 !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ~>
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: 1.8.3
|
66
|
+
type: :development
|
67
|
+
prerelease: false
|
68
|
+
version_requirements: *12464460
|
69
|
+
description: Allows you to disable methods at run-time, such as when you want to ensure
|
70
|
+
that certain methods are never called during a test suite.
|
71
|
+
email: david.cuddeback@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files:
|
75
|
+
- LICENSE.txt
|
76
|
+
- README.rdoc
|
77
|
+
files:
|
78
|
+
- .document
|
79
|
+
- .rspec
|
80
|
+
- .travis.yml
|
81
|
+
- Gemfile
|
82
|
+
- Gemfile.lock
|
83
|
+
- LICENSE.txt
|
84
|
+
- README.rdoc
|
85
|
+
- Rakefile
|
86
|
+
- VERSION
|
87
|
+
- lib/method_disabling.rb
|
88
|
+
- spec/method_disabling_spec.rb
|
89
|
+
- spec/spec_helper.rb
|
90
|
+
homepage: http://github.com/dcuddeback/method_disabling
|
91
|
+
licenses:
|
92
|
+
- MIT
|
93
|
+
post_install_message:
|
94
|
+
rdoc_options: []
|
95
|
+
require_paths:
|
96
|
+
- lib
|
97
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
98
|
+
none: false
|
99
|
+
requirements:
|
100
|
+
- - ! '>='
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
segments:
|
104
|
+
- 0
|
105
|
+
hash: -2416705567977990342
|
106
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
107
|
+
none: false
|
108
|
+
requirements:
|
109
|
+
- - ! '>='
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '0'
|
112
|
+
requirements: []
|
113
|
+
rubyforge_project:
|
114
|
+
rubygems_version: 1.8.17
|
115
|
+
signing_key:
|
116
|
+
specification_version: 3
|
117
|
+
summary: Allows disabling methods at run-time
|
118
|
+
test_files: []
|