-
-
Save pdswan/7933755 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Car | |
def initialize(model, engine = ::Engine.new) | |
@model = model | |
@engine = engine | |
end | |
def running | |
engine.running | |
end | |
def start | |
engine.start | |
end | |
private | |
attr_access :model, :engine | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe User do | |
let(:user) { User.new } | |
let(:nasty_external_library) { double(:nasty_external_library) } | |
before do | |
allow(::SomeNastyExternalLibrary).to receive(:new) { nasty_external_library } | |
end | |
describe "#ready_for_launch?" do | |
context "the nasty external library is activated" do | |
before do | |
allow(nasty_external_library).to receive(:activated?) { true } | |
end | |
it "returns true" do | |
expect(user.ready_for_launch?).to be_true | |
end | |
end | |
context "the nasty external library is not activated" do | |
before do | |
allow(nasty_external_library).to receive(:activated?) { false } | |
end | |
it "returns false" do | |
expect(user.ready_for_launch?).to be_false | |
end | |
end | |
end | |
end | |
class User | |
def ready_for_launch? | |
::SomeNastyExternalLibrary.new.activated? | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe Car do | |
let(:car) { Car.new("ford", engine) } | |
let(:engine) { double(:engine) } | |
describe "#start" do | |
it "starts the engine" do | |
expect(engine).to receive(:start) | |
car.start | |
end | |
end | |
describe "#running" do | |
let(:running_status) { double(:running_status) } | |
it "returns the engine running status" do | |
allow(engine).to receive(:running) { running_status } | |
expect(car.running).to eq(running_status) | |
end | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment