Module: Gurke::DSL

Defined in:
lib/gurke/dsl.rb

Instance Method Summary collapse

Instance Method Details

#_define_step(pattern, method_name, opts, &block) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/gurke/dsl.rb', line 20

def _define_step(pattern, method_name, opts, &block)
  step = StepDefinition.new(pattern, opts)

  define_method("match: #{step.method_name}") do |name, s = nil|
    step.match(name, s)
  end

  if block_given?
    define_method(step.method_name.to_s, &block)
  elsif method_name
    alias_method step.method_name.to_s, method_name
  end
end

#Given(pattern, method_name = nil, opts = {}, &block) ⇒ Object

rubocop:disable MethodName



35
36
37
# File 'lib/gurke/dsl.rb', line 35

def Given(pattern, method_name = nil, opts = {}, &block)
  step pattern, method_name, opts.merge(type: :given), &block
end

#step(pattern, method_name = nil, opts = {}, &block) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/gurke/dsl.rb', line 5

def step(pattern, method_name = nil, opts = {}, &block)
  if method_name.is_a?(Hash) && opts.empty?
    opts = method_name
    method_name = nil
  end

  if method_name && block_given?
    raise ArgumentError.new <<~ERR.strip
      You can either specify a method name or given a block, not both.
    ERR
  end

  _define_step(pattern, method_name, opts, &block)
end

#Then(pattern, method_name = nil, opts = {}, &block) ⇒ Object



43
44
45
# File 'lib/gurke/dsl.rb', line 43

def Then(pattern, method_name = nil, opts = {}, &block)
  step pattern, method_name, opts.merge(type: :then), &block
end

#When(pattern, method_name = nil, opts = {}, &block) ⇒ Object



39
40
41
# File 'lib/gurke/dsl.rb', line 39

def When(pattern, method_name = nil, opts = {}, &block)
  step pattern, method_name, opts.merge(type: :when), &block
end