Created
September 2, 2016 13:57
-
-
Save arthurnn/2efeb3a43b7cfae8ace267140ec36767 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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