From d28726cdf441651bbc65f3509a8aad333bef2aeb Mon Sep 17 00:00:00 2001 From: Adam Lowe Date: Sun, 2 Mar 2014 11:46:47 -0800 Subject: [PATCH 1/3] Assert that Admiral has Battleship & changed starting ammo to 10 --- minitest/minitest/navy.rb | 22 +++++++++++++++ minitest/minitest/navy_test.rb | 49 ++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 minitest/minitest/navy.rb create mode 100644 minitest/minitest/navy_test.rb diff --git a/minitest/minitest/navy.rb b/minitest/minitest/navy.rb new file mode 100644 index 0000000..e1ffa24 --- /dev/null +++ b/minitest/minitest/navy.rb @@ -0,0 +1,22 @@ +class Admiral + attr_reader :battleship + def initialize(battleship) + @battleship = battleship + end + + def fire_upon_target + @battleship.fire! + end + +end + +class Battleship + attr_reader :ammunition + def initialize + @ammunition = 10 + end + + def fire! + @ammunition = @ammunition - 1 + end +end diff --git a/minitest/minitest/navy_test.rb b/minitest/minitest/navy_test.rb new file mode 100644 index 0000000..e4f4d79 --- /dev/null +++ b/minitest/minitest/navy_test.rb @@ -0,0 +1,49 @@ +require_relative "navy" +require "minitest/autorun" +require "minitest/mock" + +class TestAdmiral < MiniTest::Unit::TestCase + + def setup + @battleship = MiniTest::Mock.new + @admiral = Admiral.new(@battleship) + end + + def test_can_tell_the_battleship_to_fire + @battleship.expect :fire!, nil + @admiral.fire_upon_target + @battleship.verify + end +end + +class TestBattleship< MiniTest::Unit::TestCase + def test_will_decrease_ammunition_when_firing + battleship = Battleship.new + starting_ammunition = battleship.ammunition + battleship.fire! + assert_equal (starting_ammunition - 1), battleship.ammunition + end +end + +describe Battleship do + it "should decrease ammo" do + battleship = Battleship.new + starting_ammunition = battleship.ammunition + battleship.fire! + battleship.ammunition.must_equal (starting_ammunition -1) + end + + it "should have starting ammo of 10" do + battleship = Battleship.new + starting_ammunition = battleship.ammunition + starting_ammunition.must_equal (10) + end +end + +describe Admiral do + it "should have a battleship" do + battleship = Battleship.new + admiral = Admiral.new(battleship) + assert (1), admiral.battleship + end +end From b560e31c941377f34856315f6b18ebdfe5bece92 Mon Sep 17 00:00:00 2001 From: Adam Lowe Date: Sun, 2 Mar 2014 12:03:06 -0800 Subject: [PATCH 2/3] Assert that Admiral has Battleship & changed starting ammo to 10 --- minitest/navy.rb | 3 ++- minitest/navy_test.rb | 12 ++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/minitest/navy.rb b/minitest/navy.rb index c672e0a..e1ffa24 100644 --- a/minitest/navy.rb +++ b/minitest/navy.rb @@ -1,4 +1,5 @@ class Admiral + attr_reader :battleship def initialize(battleship) @battleship = battleship end @@ -12,7 +13,7 @@ def fire_upon_target class Battleship attr_reader :ammunition def initialize - @ammunition = 100 + @ammunition = 10 end def fire! diff --git a/minitest/navy_test.rb b/minitest/navy_test.rb index de35ec0..2f805b0 100644 --- a/minitest/navy_test.rb +++ b/minitest/navy_test.rb @@ -32,4 +32,16 @@ def test_will_decrease_ammunition_when_firing battleship.fire! battleship.ammunition.must_equal (starting_ammunition -1) end + it "should have starting ammo of 10" do + battleship = Battleship.new + battleship.ammunition.must_equal (10) + end +end + +describe Admiral do + it "should have a battleship" do + battleship = Battleship.new + admiral = Admiral.new(battleship) + assert (true), admiral.battleship + end end From 04edf781e7fbf87a90f895f85bd49c5dd18b3cf0 Mon Sep 17 00:00:00 2001 From: Adam Lowe Date: Tue, 4 Mar 2014 11:58:46 -0800 Subject: [PATCH 3/3] Updated navy_test --- minitest/navy_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/minitest/navy_test.rb b/minitest/navy_test.rb index 2f805b0..b4bcaa3 100644 --- a/minitest/navy_test.rb +++ b/minitest/navy_test.rb @@ -42,6 +42,6 @@ def test_will_decrease_ammunition_when_firing it "should have a battleship" do battleship = Battleship.new admiral = Admiral.new(battleship) - assert (true), admiral.battleship + assert_equal (battleship), admiral.battleship end end