To tidy up codes, I separated RSpec
tests for concerns
methods to spec/concerns
directory.
I followed this answer. (Copy & Paste from the answer)
# app/models/concerns/personable.rb
module Personable
extend ActiveSupport::Concern
def full_name
"#{first_name} #{last_name}"
end
end
# spec/concerns/personable_spec.rb
require 'spec_helper'
shared_examples_for "personable" do
let(:model) { described_class } # the class that includes the concern
it "has a full name" do
person = FactoryGirl.create(model.to_s.underscore.to_sym, first_name: "Stewart", last_name: "Home")
expect(person.full_name).to eq("Stewart Home")
end
end
# spec/models/master_spec.rb
require 'spec_helper'
describe Master do
it_behaves_like "personable"
end
# spec/models/apprentice_spec.rb
require 'spec_helper'
describe Apprentice do
it_behaves_like "personable"
end
When I edit personable_spec.rb
guard detect the update, but because there is no example in the file it ends up No examples found
.
I have to run all spec to test the personable_spec.rb
. Is there a way to test examples automatically that are defined in shared_examples_for
method?