Skip to content

Instantly share code, notes, and snippets.

@antarestrader
Created January 7, 2009 19:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save antarestrader/44383 to your computer and use it in GitHub Desktop.
Save antarestrader/44383 to your computer and use it in GitHub Desktop.
Persistance steps for Cucumber
#Common steps for persisting information
#Copyright 2009 John Miller. Licensed under the terms of the MIT License.
NOUN_FORMS = '((?:that|those) \w*|the \d+(?:st|nd|rd|th) \w*?|it|I|me|".+?"|the \w* named ".*?")'
IS = '(?:is|are|am)'
Given (/^#{NOUN_FORMS} #{IS} labeled "(.*?)"/) do |noun,label|
@_labels ||= {}
@it = get_noun(noun)
@_labels[label] = @it
end
Given (/^#{NOUN_FORMS} #{IS} named "(.*?)"/) do |noun,name|
@it = get_noun(element,item)
@it.name = name
@it.save!
end
def get_noun(noun)
case noun
when /"(.*)"/
@_label[$1]
when /(?:that|those) (\w*)/
instance_variable_get "@#{$1}"
when /the (\d+)(?:st|nd|rd|th) (\w*)/
instance_variable_set "@#{$2}",(instance_variable_get "@#{$2.pluralize}")[$1.to_i - 1]
when "it"
@it
when "I","me"
@me
when /the (\w*) named "(.*)"/
#todo Check this
instance_variable_set "@#{$1}",(Object.const_get($1.capitalize).get(:first, :name=>$2))
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment