make a test pass - more of a test than is sufficient to fail - more code than is sufficient to pass the test BOB MARTIN picture source: http://agile2012.agilealliance.org
height**2).round 1 end end describe Player do context "#body_mass_index" do it "calculates the bmi" do lebron = Player.new 2.03, 113 lebron.body_mass_index.should eq 27.4 end end end object test
@skill = skill_level end end describe Player do context "#skill=" do it "updates the skill level" do player.skill = 10 player.skill.should eq 10 end end end object test
do lebron = Player.new 2.03, 113 lebron.should_receive(:actual_bmi).and_call_original lebron.body_mass_index.should eq 27.4 end end end test Over specification: no safety and breaks on every change
do it "finds if player is on the team" do team = Team.new team.add_player player player.should be_on_the_team team team.players.should include player end end end
player is on the team" do team = Team.new team.add_player player team.should_receive (:has_player?).and_call_original player.should be_on_the_team team end end end
do context "#on_the_team?" do it "finds if player is on the team" do team = Team.new team.add_player player team.should_receive (:has_player?).and_call_original player.should be_on_the_team team end end end
self end end describe Player do context "#infiltrate_team" do it "adds player to team" do team = Team.new player.infiltrate_team team team.players.should include player end end end test
self end end describe Player do context "#infiltrate_team" do it "adds player to team" do team = Team.new player.infiltrate_team team team.players.should include player end end end test depends on distant side effect
self end end describe Player do context "#infiltrate_team" do it "adds player to team" do team = Team.new player.infiltrate_team team team.players.should include player end end end test not the player’s responsibility
self end end describe Player do context "#infiltrate_team" do it "adds player to team" do team = Team.new team.should_receive(:add_player) player.infiltrate_team team end end end test this message must be sent
self end end describe Player do context "#infiltrate_team" do it "adds player to team" do team = Team.new team.should_receive(:add_player) player.infiltrate_team team end end end test this message must be sent depends on the interface
object class Player < Struct.new :height, :weight def infiltrate_team(team) team.add_player self end end describe Player do context "#infiltrate_team" do it "adds player to team" do team = Team.new team.should_receive(:add_player) player.infiltrate_team team end end end test this message must be sent