Sha256: 45c58d859d855f2b6ec73800376f0361dcf7ba45a11e99dc754f42ca8ace9b0b

Contents?: true

Size: 1.83 KB

Versions: 35

Compression:

Stored size: 1.83 KB

Contents

class ActiveSupport::TestCase
  include ActiveRecord::TestFixtures

  if ENV['AR_VERSION'].to_f >= 5.0
    self.use_transactional_tests = true
  else
    self.use_transactional_fixtures = true
  end

  class << self
    def requires_active_record_version(version_string, &blk)
      return unless Gem::Dependency.new('', version_string).match?('', ActiveRecord::VERSION::STRING)
      instance_eval(&blk)
    end

    def assertion(name, &block)
      mc = class << self; self; end
      mc.class_eval do
        define_method(name) do
          it(name, &block)
        end
      end
    end

    def asssertion_group(name, &block)
      mc = class << self; self; end
      mc.class_eval do
        define_method(name, &block)
      end
    end

    def macro(name, &block)
      class_eval do
        define_method(name, &block)
      end
    end

    def describe(description, toplevel = nil, &blk)
      text = toplevel ? description : "#{name} #{description}"
      klass = Class.new(self)

      klass.class_eval <<-RUBY_EVAL
        def self.name
          "#{text}"
        end
      RUBY_EVAL

      # do not inherit test methods from the superclass
      klass.class_eval do
        instance_methods.grep(/^test.+/) do |method|
          undef_method method
        end
      end

      klass.instance_eval(&blk)
    end
    alias context describe

    def let(name, &blk)
      define_method(name) do
        instance_variable_name = "@__let_#{name}"
        return instance_variable_get(instance_variable_name) if instance_variable_defined?(instance_variable_name)
        instance_variable_set(instance_variable_name, instance_eval(&blk))
      end
    end

    def it(description, &blk)
      define_method("test_#{name}_#{description}", &blk)
    end
  end
end

def describe(description, &blk)
  ActiveSupport::TestCase.describe(description, true, &blk)
end

Version data entries

35 entries across 35 versions & 2 rubygems

Version Path
activerecord-import-1.4.0 test/support/active_support/test_case_extensions.rb
activerecord-import-1.3.0 test/support/active_support/test_case_extensions.rb
rails_mini_profiler-0.2.0 vendor/bundle/ruby/3.0.0/gems/activerecord-import-1.2.0/test/support/active_support/test_case_extensions.rb
activerecord-import-1.2.0 test/support/active_support/test_case_extensions.rb
activerecord-import-1.1.0 test/support/active_support/test_case_extensions.rb
activerecord-import-1.0.8 test/support/active_support/test_case_extensions.rb
activerecord-import-1.0.7 test/support/active_support/test_case_extensions.rb
activerecord-import-1.0.6 test/support/active_support/test_case_extensions.rb
activerecord-import-1.0.5 test/support/active_support/test_case_extensions.rb
activerecord-import-1.0.4 test/support/active_support/test_case_extensions.rb
activerecord-import-1.0.3 test/support/active_support/test_case_extensions.rb
activerecord-import-1.0.2 test/support/active_support/test_case_extensions.rb
activerecord-import-1.0.1 test/support/active_support/test_case_extensions.rb
activerecord-import-1.0.0 test/support/active_support/test_case_extensions.rb
activerecord-import-0.28.2 test/support/active_support/test_case_extensions.rb
activerecord-import-0.28.1 test/support/active_support/test_case_extensions.rb
activerecord-import-0.28.0 test/support/active_support/test_case_extensions.rb
activerecord-import-0.27.0 test/support/active_support/test_case_extensions.rb
activerecord-import-0.26.0 test/support/active_support/test_case_extensions.rb
activerecord-import-0.25.0 test/support/active_support/test_case_extensions.rb