Skip to content

Instantly share code, notes, and snippets.

@arthurnn arthurnn/test.rb
Created Sep 2, 2016

Embed
What would you like to do?
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
You can’t perform that action at this time.