Skip to content
This repository
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 62 lines (51 sloc) 1.367 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
require 'active_support/concern'
require 'test/unit/assertions'

module RSpec
  module Rails
    module SetupAndTeardownAdapter
      extend ActiveSupport::Concern

      module ClassMethods
        def setup(*methods)
          methods.each {|method| before { send method } }
        end

        def teardown(*methods)
          methods.each {|method| after { send method } }
        end
      end

      module InstanceMethods
        def method_name
          @example
        end
      end
    end

    module TestUnitAssertionAdapter
      extend ActiveSupport::Concern

      class AssertionDelegate
        include Test::Unit::Assertions
      end

      module ClassMethods
        def assertion_method_names
          Test::Unit::Assertions.public_instance_methods.select{|m| m.to_s =~ /^(assert|flunk)/} +
            [:build_message]
        end

        def define_assertion_delegators
          assertion_method_names.each do |m|
            class_eval <<-CODE
def #{m}(*args, &block)
assertion_delegate.send :#{m}, *args, &block
end
CODE
          end
        end
      end

      module InstanceMethods
        def assertion_delegate
          @assertion_delegate ||= AssertionDelegate.new
        end
      end

      included do
        define_assertion_delegators
      end
    end
  end
end
Something went wrong with that request. Please try again.