I think you need two-layer testing:
- device specifications: testing each class in isolation
- integration specifications: testing in general
Given the code as follows:
class Car end class Mechanic def fix(car)
For unit specifications, I would drown out the dependencies, for example:
describe Mechanic do let(:mechanic) { described_class.new } let(:car) { stub(stubbed_method_on_car: 14) }
For integration specifications, I would do the following:
describe Mechanic do let(:mechanic) { FactoryGirl.create(:mechanic) } let(:car) { FactoryGirl.create(:car) } it 'does some stuff' do mechanic.fix(car).should eq true end end
Tomasz wałkuski
source share