First, self.included not a good way to describe your modules, and class_exec unnecessarily complicates the situation. Instead, you should extend ActiveSupport::Concern , as in:
module Phoneable extend ActiveSupport::Concern included do has_one :phone_number validates_uniqueness_of :phone_number end end
You did not specify which test framework you are using, but RSpec covers exactly this case. Try the following:
shared_examples_for "a Phoneable" do it "should have a phone number" do subject.should respond_to :phone_number end end
Assuming your models look like this:
class Person class Business include Phoneable include Phoneable end end
Then in your tests you can:
describe Person do it_behaves_like "a Phoneable"
source share