rspec-fire 1.1.1 → 1.1.2
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/HISTORY +3 -0
- data/lib/rspec/fire.rb +44 -18
- data/rspec-fire.gemspec +1 -1
- data/spec/fire_double_spec.rb +6 -0
- metadata +6 -6
data/HISTORY
CHANGED
data/lib/rspec/fire.rb
CHANGED
@@ -76,14 +76,53 @@ module RSpec
|
|
76
76
|
end
|
77
77
|
|
78
78
|
module RecursiveConstMethods
|
79
|
+
# We only want to consider constants that are defined directly on a
|
80
|
+
# particular module, and not include top-level/inherited constants.
|
81
|
+
# Unfortunately, the constant API changed between 1.8 and 1.9, so
|
82
|
+
# we need to conditionally define methods to ignore the top-level/inherited
|
83
|
+
# constants.
|
84
|
+
#
|
85
|
+
# Given `class A; end`:
|
86
|
+
#
|
87
|
+
# On 1.8:
|
88
|
+
# - A.const_get("Hash") # => ::Hash
|
89
|
+
# - A.const_defined?("Hash") # => false
|
90
|
+
# - Neither method accepts the extra `inherit` argument
|
91
|
+
# On 1.9:
|
92
|
+
# - A.const_get("Hash") # => ::Hash
|
93
|
+
# - A.const_defined?("Hash") # => true
|
94
|
+
# - A.const_get("Hash", false) # => raises NameError
|
95
|
+
# - A.const_defined?("Hash", false) # => false
|
96
|
+
if Module.method(:const_defined?).arity == 1
|
97
|
+
def const_defined_on?(mod, const_name)
|
98
|
+
mod.const_defined?(const_name)
|
99
|
+
end
|
100
|
+
|
101
|
+
def get_const_defined_on(mod, const_name)
|
102
|
+
if const_defined_on?(mod, const_name)
|
103
|
+
return mod.const_get(const_name)
|
104
|
+
end
|
105
|
+
|
106
|
+
raise NameError, "uninitialized constant #{mod.name}::#{const_name}"
|
107
|
+
end
|
108
|
+
else
|
109
|
+
def const_defined_on?(mod, const_name)
|
110
|
+
mod.const_defined?(const_name, false)
|
111
|
+
end
|
112
|
+
|
113
|
+
def get_const_defined_on(mod, const_name)
|
114
|
+
mod.const_get(const_name, false)
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
79
118
|
def recursive_const_get name
|
80
|
-
name.split('::').inject(Object) {|klass,name| klass
|
119
|
+
name.split('::').inject(Object) {|klass,name| get_const_defined_on(klass, name) }
|
81
120
|
end
|
82
121
|
|
83
122
|
def recursive_const_defined? name
|
84
123
|
!!name.split('::').inject(Object) {|klass,name|
|
85
|
-
if klass &&
|
86
|
-
klass
|
124
|
+
if klass && const_defined_on?(klass, name)
|
125
|
+
get_const_defined_on(klass, name)
|
87
126
|
end
|
88
127
|
}
|
89
128
|
end
|
@@ -243,21 +282,8 @@ module RSpec
|
|
243
282
|
|
244
283
|
verify_constant_name if RSpec::Fire.configuration.verify_constant_names?
|
245
284
|
|
246
|
-
|
247
|
-
|
248
|
-
# details.
|
249
|
-
if defined?(::RSpec::Mocks::TestDouble)
|
250
|
-
::RSpec::Mocks::TestDouble.extend_onto self,
|
251
|
-
doubled_class, stubs.merge(:__declared_as => "FireClassDouble")
|
252
|
-
else
|
253
|
-
stubs.each do |message, response|
|
254
|
-
stub(message).and_return(response)
|
255
|
-
end
|
256
|
-
|
257
|
-
def self.method_missing(name, *args)
|
258
|
-
__mock_proxy.raise_unexpected_message_error(name, *args)
|
259
|
-
end
|
260
|
-
end
|
285
|
+
::RSpec::Mocks::TestDouble.extend_onto self,
|
286
|
+
doubled_class, stubs.merge(:__declared_as => "FireClassDouble")
|
261
287
|
|
262
288
|
def self.as_replaced_constant(options = {})
|
263
289
|
RSpec::Mocks::ConstantStubber.stub(@__doubled_class_name, self, options)
|
data/rspec-fire.gemspec
CHANGED
data/spec/fire_double_spec.rb
CHANGED
@@ -193,6 +193,12 @@ describe '#fire_double' do
|
|
193
193
|
double = fire_double("TestObject", :defined_method => 17)
|
194
194
|
double.defined_method.should eq(17)
|
195
195
|
end
|
196
|
+
|
197
|
+
it 'does not prevent stubbing methods on an unloaded nested constant with a name that matches a top-level constant' do
|
198
|
+
double = fire_double("TestObject::Hash")
|
199
|
+
double.stub(:foo).and_return("bar")
|
200
|
+
double.foo.should eq("bar")
|
201
|
+
end
|
196
202
|
end
|
197
203
|
|
198
204
|
describe '#fire_class_double' do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspec-fire
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-08-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
|
-
requirement: &
|
16
|
+
requirement: &2160766260 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '2.11'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *2160766260
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rake
|
27
|
-
requirement: &
|
27
|
+
requirement: &2160765580 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,7 +32,7 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *2160765580
|
36
36
|
description:
|
37
37
|
email:
|
38
38
|
- hello@xaviershay.com
|