title: Rails & Rspec: testing model with methods defined via module extending ActiveSupport::Concern
body: <p>I have a module that defines a class method to dynamically define a series of instance methods based on values in given columns, roughly as follows:</p>
  
  <p><strong>lib/active_record_extension.rb</strong></p>
  
  <pre><code>module ActiveRecordExtension
    extend ActiveSupport::Concern
  
    module ClassMethods
      def define_some_methods(*attribute_names)
        # define some methods
      end
    end
  end
  
  ActiveRecord::Base.send(:include, ActiveRecordExtension)
  </code></pre>
  
  <p><strong>config/initializers/extensions.rb</strong></p>
  
  <pre><code>require 'active_record_extension.rb'
  </code></pre>
  
  <p><strong>app/models/my_model.rb</strong></p>
  
  <pre><code>class MyModel &lt; ActiveRecord::Base
    define_some_methods :first_attribute, :second_attribute
  end
  </code></pre>
  
  <p>This setup for adding a class method to ActiveRecord::Base is based on the first answer to <a href="https://stackoverflow.com/questions/2328984/rails-extending-activerecordbase">this question</a>.</p>
  
  <p>This works beautifully in my Rails app and console, allowing me to define a variety of similar methods without cluttering up my model. However, it doesn't work at all in my rspec tests, which now all fail with <code>NoMethodError</code>s for calls to the dynamically defined methods.</p>
  
  <p>How can I be sure this module (or just this method) is correctly included in my models while running rspec?</p>
  
  <p>EDIT: Here is my <strong>spec/spec_helper.rb</strong>:</p>
  
  <pre><code>ENV["RAILS_ENV"] ||= 'test'
  require File.expand_path("../../config/environment", __FILE__)
  require 'rspec/rails'
  require 'rspec/autorun'
  
  #to test with sunspot
  require 'sunspot/rails/spec_helper'
  RSpec.configure do |config|
    ::Sunspot.session = ::Sunspot::Rails::StubSessionProxy.new(::Sunspot.session)
  end
  
  #adds devise and jasmine fixture test helpers
  Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
  
  RSpec.configure do |config|
    config.fixture_path = "#{::Rails.root}/spec/fixtures"
    config.use_transactional_fixtures = true
    config.infer_base_class_for_anonymous_controllers = false
    config.order = "random"
  end
  </code></pre>