module Cucumber::Glue::ProtoWorld

def self.extended(object)

rubocop:disable Metrics/BlockLength
rubocop:disable Metrics/MethodLength
Dynamially generate the API module, closuring the dependencies
def self.extended(object)
  # wrap the dynamically generated module so that we can document the methods
  # for yardoc, which doesn't like define_method.
  object.extend(ProtoWorld)
end

def self.for(runtime, language) # rubocop:disable Metrics/MethodLength

rubocop:disable Metrics/MethodLength
Dynamially generate the API module, closuring the dependencies
def self.for(runtime, language) # rubocop:disable Metrics/MethodLength
  Module.new do # rubocop:disable Metrics/BlockLength
    def self.extended(object)
      # wrap the dynamically generated module so that we can document the methods
      # for yardoc, which doesn't like define_method.
      object.extend(ProtoWorld)
    end
    # TODO: pass these in when building the module, instead of mutating them later
    # Extend the World with user-defined modules
    def add_modules!(world_modules, namespaced_world_modules)
      add_world_modules!(world_modules)
      add_namespaced_modules!(namespaced_world_modules)
    end
    define_method(:step) do |name, raw_multiline_arg = nil|
      location = Core::Test::Location.of_caller
      runtime.invoke_dynamic_step(name, MultilineArgument.from(raw_multiline_arg, location))
    end
    define_method(:steps) do |steps_text|
      location = Core::Test::Location.of_caller
      runtime.invoke_dynamic_steps(steps_text, language, location)
    end
    # rubocop:disable UnneededInterpolation
    define_method(:puts) do |*messages|
      # Even though they won't be output until later, converting the messages to
      # strings right away will protect them from modifications to their original
      # objects in the mean time
      messages.collect! { |message| "#{message}" }
      runtime.puts(*messages)
    end
    # rubocop:enable UnneededInterpolation
    define_method(:ask) do |question, timeout_seconds = 60|
      runtime.ask(question, timeout_seconds)
    end
    define_method(:embed) do |file, mime_type, label = 'Screenshot'|
      runtime.embed(file, mime_type, label)
    end
    # Prints the list of modules that are included in the World
    def inspect
      modules = [self.class]
      (class << self; self; end).instance_eval do
        modules += included_modules
      end
      modules << stringify_namespaced_modules
      format('#<%<modules>s:0x%<object_id>x>', modules: modules.join('+'), object_id: object_id)
    end
    private
    # @private
    def add_world_modules!(modules)
      modules.each do |world_module|
        extend(world_module)
      end
    end
    # @private
    def add_namespaced_modules!(modules)
      @__namespaced_modules = modules
      modules.each do |namespace, world_modules|
        world_modules.each do |world_module|
          variable_name = "@__#{namespace}_world"
          inner_world = if self.class.respond_to?(namespace)
                          instance_variable_get(variable_name)
                        else
                          Object.new
                        end
          instance_variable_set(variable_name,
                                inner_world.extend(world_module))
          self.class.send(:define_method, namespace) do
            instance_variable_get(variable_name)
          end
        end
      end
    end
    # @private
    def stringify_namespaced_modules
      @__namespaced_modules.map { |k, v| "#{v.join(',')} (as #{k})" }.join('+')
    end
  end
end

def add_modules!(world_modules, namespaced_world_modules)

Extend the World with user-defined modules
TODO: pass these in when building the module, instead of mutating them later
def add_modules!(world_modules, namespaced_world_modules)
  add_world_modules!(world_modules)
  add_namespaced_modules!(namespaced_world_modules)
end

def add_namespaced_modules!(modules)

Other tags:
    Private: -
def add_namespaced_modules!(modules)
  @__namespaced_modules = modules
  modules.each do |namespace, world_modules|
    world_modules.each do |world_module|
      variable_name = "@__#{namespace}_world"
      inner_world = if self.class.respond_to?(namespace)
                      instance_variable_get(variable_name)
                    else
                      Object.new
                    end
      instance_variable_set(variable_name,
                            inner_world.extend(world_module))
      self.class.send(:define_method, namespace) do
        instance_variable_get(variable_name)
      end
    end
  end
end

def add_world_modules!(modules)

Other tags:
    Private: -
def add_world_modules!(modules)
  modules.each do |world_module|
    extend(world_module)
  end
end

def ask(question, timeout_seconds = 60)

Pause the tests and ask the operator for input
def ask(question, timeout_seconds = 60)
  super
end

def embed(file, mime_type, label = 'Screenshot')

Embed an image in the output
def embed(file, mime_type, label = 'Screenshot')
  super
end

def inspect

Prints the list of modules that are included in the World
def inspect
  super
end

def inspect

Prints the list of modules that are included in the World
def inspect
  modules = [self.class]
  (class << self; self; end).instance_eval do
    modules += included_modules
  end
  modules << stringify_namespaced_modules
  format('#<%<modules>s:0x%<object_id>x>', modules: modules.join('+'), object_id: object_id)
end

def pending(message = 'TODO')

Mark the matched step as pending.
def pending(message = 'TODO')
  raise Pending, message unless block_given?
  begin
    yield
  rescue Exception # rubocop:disable Lint/RescueException
    raise Pending, message
  end
  raise Pending, "Expected pending '#{message}' to fail. No Error was raised. No longer pending?"
end

def puts(*messages)

Other tags:
    Note: - Cucumber might surprise you with the behaviour of this method. Instead
def puts(*messages)
  super
end

def skip_this_scenario(message = 'Scenario skipped')

Skips this step and the remaining steps in the scenario
def skip_this_scenario(message = 'Scenario skipped')
  raise Core::Test::Result::Skipped, message
end

def step(name, raw_multiline_arg = nil)

Parameters:
  • multiline_argument (String, Cucumber::Test::DocString, Cucumber::Ast::Table) --
  • name (String) -- The name of the step

Other tags:
    Example: Passing a multiline string -
    Example: Passing a table -
    Example: Call a step with quotes in the name -
    Example: Call another step -
def step(name, raw_multiline_arg = nil)
  super
end

def steps(steps_text)

Parameters:
  • steps_text (String) -- The Gherkin snippet to run
def steps(steps_text)
  super
end

def stringify_namespaced_modules

Other tags:
    Private: -
def stringify_namespaced_modules
  @__namespaced_modules.map { |k, v| "#{v.join(',')} (as #{k})" }.join('+')
end

def table(text_or_table, file = nil, line = 0)

Parameters:
  • text_or_table (String) -- The Gherkin string that represents the table

Other tags:
    Example: Create a table -
def table(text_or_table, file = nil, line = 0)
  location = !file ? Core::Test::Location.of_caller : Core::Test::Location.new(file, line)
  MultilineArgument::DataTable.from(text_or_table, location)
end

def to_s

see {#inspect}
def to_s
  inspect
end