Class: Turnip::StepDefinition

Inherits:
Object
  • Object
show all
Defined in:
lib/turnip/step_definition.rb

Defined Under Namespace

Classes: Match

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(expression, method_name = nil, called_from = nil, &block) ⇒ StepDefinition

Returns a new instance of StepDefinition.



15
16
17
18
19
20
# File 'lib/turnip/step_definition.rb', line 15

def initialize(expression, method_name=nil, called_from=nil, &block)
  @expression = expression
  @method_name = method_name || expression
  @called_from = called_from
  @block = block
end

Instance Attribute Details

#blockObject (readonly)

Returns the value of attribute block.



13
14
15
# File 'lib/turnip/step_definition.rb', line 13

def block
  @block
end

#called_fromObject (readonly)

Returns the value of attribute called_from.



13
14
15
# File 'lib/turnip/step_definition.rb', line 13

def called_from
  @called_from
end

#expressionObject (readonly)

Returns the value of attribute expression.



13
14
15
# File 'lib/turnip/step_definition.rb', line 13

def expression
  @expression
end

#method_nameObject (readonly)

Returns the value of attribute method_name.



13
14
15
# File 'lib/turnip/step_definition.rb', line 13

def method_name
  @method_name
end

Instance Method Details

#match(description) ⇒ Object



26
27
28
29
30
31
32
33
34
35
# File 'lib/turnip/step_definition.rb', line 26

def match(description)
  result = description.match(regexp)
  if result
    params = result.captures
    @placeholder_names.each_with_index do |name, index|
      params[index] = Turnip::Placeholder.apply(name.to_sym, params[index])
    end
    Match.new(self, params, block)
  end
end

#regexpObject



22
23
24
# File 'lib/turnip/step_definition.rb', line 22

def regexp
  @regexp ||= compile_regexp
end