Module: MiniTest::Spec::Magic::Context

Included in:
Test::Unit::TestCase
Defined in:
lib/minitest/spec/magic/context.rb

Instance Method Summary collapse

Instance Method Details

#described_typeClass

Returns the test context. Example:

class UserTest < ActiveSupport::TestCase
  self.described_type # => User

  describe "something" do
    self.described_type # => User, here too
  end
end

Returns:

  • (Class)

    the described type



14
15
16
17
18
19
20
# File 'lib/minitest/spec/magic/context.rb', line 14

def described_type
  @described_type ||= begin
    klass = self
    klass = klass.superclass while klass && klass.name !~ /Test$/
    klass.name.sub(/Test$/, '').constantize if klass
  end
end