Class: Hypercuke::StepDriver

Inherits:
Object
  • Object
show all
Defined in:
lib/hypercuke/step_driver.rb

Overview

The step driver serves as the entry point from Cucumber step definition bodies to the Hypercuke API. An instance of this object will be made available to Cucumber::World via the #step_driver method.

The StepDriver will interpret any message sent to it as a topic name, combine that with the current_layer name from Hypercuke, and use that to instantitate a StepAdapter for the appropriate topic/layer combo.

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *_O) ⇒ Object

No arguments for you, Mister Bond! *adjusts monocle*



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/hypercuke/step_driver.rb', line 17

def method_missing(method, *_O) # No arguments for you, Mister Bond! *adjusts monocle*
  topic_name = method.to_sym

  # Define a method for the topic name so that future requests for
  # the same step adapter don't pay the method_missing tax.
  self.class.send(:define_method, topic_name) do
    # Within the defined method, memoize the step adapter so that
    # future requests also don't pay the GC tax.
    key = [topic_name, layer_name] # key on both names in case someone changes the layer on us
    __step_adapters__[key] ||=
      begin
        klass = Hypercuke.step_adapter_class(*key)
        klass.new(__context__, self)
      end
  end

  # And don't forget to invoke the newly-created method.
  send(method)
end

Instance Method Details

#layer_nameObject



13
14
15
# File 'lib/hypercuke/step_driver.rb', line 13

def layer_name
  Hypercuke.current_layer
end

#respond_to_missing?(_) ⇒ Boolean

StepDriver is eager to please.

Returns:

  • (Boolean)


38
39
40
# File 'lib/hypercuke/step_driver.rb', line 38

def respond_to_missing?(_)
  true
end