Skip to content

Instantly share code, notes, and snippets.

@seanbehan
Forked from defunkt/mini.rb
Created January 13, 2012 18:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seanbehan/1607872 to your computer and use it in GitHub Desktop.
Save seanbehan/1607872 to your computer and use it in GitHub Desktop.
test/spec/mini 5 - nested contexts, stacked setups
require 'test/spec/mini'
context "It's test/spec/mini!" do
setup do
@name = "Chris"
end
teardown do
@name = nil
end
test "with Test::Unit" do
assert (self.class < Test::Unit::TestCase)
end
test "body-less test cases"
xtest "disabled tests" do
assert disabled!
end
context "and of course" do
test "nested contexts!" do
assert_equal "Chris", @name
end
end
end
##
# test/spec/mini 4
# http://gist.github.com/307649
# chris@ozmm.org
#
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.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, &block) 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment