rconditions 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.
Files changed (4) hide show
  1. data/README +1 -0
  2. data/lib/rconditions.rb +12 -8
  3. data/test/rconditions_test.rb +37 -1
  4. metadata +38 -38
data/README CHANGED
@@ -96,6 +96,7 @@ the require call. Our test setup had no measurable slowdown afterwards.
96
96
  The test suite of RConditions passes for
97
97
  * ruby 1.8.6
98
98
  * ruby 1.9.0 (tested with revision 13680)
99
+ * jruby 1.1 (tested with revision 4574)
99
100
 
100
101
  If you use another ruby version, please check whether the tests pass.
101
102
 
data/lib/rconditions.rb CHANGED
@@ -31,7 +31,7 @@ module RConditions
31
31
  def extend_predicate_methods_and_define_bang_methods
32
32
  ObjectSpace.each_object(Module) do |mod|
33
33
  (mod.instance_methods(false) + mod.private_instance_methods(false)).each do |id|
34
- RConditions.extend_predicate_method_and_define_bang_method(mod, id)
34
+ ::RConditions.extend_predicate_method_and_define_bang_method(mod, id)
35
35
  end
36
36
  end
37
37
  end
@@ -61,7 +61,7 @@ module RConditions
61
61
  mod.const_set(positive_module, Module.new) unless mod.const_defined?(positive_module)
62
62
  negative_module = camelize("not_#{predicate_method_without_questionmark}_error")
63
63
  mod.const_set(negative_module, Module.new) unless mod.const_defined?(negative_module)
64
-
64
+
65
65
  time = Time.now
66
66
  predicate_method_without_rconditions = "#{predicate_method_without_questionmark}_rconditions_#{mod.object_id}_#{time.to_i}_#{time.usec}"
67
67
 
@@ -73,6 +73,10 @@ module RConditions
73
73
  result = #{predicate_method_without_rconditions}(*args, &block)
