test-redef 1.0 → 1.0.1

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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/test/redef.rb +3 -3
  3. data/test/redef.rb +16 -1
  4. metadata +8 -8
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f6047a2115ef0cf71503c4221619fef15645afe1
4
- data.tar.gz: 001a8a1f7e1ea8c96ca0baacbe5285c052f321c5
3
+ metadata.gz: b1d0499975b9a3b2197b73ed016e48ebb72b9744
4
+ data.tar.gz: d19562cb49b2e12237c1de3e712c49aeb237a54b
5
5
  SHA512:
6
- metadata.gz: 37837c324a1102703ee596c15a69b4c09f5fa9b9687c1b3aa4725f08553fa755e741372e6956aada91f23495661fd4b2198769640a8175c940744c053582e5f3
7
- data.tar.gz: c37f32c2b9c4b5cea2717f421a96ab2fe0fd62219932c83f0f7d0eec10c48b505089918837f31a38fcd856b9181a7d75688fde5f5e3f982b56fbc0ef3fd4f8ea
6
+ metadata.gz: e32c1c58a46fc75081e524c1967884d97e8f24d19440ad4cfc2fd960f20911e327511f97413ed48286f84229c47d73c06e86f46ef4f5b01c2fb50d089be034b6
7
+ data.tar.gz: f3713d6511c5248cf769d6fc308d796decc358319b0395e6a9c63c4d75c0b0dc764b62f18b59ce2dae9aeeecbbf67f737dd595895ee3369be97b0e09be2bbe11
data/lib/test/redef.rb CHANGED
@@ -33,10 +33,10 @@ class Test::Redef
33
33
  end
34
34
 
35
35
  def self.publicize_method(*methods)
36
- orig_access_level = {}
37
36
  method_syms = []
38
37
  methods.each do |class_method_name|
39
38
  klass, method_name = parse_class_and_method(class_method_name)
39
+ next if klass.public_instance_methods.include?(method_name)
40
40
  method_syms << [klass, method_name]
41
41
  klass.send(:public, method_name)
42
42
  end
@@ -81,7 +81,7 @@ class Test::Redef
81
81
  def [](method_name)
82
82
  c = Class.new
83
83
  c.instance_exec(self, method_name) do |rs, rs_method_name|
84
- [:called, :args, :object, :reset].each do |method|
84
+ [:called, :args, :object, :reset, :called?].each do |method|
85
85
  define_method(method) { rs.__send__(method, rs_method_name) }
86
86
  end
87
87
  end
@@ -180,7 +180,7 @@ class Test::Redef
180
180
  klass.__send__(:alias_method, hider, method_name)
181
181
  real_redef_method_name = "__redef_new_method_#{@@redef_next_id}"
182
182
  temporary_methods << [klass, real_redef_method_name]
183
- @@redef_next_id += 1;
183
+ @@redef_next_id += 1
184
184
  klass.__send__(:define_method, real_redef_method_name, method)
185
185
  arity = method.arity
186
186
 
data/test/redef.rb CHANGED
@@ -137,6 +137,7 @@ class RedefTest < Test::Unit::TestCase
137
137
  assert_equal( [["pacifies-empiricism\'s"]], rd['TestClass#test_method'].args )
138
138
 
139
139
  assert_equal( 1, rd[:class_method].called )
140
+ assert( rd[:class_method].called? )
140
141
  assert_equal( [[]], rd[:class_method].args )
141
142
  end
142
143
  end
@@ -152,6 +153,8 @@ class RedefTest < Test::Unit::TestCase
152
153
  assert_equal( 0, rd['TestClass#both_class_and_instance'].called )
153
154
  assert_equal( 0, rd['TestClass.both_class_and_instance'].called )
154
155
 
156
+ assert( !rd['TestClass#both_class_and_instance'].called? )
157
+ assert( !rd['TestClass.both_class_and_instance'].called? )
155
158
 
156
159
  assert_equal( 'new_instance', a.both_class_and_instance )
157
160
  assert_equal( 'new_class', TestClass.both_class_and_instance )
@@ -208,13 +211,25 @@ class RedefTest < Test::Unit::TestCase
208
211
  assert_raises( NoMethodError ) do
209
212
  a.private_method
210
213
  end
211
- Test::Redef.publicize_method('TestClass#private_method', 'TestClass.private_class_method') do
214
+ Test::Redef.publicize_method(
215
+ 'TestClass#private_method',
216
+ 'TestClass.private_class_method',
217
+ 'TestClass#test_method',
218
+ 'TestClass.class_method',
219
+ ) do
212
220
  assert_equal( 'orig private method', a.private_method )
213
221
  assert_equal( 'bolero-mute', TestClass.private_class_method )
222
+ assert_equal( 'orig', a.test_method )
223
+ assert_equal( 'orig', TestClass.class_method )
214
224
  end
225
+
215
226
  assert_raises( NoMethodError ) do
216
227
  a.private_method
217
228
  end
229
+
230
+ # don't privatize methods that were public
231
+ assert_equal( 'orig', a.test_method )
232
+ assert_equal( 'orig', TestClass.class_method )
218
233
  end
219
234
 
220
235
  # this sometimes seems like a good idea, but can lead to subtle bugs
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: test-redef
3
3
  version: !ruby/object:Gem::Version
4
- version: '1.0'
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
- - Nearbuy Systems
7
+ - RetailNext
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-08-14 00:00:00.000000000 Z
11
+ date: 2014-09-04 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Replace methods with test code, get feedback on how they are called and
14
14
  put it all back together when your test is done.
@@ -21,7 +21,7 @@ files:
21
21
  - Rakefile
22
22
  - lib/test/redef.rb
23
23
  - test/redef.rb
24
- homepage: http://github.com/nearbuy/test-redef
24
+ homepage: http://github.com/retailnext/test-redef
25
25
  licenses:
26
26
  - MIT
27
27
  metadata: {}
@@ -31,18 +31,18 @@ require_paths:
31
31
  - lib
32
32
  required_ruby_version: !ruby/object:Gem::Requirement
33
33
  requirements:
34
- - - '>='
34
+ - - ">="
35
35
  - !ruby/object:Gem::Version
36
36
  version: 1.9.2
37
37
  required_rubygems_version: !ruby/object:Gem::Requirement
38
38
  requirements:
39
- - - '>='
39
+ - - ">="
40
40
  - !ruby/object:Gem::Version
41
41
  version: '0'
42
42
  requirements: []
43
43
  rubyforge_project:
44
- rubygems_version: 2.0.3
44
+ rubygems_version: 2.2.2
45
45
  signing_key:
46
46
  specification_version: 4
47
- summary: Scopped and logged monkey patching for unit tests
47
+ summary: Scoped and logged monkey patching for unit tests
48
48
  test_files: []