Skip to content

Instantly share code, notes, and snippets.

@vysogot
Created July 5, 2011 09:05
Show Gist options
  • Save vysogot/1064521 to your computer and use it in GitHub Desktop.
Save vysogot/1064521 to your computer and use it in GitHub Desktop.
user stories for test unit
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