Skip to content

Instantly share code, notes, and snippets.

@nickleefly
Forked from holman/gemspec-usage.md
Created November 29, 2012 13:20
Show Gist options
  • Save nickleefly/4169010 to your computer and use it in GitHub Desktop.
Save nickleefly/4169010 to your computer and use it in GitHub Desktop.
test/spec/mini

Just install this in your apps like so:

gem 'test-spec-mini', :git => 'git://gist.github.com/1806986.git', :require => 'mini'
##
# test/spec/mini 5
# http://gist.github.com/307649
# [email protected]
#
def context(*args, &block)
return super unless (name = args.first) && block
require 'test/unit'
klass = Class.new(defined?(ActiveSupport::TestCase) ? ActiveSupport::TestCase : Test::Unit::TestCase) do
def self.test(name, &block)
define_method("test_#{name.to_s.gsub(/\W/,'_')}", &block) if block
end
def self.xtest(*args) end
def self.context(*args, &block) instance_eval(&block) end
def self.setup(&block)
define_method(:setup) { self.class.setups.each { |s| instance_eval(&s) } }
setups << block
end
def self.setups; @setups ||= [] end
def self.teardown(&block) define_method(:teardown, &block) end
end
(class << klass; self end).send(:define_method, :name) { name.gsub(/\W/,'_') }
klass.class_eval &block
end
Gem::Specification.new do |s|
s.name = 'test-spec-mini'
s.version = '0.0.1'
s.platform = Gem::Platform::RUBY
s.author = 'Chris Wanstrath'
s.email = '[email protected]'
s.summary = 'test/spec/mini'
s.description = 'Simple, neat test contexts.'
s.files = ['mini.rb']
s.require_path = '.'
end
require 'test/spec/mini'
context "It's test/spec/mini!" do
setup do
@name = "Chris"
end
setup do
puts "Stacked setups!"
end
teardown do
@name = nil
end
test "with Test::Unit" do
assert (self.class < Test::Unit::TestCase)
end
test "body-less test cases"
test :symbol_test_names do
assert true
end
xtest "disabled tests" do
assert disabled!
end
context "and of course" do
test "nested contexts!" do
assert_equal "Chris", @name
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment