Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ doc/

config/database.yml
TODO
.idea
4 changes: 3 additions & 1 deletion minitest/navy.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
class Admiral
attr_reader :battleship

def initialize(battleship)
@battleship = battleship
end
Expand All @@ -12,7 +14,7 @@ def fire_upon_target
class Battleship
attr_reader :ammunition
def initialize
@ammunition = 100
@ammunition = 10
end

def fire!
Expand Down
20 changes: 15 additions & 5 deletions minitest/navy_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
require "minitest/mock"

class TestAdmiral < MiniTest::Unit::TestCase

def setup
@battleship = MiniTest::Mock.new
@admiral = Admiral.new(@battleship)
Expand All @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the respond_to test here. It doesn't actually test that the battleship IS something though ... So maybe something like:


def test_has_battleship
  battleship = Object.new
  admiral = Admiral.new(battleship)
  assert_equal battleship, admiral.battleship
end

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

Expand Down