Sha256: 103f24e37804fa551b5e3f9b71f5c42852d48c9e40b9d6c3dca0f015758694c5

Contents?: true

Size: 1.09 KB

Versions: 48

Compression:

Stored size: 1.09 KB

Contents

module ClassBuilder
  def self.included(example_group)
    example_group.class_eval do
      after do
        teardown_defined_constants
      end
    end
  end

  def define_class(class_name, base = Object, &block)
    class_name = class_name.to_s.camelize

    # FIXME: ActionMailer 3.2 calls `name.underscore` immediately upon
    # subclassing. Class.new.name == nil. So, Class.new(ActionMailer::Base)
    # errors out since it's trying to do `nil.underscore`. This is very ugly but
    # allows us to test against ActionMailer 3.2.x.
    eval <<-A_REAL_CLASS_FOR_ACTION_MAILER_3_2
    class ::#{class_name} < #{base}
    end
    A_REAL_CLASS_FOR_ACTION_MAILER_3_2

    Object.const_get(class_name).tap do |constant_class|
      constant_class.unloadable

      if block_given?
        constant_class.class_eval(&block)
      end

      if constant_class.respond_to?(:reset_column_information)
        constant_class.reset_column_information
      end
    end
  end

  def teardown_defined_constants
    ActiveSupport::Dependencies.clear
  end
end

RSpec.configure do |config|
  config.include ClassBuilder
end

Version data entries

48 entries across 42 versions & 6 rubygems

Version Path
challah-1.0.0.beta2 vendor/bundle/gems/shoulda-matchers-1.5.6/spec/support/class_builder.rb
challah-1.0.0.beta vendor/bundle/gems/shoulda-matchers-1.5.6/spec/support/class_builder.rb
challah-1.0.0.beta vendor/bundle/gems/shoulda-matchers-1.4.2/spec/support/class_builder.rb
shoulda-matchers-2.0.0 spec/support/class_builder.rb
shoulda-matchers-1.5.6 spec/support/class_builder.rb
shoulda-matchers-1.5.5 spec/support/class_builder.rb
shoulda-matchers-1.5.4 spec/support/class_builder.rb
shoulda-matchers-1.5.2 spec/support/class_builder.rb
shoulda-matchers-1.5.1 spec/support/class_builder.rb
shoulda-matchers-1.5.0 spec/support/class_builder.rb
challah-0.9.1.beta.3 vendor/bundle/gems/shoulda-matchers-1.4.2/spec/support/class_builder.rb
devise_sociable-0.1.0 vendor/bundle/gems/shoulda-matchers-1.4.2/spec/support/class_builder.rb
challah-0.9.1.beta vendor/bundle/gems/shoulda-matchers-1.4.2/spec/support/class_builder.rb
challah-0.9.0 vendor/bundle/gems/shoulda-matchers-1.4.2/spec/support/class_builder.rb
shoulda-callback-matchers-0.2.0 spec/support/class_builder.rb
shoulda-matchers-1.4.2 spec/support/class_builder.rb
shoulda-callback-matchers-0.1.0 spec/support/class_builder.rb
challah-rolls-0.2.0 vendor/bundle/gems/shoulda-matchers-1.4.1/spec/support/class_builder.rb
challah-rolls-0.2.0 vendor/bundle/gems/challah-0.8.3/vendor/bundle/gems/shoulda-matchers-1.3.0/spec/support/class_builder.rb
challah-rolls-0.2.0 vendor/bundle/gems/challah-0.8.3/vendor/bundle/gems/shoulda-matchers-1.4.1/spec/support/class_builder.rb