fakes 1.1.3 → 1.1.4
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/lib/fakes/class_swap.rb +29 -6
- data/lib/fakes/class_swaps.rb +1 -1
- data/lib/fakes/version.rb +1 -1
- data/spec/specs/class_swaps_spec.rb +1 -0
- metadata +2 -8
data/lib/fakes/class_swap.rb
CHANGED
@@ -4,14 +4,37 @@ module Fakes
|
|
4
4
|
attr_reader :klass
|
5
5
|
|
6
6
|
def initialize(fully_qualified_klass,replacement,options ={})
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
7
|
+
modules = get_modules(fully_qualified_klass)
|
8
|
+
@klass = modules.keys.last.to_sym
|
9
|
+
|
10
|
+
class_root = modules.keys[modules.keys.count - 2]
|
11
|
+
class_root = modules[class_root.to_sym]
|
11
12
|
|
12
13
|
@replacement = replacement
|
13
|
-
|
14
|
-
@
|
14
|
+
|
15
|
+
@remove_strategy = options.fetch(:remove_strategy, Proc.new do |klass|
|
16
|
+
class_root.send(:remove_const, klass)
|
17
|
+
end)
|
18
|
+
|
19
|
+
@set_strategy = options.fetch(:set_strategy, Proc.new do |klass, new_value|
|
20
|
+
class_root.const_set(klass.to_sym, new_value)
|
21
|
+
end)
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
def get_modules(fully_qualified_klass)
|
26
|
+
klass_parts = fully_qualified_klass.to_s.split("::")
|
27
|
+
root = Object
|
28
|
+
modules = {}
|
29
|
+
modules[:Object] = root
|
30
|
+
|
31
|
+
klass_parts.each do |part|
|
32
|
+
class_or_module = root.const_get(part.to_sym)
|
33
|
+
modules[part.to_sym] = class_or_module
|
34
|
+
root = class_or_module
|
35
|
+
end
|
36
|
+
|
37
|
+
modules
|
15
38
|
end
|
16
39
|
|
17
40
|
def initiate
|
data/lib/fakes/class_swaps.rb
CHANGED
data/lib/fakes/version.rb
CHANGED
@@ -102,6 +102,7 @@ module Fakes
|
|
102
102
|
ClassSwaps.instance.reset
|
103
103
|
Dir.should_not == replacement
|
104
104
|
end
|
105
|
+
|
105
106
|
it 'should be able to swap class values in another module' do
|
106
107
|
ClassSwaps.instance.add_fake_for(SomeModule::ClassInAModule,replacement)
|
107
108
|
SomeModule::ClassInAModule.should == replacement
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fakes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-06-
|
12
|
+
date: 2013-06-25 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
@@ -132,18 +132,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
132
132
|
- - ! '>='
|
133
133
|
- !ruby/object:Gem::Version
|
134
134
|
version: '0'
|
135
|
-
segments:
|
136
|
-
- 0
|
137
|
-
hash: -4322059409981481306
|
138
135
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
139
136
|
none: false
|
140
137
|
requirements:
|
141
138
|
- - ! '>='
|
142
139
|
- !ruby/object:Gem::Version
|
143
140
|
version: '0'
|
144
|
-
segments:
|
145
|
-
- 0
|
146
|
-
hash: -4322059409981481306
|
147
141
|
requirements: []
|
148
142
|
rubyforge_project: fakes
|
149
143
|
rubygems_version: 1.8.25
|