require File.join(File.dirname(__FILE__), 'test_helper') class MissingConstantTest < ActiveSupport::TestCase context "MissingConstant" do should "not have the constant by default" do assert ::UserProfile end context "define the base" do setup do class ::Object class << self def profile(&block) define_class("::#{self.name}Profile", "::Profile") do attr_accessor :profile def profile @profile ||= {} end end end end end class ::Profile end end should "have defined the profile" do end context "define the meat" do setup do class ::User profile end end should "have defined the constant now" do assert ::UserProfile end end end context "DSL" do setup do DefinedBy::MissingConstants() do match %r{\w+(Profile)$}, "\\1" end end should "define the dsl" do assert_equal 1, DefinedBy::MissingConstant::Definition.definitions.length assert_equal :Profile, DefinedBy::MissingConstant::Definition.for(:UserProfile) end end end end