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 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..b4bcaa3 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_equal (battleship), admiral.battleship + end end