Use expect .should class Proxy < BasicObject def initialize(target) @target = target end def method_missing(*args, &block) @target.__send__(*args, &block) end ... end
Use let let(:email) { ‘[email protected]’ } let(:user) { User.new(email: email) } context ‘when there is no email’ do let(:email) { ‘’ } it ‘is invalid’ do expect(user).to be_invalid end end
Use subject describe User do it ‘has the expected attributes’ do user = User.new expect(user).to respond_to :name expect(user).to respond_to :email expect(user).to respond_to :age end end
Reuse specs shared_examples ‘a collection’ do let(:collection) { described_class.new([7, 2, 4]) } context ‘when initialized with 3 items’ do it ‘says it has three items’ do expect(collection.size).to eq(3) end end end
Use mocks? Mock-based tests are more coupled to the interfaces in your system, while classical tests are more coupled to the implementation of an object’s collaborators. -- Myron Marston