4 rescue LoadError ; raise "You must gem install heckle to use --heckle" ; end
8 # Creates a new Heckler configured to heckle all methods in the classes
9 # whose name matches +filter+
11 def initialize(filter, heckle_class=Heckler)
13 @heckle_class = heckle_class
16 # Runs all the example groups held by +rspec_options+ once for each of the
17 # methods in the matched classes.
19 if @filter =~ /(.*)[#\.](.*)/
22 heckle_class_or_module(@filter)
26 def heckle_method(class_name, method_name)
27 verify_constant(class_name)
28 heckle = @heckle_class.new(class_name, method_name, rspec_options)
32 def heckle_class_or_module(class_or_module_name)
33 verify_constant(class_or_module_name)
34 pattern = /^#{class_or_module_name}/
36 ObjectSpace.each_object(Class) do |klass|
37 classes << klass if klass.name =~ pattern
40 classes.each do |klass|
41 klass.instance_methods(false).each do |method_name|
42 heckle = @heckle_class.new(klass.name, method_name, rspec_options)
48 def verify_constant(name)
50 # This is defined in Heckle
53 raise "Heckling failed - \"#{name}\" is not a known class or module"
58 #Supports Heckle 1.2 and prior (earlier versions used Heckle::Base)
59 class Heckler < (Heckle.const_defined?(:Base) ? Heckle::Base : Heckle)
60 def initialize(klass_name, method_name, rspec_options)
61 super(klass_name, method_name)
62 @rspec_options = rspec_options
66 success = @rspec_options.run_examples