diff --git a/.gitignore b/.gitignore index 61a293a..de633b8 100644 --- a/.gitignore +++ b/.gitignore @@ -21,3 +21,4 @@ doc/ config/database.yml TODO +.idea diff --git a/minitest/navy.rb b/minitest/navy.rb index c672e0a..0ef0115 100644 --- a/minitest/navy.rb +++ b/minitest/navy.rb @@ -1,4 +1,6 @@ class Admiral + attr_reader :battleship + def initialize(battleship) @battleship = battleship end @@ -12,7 +14,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..6c73bbe 100644 --- a/minitest/navy_test.rb +++ b/minitest/navy_test.rb @@ -3,7 +3,6 @@ require "minitest/mock" class TestAdmiral < MiniTest::Unit::TestCase - def setup @battleship = MiniTest::Mock.new @admiral = Admiral.new(@battleship) @@ -14,14 +13,25 @@ def test_can_tell_the_battleship_to_fire @admiral.fire_upon_target @battleship.verify end + + def test_has_battleship + assert_respond_to @admiral, :battleship + end end class TestBattleship< MiniTest::Unit::TestCase + def setup + @battleship = Battleship.new + end + + def test_ammo_count_starts_at_10 + assert_equal 10, @battleship.ammunition + end + def test_will_decrease_ammunition_when_firing - battleship = Battleship.new - starting_ammunition = battleship.ammunition - battleship.fire! - assert_equal (starting_ammunition - 1), battleship.ammunition + starting_ammunition = @battleship.ammunition + @battleship.fire! + assert_equal (starting_ammunition - 1), @battleship.ammunition end end