Skip to content

Instantly share code, notes, and snippets.

@arthurnn
Created September 2, 2016 13:57
Show Gist options
  • Select an option

  • Save arthurnn/2efeb3a43b7cfae8ace267140ec36767 to your computer and use it in GitHub Desktop.

Select an option

Save arthurnn/2efeb3a43b7cfae8ace267140ec36767 to your computer and use it in GitHub Desktop.

Revisions

  1. Arthur Nogueira Neves created this gist Sep 2, 2016.
    43 changes: 43 additions & 0 deletions test.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,43 @@
    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