Module: CucumberFactory::Factory

Defined in:
lib/cucumber_factory/factory.rb

Defined Under Namespace

Classes: Error

Constant Summary collapse

ATTRIBUTES_PATTERN =

… with the year 1979 which is science fiction

'( with the .+?)?( (?:which|who|that) is .+?)?'
TEXT_ATTRIBUTES_PATTERN =
' (?:with|and) these attributes:'
UPDATE_ATTR_PATTERN =

… belongs to the collection “Fantasy” and is trending

'(?: (?:has|belongs to)( the .+?)|(?: and| but|,)*( is .+?))'
TEXT_UPDATE_ATTR_PATTERN =
'(?: and|,)* has these attributes:'
RECORD_PATTERN =

Given there is a movie (comedy)

'there is an? (.+?)( \(.+?\))?'
NAMED_RECORD_PATTERN =

Given “LotR” is a movie

'(?:"([^\"]*)"|\'([^\']*)\') is an? (.+?)( \(.+?\))?'
RECORD_UPDATE_PATTERN =

Given the movie “LotR” …

'the ([^"\',]+?) (above|".+?"|\'.+?\')'
NAMED_RECORDS_VARIABLE =
:'@named_cucumber_factory_records'
VALUE_INTEGER =
/\d+/
VALUE_DECIMAL =
/[\d\.]+/
VALUE_STRING =
/"[^"]*"|'[^']*'/
VALUE_FILE =
/file:#{VALUE_STRING}/
VALUE_ARRAY =
/\[[^\]]*\]/
VALUE_LAST_RECORD =
/\babove\b/
VALUE_SCALAR =
/#{VALUE_STRING}|#{VALUE_DECIMAL}|#{VALUE_INTEGER}|#{VALUE_FILE}/
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, a6| CucumberFactory::Factory.send(:parse_named_creation, self, a1, a2, a3, a4, a5, a6) }
}
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) }
}
UPDATE_STEP_DESCRIPTOR =
{
  :kind => :And,
  :pattern => /^#{RECORD_UPDATE_PATTERN}#{UPDATE_ATTR_PATTERN}+$/,
  :block => lambda { |a1, a2, a3, a4| CucumberFactory::Factory.send(:parse_update, 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, a7| CucumberFactory::Factory.send(:parse_named_creation, self, a1, a2, a3, a4, a5, a6, a7) },
  :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
}
UPDATE_STEP_DESCRIPTOR_WITH_TEXT_ATTRIBUTES =
{
  :kind => :And,
  :pattern => /^#{RECORD_UPDATE_PATTERN}#{UPDATE_ATTR_PATTERN}*#{TEXT_UPDATE_ATTR_PATTERN}$/,
  :block => lambda { |a1, a2, a3, a4, a5| CucumberFactory::Factory.send(:parse_update, self, a1, a2, a3, a4, a5) },
  :priority => true
}

Class Method Summary collapse

Class Method Details

.add_steps(main) ⇒ Object



75
76
77
78
79
80
81
82
83
# File 'lib/cucumber_factory/factory.rb', line 75

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)
  add_step(main, UPDATE_STEP_DESCRIPTOR)
  add_step(main, UPDATE_STEP_DESCRIPTOR_WITH_TEXT_ATTRIBUTES)
end