Module: CucumberFactory::Factory

Defined in:
lib/cucumber_factory/factory.rb

Defined Under Namespace

Classes: Error

Constant Summary collapse

ATTRIBUTES_PATTERN =
'( with the .+?)?( (?:which|who|that) is .+?)?'
TEXT_ATTRIBUTES_PATTERN =
' (?:with|and) these attributes:'
RECORD_PATTERN =
'there is an? (.+?)( \(.+?\))?'
NAMED_RECORD_PATTERN =
'"([^\"]*)" is an? (.+?)( \(.+?\))?'
NAMED_RECORDS_VARIABLE =
:'@named_cucumber_factory_records'
VALUE_INTEGER =
/\d+/
VALUE_DECIMAL =
/[\d\.]+/
VALUE_STRING =
/"[^"]*"/
VALUE_ARRAY =
/\[[^\]]*\]/
VALUE_LAST_RECORD =
/\babove\b/
VALUE_SCALAR =
/#{VALUE_STRING}|#{VALUE_DECIMAL}|#{VALUE_INTEGER}/
CLEAR_NAMED_RECORDS_STEP_DESCRIPTOR =
{
  :kind => :Before,
  :block => proc { CucumberFactory::Factory.send(:reset_named_records, self) }
}
NAMED_CREATION_STEP_DESCRIPTOR =

We cannot use vararg blocks in the descriptors in Ruby 1.8, as explained by Aslak: www.ruby-forum.com/topic/182927. We use different descriptors and cucumber priority to work around it.

{
  :kind => :Given,
  :pattern => /^#{NAMED_RECORD_PATTERN}#{ATTRIBUTES_PATTERN}?$/,
  :block => lambda { |a1, a2, a3, a4, a5| CucumberFactory::Factory.send(:parse_named_creation, self, a1, a2, a3, a4, a5) }
}
CREATION_STEP_DESCRIPTOR =
{
  :kind => :Given,
  :pattern => /^#{RECORD_PATTERN}#{ATTRIBUTES_PATTERN}$/,
  :block => lambda { |a1, a2, a3, a4| CucumberFactory::Factory.send(:parse_creation, self, a1, a2, a3, a4) }
}
NAMED_CREATION_STEP_DESCRIPTOR_WITH_TEXT_ATTRIBUTES =
{
  :kind => :Given,
  :pattern => /^"#{NAMED_RECORD_PATTERN}#{ATTRIBUTES_PATTERN}#{TEXT_ATTRIBUTES_PATTERN}?$/,
  :block => lambda { |a1, a2, a3, a4, a5, a6| CucumberFactory::Factory.send(:parse_named_creation, self, a1, a2, a3, a4, a5, a6) },
  :priority => true
}
CREATION_STEP_DESCRIPTOR_WITH_TEXT_ATTRIBUTES =
{
  :kind => :Given,
  :pattern => /^#{RECORD_PATTERN}#{ATTRIBUTES_PATTERN}#{TEXT_ATTRIBUTES_PATTERN}$/,
  :block => lambda { |a1, a2, a3, a4, a5| CucumberFactory::Factory.send(:parse_creation, self, a1, a2, a3, a4, a5) },
  :priority => true
}

Class Method Summary collapse

Class Method Details

.add_steps(main) ⇒ Object



58
59
60
61
62
63
64
# File 'lib/cucumber_factory/factory.rb', line 58

def add_steps(main)
  add_step(main, CREATION_STEP_DESCRIPTOR)
  add_step(main, NAMED_CREATION_STEP_DESCRIPTOR)
  add_step(main, CREATION_STEP_DESCRIPTOR_WITH_TEXT_ATTRIBUTES)
  add_step(main, NAMED_CREATION_STEP_DESCRIPTOR_WITH_TEXT_ATTRIBUTES)
  add_step(main, CLEAR_NAMED_RECORDS_STEP_DESCRIPTOR)
end