Created
July 5, 2011 09:05
-
-
Save vysogot/1064521 to your computer and use it in GitHub Desktop.
user stories for test unit
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
module Test::Unit::UserStory | |
class UserStoryTestCase < ActionController::IntegrationTest | |
class << self | |
attr_accessor :description | |
alias :it :test | |
def criteria(name, options = {}, &block) | |
klass = create_class(name, self, &block) | |
helper_klass = options[:js] ? CapybaraJavascriptTestHelper : CapybaraTestHelper | |
klass.send(:include, helper_klass) | |
klass | |
end | |
def background(&block) | |
define_method(:setup, &block) | |
end | |
end | |
end | |
def story(name, description, options = {}, &block) | |
klass = create_class(name, UserStoryTestCase, &block) | |
klass.description = description | |
klass | |
end | |
def create_class(name, superclass, &block) | |
klass = Class.new(superclass, &block) | |
name = name.gsub(/(^\d*|\W)/, ' ').lstrip | |
klass_name = name.gsub(/(^[a-z]|\s+[a-zA-Z])/).each do |match| | |
match.lstrip.upcase | |
end | |
Object.const_set klass_name, klass | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment