Created
September 23, 2009 03:56
-
-
Save larrytheliquid/191691 to your computer and use it in GitHub Desktop.
Reply to Cucumber Transform comment http://is.gd/3AqhI
This file contains hidden or 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
def self.TokenTransform(token, pattern, &transform) | |
unless Kernel.const_defined? token | |
class << val = [] | |
def to_s | |
"(#{Regexp.union(*self)})" | |
end | |
end | |
Kernel.const_set token, val | |
end | |
no_captures = Regexp.new(pattern.source.gsub(/\^|\$/, '').gsub('(', '(?:'), | |
pattern.options) | |
Kernel.const_get(token) << no_captures | |
Transform(pattern, &transform) | |
end | |
TokenTransform "PERSON", /^a young child$/ do | |
...code that creates a young child person and returns it... | |
end | |
TokenTransform "PERSON", /^an elderly person$/ do | |
...code that creates an elderly person and returns it... | |
end | |
TokenTransform "USER", /^a guest user$/ do | |
...code that creates a guest user and returns it... | |
end | |
TokenTransform "USER", /^a user with role (w+)$/ do | roleString | | |
...code that creates a user with a certain role and returns it... | |
end |
This file contains hidden or 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
Given /^#{PERSON} added by #{USER}$/ do | person, user | | |
... (code that uses person and user as their corresponding types, already converted from a string)... | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment