2: Too much happening class User def watch(video) ... video.watched_by(self) end end class Video def watched_by(user) ... end end Thursday, 26 September 13
it may break class User def watch(video) ... video.watched_by(self) end end class Video def seen_by(user) ... end end Test still passes! Thursday, 26 September 13
let(:video) { double.as_null_object } it { user.watch(video) ... 1 example, 0 failures still passes class Video def seen_by(user) ... end end Thursday, 26 September 13
`watched_by' it breaks Bogus Fakes class Video def seen_by(person) ... end end fake(:video) { Video } it { user.watch(video) ... Thursday, 26 September 13
(args) class User def watch(video) ... video.watched_by(self, args) end end class Video def watched_by(user) ... end end fake(:video) { Video } it { user.watch(video) ... Thursday, 26 September 13
.and_return(14.minutes) end it { user.watch(video) expect(user.busy_for).to eq(14.minutes) 1 example, 0 failures passes even if video.time doesn’t exist class User ... def busy_for current_video.time end ... end class Video def duration ... end Thursday, 26 September 13
14.minutes } end it { user.watch(video) expect(user.busy_for).to eq(14.minutes) } <Video:0x8051f2cc> does not respond to time This is what we want class User ... def busy_for current_video.time end ... end class Video def duration ... end Thursday, 26 September 13
{ Video } before do stub(video) .time(any_args){ 14.minutes } end it { user.watch(video) expect(user.busy_for).to eq(14.minutes) } class User ... def busy_for current_video.time end ... end class Video def time(args) ... end Thursday, 26 September 13
expect(video).to have_received(watched_by) } 1 example, 0 failures class User ... def watch(video) ... video.watched_by(self) end ... class Video def seen_by(person) ... end end Thursday, 26 September 13
} <Video:0x8051f2cc> does not respond to watched_by class User ... def watch(video) ... video.watched_by(self) end ... class Video def seen_by(person) ... end end Thursday, 26 September 13