Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Factor out target proc from factory method

  • Loading branch information...
commit 82986417fd4ac0fa4e1edf773e70c0f5e133dc54 1 parent 8aa614c
@mattwynne mattwynne authored
Showing with 15 additions and 12 deletions.
  1. +15 −12 lib/cucumber/rb_support/rb_step_definition.rb
View
27 lib/cucumber/rb_support/rb_step_definition.rb
@@ -43,22 +43,25 @@ def create_proc(proc_or_sym, options)
return proc_or_sym if proc_or_sym.is_a?(Proc)
raise ArgumentError unless proc_or_sym.is_a?(Symbol)
message = proc_or_sym
+ target_proc = parse_target_proc_from(options)
lambda do |*args|
- target = if options.key?(:on)
- case options[:on]
- when Proc
- instance_exec(&options[:on])
- when Symbol
- self.send(options[:on])
- else
- raise ArgumentError, "Target must be a symbol or a proc"
- end
- else
- self
- end
+ target = instance_exec(&target_proc)
target.send(message, *args)
end
end
+
+ def parse_target_proc_from(options)
+ return lambda { self } unless options.key?(:on)
+ target = options[:on]
+ case target
+ when Proc
+ target
+ when Symbol
+ lambda { self.send(target) }
+ else
+ lambda { raise ArgumentError, "Target must be a symbol or a proc" }
+ end
+ end
end
def initialize(rb_language, regexp, proc)
Please sign in to comment.
Something went wrong with that request. Please try again.