Permalink
Browse files

Make Procsy a module and extend the generated Procs instead of

inheriting from Proc.

- This allows Procsy to behave correctly in all supported versions of
  MRI, as well as JRuby-1.5 and JRuby-1.6.
- See http://jira.codehaus.org/browse/JRUBY-5261
- See http://jira.codehaus.org/browse/JRUBY-5026
- Thanks to John Firebaugh for the suggestion!
- Closes #291 (hopefully forealz)
  • Loading branch information...
1 parent 6a860d9 commit 33f490362b00372f4c7c93376396fec6f897f697 @dchelimsky dchelimsky committed Jan 27, 2011
Showing with 14 additions and 6 deletions.
  1. +13 −5 lib/rspec/core/example.rb
  2. +1 −1 lib/rspec/core/example_group.rb
View
@@ -75,12 +75,20 @@ def fail_fast(reporter, exception)
finish(reporter)
end
- class Procsy < Proc
+ def self.procsy(metadata, &block)
+ Proc.new(&block).extend(Procsy).with(metadata)
+ end
+
+ module Procsy
attr_reader :metadata
- alias_method :run, :call
- def initialize(metadata, &block)
+
+ def self.extended(object)
+ def object.run; call; end
+ end
+
+ def with(metadata)
@metadata = metadata
- super(&block)
+ self
end
end
@@ -97,7 +105,7 @@ def with_around_hooks(&block)
if around_hooks.empty?
yield
else
- @example_group_class.eval_around_eachs(self, Procsy.new(metadata, &block)).call
+ @example_group_class.eval_around_eachs(self, Example.procsy(metadata, &block)).call
end
end
@@ -180,7 +180,7 @@ def self.eval_before_alls(example_group_instance)
def self.eval_around_eachs(example, initial_procsy)
example.around_hooks.reverse.inject(initial_procsy) do |procsy, around_hook|
- Example::Procsy.new(procsy.metadata) do
+ Example.procsy(procsy.metadata) do
example.example_group_instance.instance_eval_with_args(procsy, &around_hook)
end
end

0 comments on commit 33f4903

Please sign in to comment.