74
74
  ::RConditions.add_exception_module(result ? #{positive_module} : #{negative_module})
75
75
  result
76
+ rescue NoMethodError => e
77
+ raise unless self.is_a?(Module) && e.message =~ /#{Regexp.escape(predicate_method_without_rconditions)}/
78
+ module_function :#{predicate_method_without_rconditions}
79
+ #{predicate_method_without_rconditions}(*args, &block)
76
80
  end
77
81
  #{visibility(mod, predicate_method)} :#{predicate_method}
78
82
  EOS
@@ -111,16 +115,16 @@ module RConditions
111
115
  end
112
116
  end
113
117
 
114
- unless defined? RCONDITIONS_ONLY_FOR_NEW_METHODS
118
+ unless defined? ::RCONDITIONS_ONLY_FOR_NEW_METHODS
115
119
  # To apply RConditions to new methods only, set this constant to <tt>true</tt>
116
120
  # before <tt>require "rconditions"</tt>.
117
- RCONDITIONS_ONLY_FOR_NEW_METHODS = false
121
+ ::RCONDITIONS_ONLY_FOR_NEW_METHODS = false
118
122
  end
119
-
120
- unless RCONDITIONS_ONLY_FOR_NEW_METHODS
121
- RConditions.extend_predicate_methods_and_define_bang_methods
123
+
124
+ unless ::RCONDITIONS_ONLY_FOR_NEW_METHODS
125
+ ::RConditions.extend_predicate_methods_and_define_bang_methods
122
126
  end
123
-
127
+
124
128
  class Module #:nodoc:
125
129
  alias_method :method_added_without_rconditions, :method_added
126
130
  private :method_added_without_rconditions
@@ -239,7 +239,7 @@ class RConditionsTest < Test::Unit::TestCase
239
239
  assert e.kind_of?(NowANamedModule::NotActivatedError)
240
240
  end
241
241
 
242
- def test_does_not_work_for_virtual_classes
242
+ def test_does_not_work_for_singleton_methods
243
243
  f = Foo.new
244
244
  class << f
245
245
  def x?; b?; end
@@ -247,6 +247,42 @@ class RConditionsTest < Test::Unit::TestCase
247
247
  assert !f.respond_to?(:x!)
248
248
  end
249
249
 
250
+ def test_does_not_break_module_functions
251
+ eval <<-EOS
252
+ module WithModuleFunctions
253
+ def module_function_1?
254
+ 'module_function_1?'
255
+ end
256
+ module_function :module_function_1?
257
+
258
+ module_function
259
+ def module_function_2?
260
+ 'module_function_2?'
261
+ end
262
+ end
263
+ EOS
264
+ assert !WithModuleFunctions.respond_to?(:module_function_1!)
265
+ assert !WithModuleFunctions.respond_to?(:module_function_2!)
266
+ assert_equal 'module_function_1?', WithModuleFunctions.module_function_1?
267
+ assert_equal 'module_function_2?', WithModuleFunctions.module_function_2?
268
+ end
269
+
270
+ def test_module_functions_fix_ignores_no_method_error_from_non_module_function
271
+ eval <<-EOS
272
+ module ModuleWithNoMethodError
273
+ def error?
274
+ foo()
275
+ end
276
+ module_function :error?
277
+ end
278
+ EOS
279
+ o = Object.new
280
+ class<<o;include ModuleWithNoMethodError;end
281
+ e = exception_raised_by { o.instance_eval { error? } }
282
+ assert_equal NoMethodError, e.class
283
+ assert e.message =~ /foo/
284
+ end
285
+
250
286
  def test_exception_in_a_predicate_method_does_not_screw_up_the_next_result
251
287
  eval <<-EOS
252
288
  class Foo
metadata CHANGED
@@ -1,41 +1,17 @@
1
- --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.9.2
3
- specification_version: 1
4
- name: rconditions
5
- version: !ruby/object:Gem::Version
6
- version: 0.2.0
7
- date: 2007-10-14 00:00:00 +02:00
8
- summary: RConditions generates a bang method (for example, Array#empty!) for each predicate method (for example, Array#empty?). The bang method will return true if the predicate method returns true, otherwise it will throw an exception. The exception will include auto-generated modules that give information on predicate methods passed or failed in the bang method's execution.
9
- require_paths:
10
- - lib
11
- email: tammo@tammofreese.de
1
+ --- !ruby/object:Gem::Specification
12
2
  homepage: http://rconditions.rubyforge.org
13
- rubyforge_project:
14
- description:
15
- autorequire: rconditions
16
- default_executable:
17
- bindir: bin
18
- has_rdoc: true
19
- required_ruby_version: !ruby/object:Gem::Version::Requirement
20
- requirements:
21
- - - ">"
22
- - !ruby/object:Gem::Version
23
- version: 0.0.0
24
- version:
25
- platform: ruby
26
- signing_key:
27
- cert_chain:
3
+ extensions: []
4
+ executables: []
5
+ version: !ruby/object:Gem::Version
6
+ version: 0.3.0
28
7
  post_install_message:
29
- authors:
30
- - Norman Timmler
31
- - Tammo Freese
8
+ date: 2007-11-28 23:00:00 +00:00
32
9
  files:
33
10
  - test/rconditions_test.rb
34
11
  - lib/rconditions.rb
35
12
  - README
36
13
  - MIT-LICENSE
37
- test_files:
38
- - test/rconditions_test.rb
14
+ rubygems_version: 0.9.4
39
15
  rdoc_options:
40
16
  - --title
41
17
  - RConditions RDoc Documentation
@@ -43,14 +19,38 @@ rdoc_options:
43
19
  - README
44
20
  - --charset
45
21
  - utf-8
22
+ signing_key:
23
+ cert_chain:
24
+ name: rconditions
25
+ has_rdoc: true
26
+ platform: ruby
27
+ summary: RConditions generates a bang method (for example, Array#empty!) for each
28
+ predicate method (for example, Array#empty?). The bang method will return true if
29
+ the predicate method returns true, otherwise it will throw an exception. The exception
30
+ will include auto-generated modules that give information on predicate methods passed
31
+ or failed in the bang method's execution.
32
+ default_executable:
33
+ bindir: bin
34
+ required_ruby_version: !ruby/object:Gem::Version::Requirement
35
+ version:
36
+ requirements:
37
+ - - '>'
38
+ - !ruby/object:Gem::Version
39
+ version: 0.0.0
40
+ require_paths:
41
+ - lib
42
+ specification_version: 1
43
+ test_files:
44
+ - test/rconditions_test.rb
45
+ dependencies: []
46
+ description:
47
+ authors:
48
+ - Norman Timmler
49
+ - Tammo Freese
50
+ email: tammo@tammofreese.de
46
51
  extra_rdoc_files:
47
52
  - README
48
53
  - MIT-LICENSE
49
- executables: []
50
-
51
- extensions: []
52
-
53
54
  requirements: []
54
-
55
- dependencies: []
56
-
55
+ rubyforge_project:
56
+ autorequire: rconditions