watchdog 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG.txt +3 -0
- data/README.md +9 -0
- data/lib/watchdog.rb +4 -2
- data/lib/watchdog/version.rb +1 -1
- data/spec/watchdog_spec.rb +19 -0
- metadata +2 -2
data/CHANGELOG.txt
CHANGED
data/README.md
CHANGED
@@ -59,6 +59,15 @@ Watchdog also guards over extension modules that define class methods:
|
|
59
59
|
Date.extend DaysTillXmas
|
60
60
|
# Date.days_till_xmas -> 253 NOOOO...
|
61
61
|
|
62
|
+
Caveats
|
63
|
+
=======
|
64
|
+
|
65
|
+
Watchdog's protectiveness can be problematic with mocks in a test suite as they love to redefine
|
66
|
+
methods. Watchdog provides Watchdog.sleep, a Proc to conditionally turn off guarding extension
|
67
|
+
methods. By default, Watchdog sets this so that Rspec mocks are allowed to slip by:
|
68
|
+
|
69
|
+
Watchdog.sleep = lambda { defined? RSpec && !caller.grep(/rspec-mocks/).empty? }
|
70
|
+
|
62
71
|
Credits
|
63
72
|
=======
|
64
73
|
|
data/lib/watchdog.rb
CHANGED
@@ -3,12 +3,14 @@ require 'watchdog/german_shepard'
|
|
3
3
|
require 'watchdog/version'
|
4
4
|
|
5
5
|
module Watchdog
|
6
|
-
class <<self; attr_accessor :extensions, :subclasses; end
|
6
|
+
class <<self; attr_accessor :extensions, :subclasses, :sleep; end
|
7
7
|
self.extensions, self.subclasses = {}, []
|
8
|
+
# sleep when rspec mocks redefine guarded methods
|
9
|
+
self.sleep = lambda { defined? RSpec && !caller.grep(/rspec-mocks/).empty? }
|
8
10
|
|
9
11
|
# Guards extension methods from being overwritten
|
10
12
|
def self.guard(obj, meth)
|
11
|
-
return if subclasses.include?(obj)
|
13
|
+
return if subclasses.include?(obj) || (sleep && sleep.call)
|
12
14
|
return subclasses << obj if !extensions.key?(obj) && extensions.keys.
|
13
15
|
any? {|e| e.is_a?(Module) && e > obj }
|
14
16
|
if extensions[obj].instance_methods.map(&:to_sym).include?(meth)
|
data/lib/watchdog/version.rb
CHANGED
data/spec/watchdog_spec.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'watchdog'
|
2
|
+
Watchdog.sleep = nil
|
2
3
|
|
3
4
|
describe Watchdog do
|
4
5
|
def create_methods(obj, *meths)
|
@@ -103,5 +104,23 @@ describe Watchdog do
|
|
103
104
|
existing.send :include, another_extensions
|
104
105
|
Watchdog::GermanShepard.created.size.should == 1
|
105
106
|
end
|
107
|
+
|
108
|
+
context ".sleep" do
|
109
|
+
def redefined_method
|
110
|
+
existing = Class.new.send :include, extensions
|
111
|
+
lambda { existing.send(:define_method, :blah) { } }
|
112
|
+
end
|
113
|
+
after { Watchdog.sleep = nil }
|
114
|
+
|
115
|
+
it "ignores error if it evaluates to true" do
|
116
|
+
Watchdog.sleep = lambda { true }
|
117
|
+
redefined_method.should_not raise_error
|
118
|
+
end
|
119
|
+
|
120
|
+
it "ignores error if set to false" do
|
121
|
+
Watchdog.sleep = false
|
122
|
+
redefined_method.should raise_error Watchdog::ExtensionMethodExistsError
|
123
|
+
end
|
124
|
+
end
|
106
125
|
end
|
107
126
|
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: watchdog
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.
|
5
|
+
version: 0.3.0
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Gabriel Horner
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-04-
|
13
|
+
date: 2011-04-20 00:00:00 -04:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|