Sha256: 9c1708b45f3004c0575e1e98e6e0ac00e601d46ef614bce867eb27ac8740e3f8

Contents?: true

Size: 847 Bytes

Versions: 4

Compression:

Stored size: 847 Bytes

Contents

module Gurke
  #
  module Steps
    #
    # rubocop:disable MethodName
    def Given(step)
      rst = self.class.find_step(step, self, :given)
      send rst.method_name
    end

    def When(step)
      rst = self.class.find_step(step, self, :when)
      send rst.method_name
    end

    def Then(step)
      rst = self.class.find_step(step, self, :then)
      send rst.method_name
    end

    class << self
      def find_step(step, world, type)
        matches = world.methods.map do |method|
          next unless method.to_s.start_with?('match: ')
          world.send(method.to_s, step.to_s, type)
        end.compact

        case matches.size
          when 0 then raise Gurke::StepPending.new step.to_s
          when 1 then matches.first
          else raise Gurke::StepAmbiguous.new step.to_s
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
gurke-2.0.0.dev.1.b20 lib/gurke/steps.rb
gurke-2.0.0.dev.1.b19 lib/gurke/steps.rb
gurke-2.0.0.dev.1.b18 lib/gurke/steps.rb
gurke-2.0.0.dev.1.b17 lib/gurke/steps.rb