Skip to content

Instantly share code, notes, and snippets.

@arthurnn
Created September 2, 2016 13:57
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 arthurnn/2efeb3a43b7cfae8ace267140ec36767 to your computer and use it in GitHub Desktop.
Save arthurnn/2efeb3a43b7cfae8ace267140ec36767 to your computer and use it in GitHub Desktop.
require 'active_support/all'
module SetupAndTeardown
extend ActiveSupport::Concern
included do
class_attribute :callbacks
self.callbacks = []
end
module ClassMethods
def setup(&block)
#self.callbacks ||= []
callbacks << block
end
end
end
module Behavior
def self.included(base)
base.include SetupAndTeardown
end
end
class TestCase
include Behavior
end
class MyFirstTest < TestCase
setup { puts "#{self}:C" }
end
class MyTest < TestCase
setup { puts "#{self}:A" }
setup { puts "#{self}:B" }
def foo
self.class.callbacks.each { |c| instance_eval(&c) }
end
end
MyTest.new.foo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment