Hi all,
I’m working on the Battleship program. I’ve got all the rspec tests passing (woot!). But, I am finding that attempting to extend my code beyond them and have a playable game results in tests failing again. Do I need to care?
To give a better idea of what I am on about, as a basic example my BattleshipGame#play_turn method in the version that passes the tests is
def play_turn
pos = player.get_play(@board)
attack(pos)
# puts "Hit Enter to continue."
# gets
end
In attempting to extend my rspec-passing code to a playable game, I put in the puts and gets lines commented out above as a means to freeze the output. My BattleshipGame#attack method displays some information about the results of the attack and without a gets somewhere it immediately disappeared from the screen. However, if the gets call is uncommented, this causes rspec tests of BattleshipGame#play_turn to fail:
BattleshipGame#play_turn gets a move from the player and makes an attack at that position
Failure/Error: game.play_turn
Errno::EISDIR:
Is a directory @ io_fillbuf - fd:7 spec
# ./lib/battleship.rb:50:in `gets'
# ./lib/battleship.rb:50:in `gets'
# ./lib/battleship.rb:50:in `play_turn'
# ./spec/battleship_spec.rb:51:in `block (3 levels) in <top (required)>'
In the particular case, there are other ways to solve the issue that still result in all rspec tests passing. For instance, I can just move the offending lines into the BattleshipGame#attack method. This might even be better.
But, not all cases of rspec failures caused by extensions that I have made are so easily dealt with. In a couple of cases, it has been a bit difficult. I suspect that the root cause of the difficulty is my having a different organization of the program in mind than the organization that the writer of the rspec tests had in mind. It is also seems that the failing test doesn’t indicate a failure of the logic of my program.
So, my question is: if I got the rspec tests to pass and then my extending the game to a playable game or to the Bonus stages breaks the rsepc tests in ways like this, is that OK? Or, do I need to figure out a way to extend the game which will not result in breaking some tests? I don’t doubt that it can be done without breaking rspec tests, but it isn’t clear to me that the effort to do that is well spent. If I don’t need to care, how do I handle the submission? (Provide a minimal rspec passing version and my extended version?)
Thanks and sorry for the wall’o’text.
Brian