Sha256: 1659d0dffb380a622d05b1583d636aab7aeebcbb0bcde0bc887f292254221316

Contents?: true

Size: 1.56 KB

Versions: 7

Compression:

Stored size: 1.56 KB

Contents

module TestBelt::Callbacks
  module Test

    # Test before/setup callbacks run before each test in the test case class.
    # The after/teardown callbacks run after each test in the test case class.
    # Each pair does identical logic - they are just an alias of each other so
    # use what reads better to you.

    # Usage:
    # <pre>
    #   class SomeTest < Test::Unit::TestCase
    #     include TestBelt::Callbacks::Test
    #
    #     before {
    #       # anything here runs before each test
    #     }
    #     after {
    #       # anything here runs after each test
    #     }
    #
    #     should 'do stuff' do
    #       assert true
    #     end
    #   end
    # </pre>

    def self.included(receiver)
      receiver.send(:extend, ClassMethods)
    end

    module ClassMethods
      def setup(&block)
        raise ArgumentError, "please provide a setup block" unless block_given?
        @_testbelt_setups ||= []
        @_testbelt_setups << block
      end
      alias_method :before, :setup

      def _testbelt_setups
        ((begin; superclass._testbelt_setups; rescue NoMethodError; []; end) || []) +
        (@_testbelt_setups || [])
      end

      def teardown(&block)
        raise ArgumentError, "please provide a teardown block" unless block_given?
        @_testbelt_teardowns ||= []
        @_testbelt_teardowns << block
      end
      alias_method :after, :teardown

      def _testbelt_teardowns
        ((begin; superclass._testbelt_teardowns; rescue NoMethodError; []; end) || []) +
        (@_testbelt_teardowns || [])
      end
    end

  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
test-belt-2.0.1 lib/test_belt/callbacks/test.rb
test-belt-2.0.0 lib/test_belt/callbacks/test.rb
test-belt-1.1.2 lib/test_belt/callbacks/test.rb
test-belt-1.1.1 lib/test_belt/callbacks/test.rb
test-belt-1.1.0 lib/test_belt/callbacks/test.rb
test-belt-1.0.1 lib/test_belt/callbacks/test.rb
test-belt-1.0.0 lib/test_belt/callbacks/test.rb