Sha256: ebda9572e1e953b5c97756c231fa0a96662e04b2ecd720ff2c601e0ee2f5646d

Contents?: true

Size: 1022 Bytes

Versions: 3

Compression:

Stored size: 1022 Bytes

Contents

module MiniTestSpecRails
  module DSL

    RAILS_TEST_CASES = []

    def self.included(klass)
      klass.extend ClassMethods
    end

    module ClassMethods  

      def before(type = nil, &block)
        setup { self.instance_eval(&block) }
      end

      def after(type = nil, &block)
        teardown { self.instance_eval(&block) }
      end

      def rails_test_cases
        RAILS_TEST_CASES
      end

      def register_rails_test_case(test_case)
        return if RAILS_TEST_CASES.include?(test_case)
        RAILS_TEST_CASES.unshift(test_case)
      end

      def describing_class
        ancestors.detect { |a| Class === a && rails_test_cases.include?(a.superclass) }
      end

      def described_class
        begin
          describing_class.name.gsub(/Test$/, '').constantize
        rescue NameError
          nil
        end
      end
      
    end

    def describing_class
      self.class.describing_class
    end

    def described_class
      self.class.described_class
    end
    
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
minitest-spec-rails-3.1.2 lib/minitest-spec-rails/dsl.rb
minitest-spec-rails-3.1.1 lib/minitest-spec-rails/dsl.rb
minitest-spec-rails-3.1.0 lib/minitest-spec-rails/dsl.rb