Created
January 7, 2009 19:37
-
-
Save antarestrader/44383 to your computer and use it in GitHub Desktop.
Persistance steps for Cucumber
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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