Guest User

Untitled

a guest
Jan 22nd, 2019
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.48 KB | None | 0 0
  1. class Player
  2.  
  3. attr_reader :boardpiece # i exist so game can read me
  4.  
  5. def initialize(letter)
  6. @boardpiece = letter
  7. end
  8.  
  9. def move_human(game, board)
  10. @game_two = game
  11.  
  12. puts "human move..."
  13.  
  14. human_move = gets.chomp
  15.  
  16. human_symbol = human_move.to_sym
  17.  
  18. # look for move as key in board.grid
  19. if board.grid.has_key?(human_symbol)
  20. if board.grid[human_symbol] == " "
  21. #puts "bingo"
  22. @move = human_symbol
  23. else
  24. puts "spot taken...try again"
  25. move_human(@game_two, board)
  26. end
  27. else
  28. puts "invalid move...try again"
  29. move_human(@game_two, board)
  30. end
  31.  
  32. end
  33. end
  34.  
  35. require 'game'
  36. require 'board'
  37.  
  38. describe Player do
  39. describe 'move_human' do
  40. it 'receives cli input' do
  41. player_h = Player.new('X')
  42. player_c = Player.new('O')
  43. board = Board.new
  44. game = Game.new(player_h, player_c, board)
  45.  
  46. player_h.move_human('X', board).should_receive(:puts).with('human move...')
  47.  
  48. game.play
  49. end
  50. xit 'and returns a move value'
  51.  
  52. end
  53. end
  54.  
  55. gideon@thefonso ~/Documents/ca_ruby/rubytactoe (development)$ rspec spec
  56.  
  57. Board
  58. creates a blank board with nine spaces
  59. can set the value of a specified cell
  60. checks if a space is taken or not
  61. drawgrid
  62. draws a blank grid given no input
  63.  
  64. Player
  65. move_human
  66. human move...
  67. receives cli input (FAILED - 1)
  68. and returns a move value (PENDING: Temporarily disabled with xit)
  69.  
  70. Pending:
  71. Player move_human and returns a move value
  72. # Temporarily disabled with xit
  73. # ./spec/player_spec.rb:16
  74.  
  75. Failures:
  76.  
  77. 1) Player move_human receives cli input
  78. Failure/Error: player_h.move_human('X', board).should_receive(:puts).with('human move...')
  79. Errno::EISDIR:
  80. Is a directory - spec
  81. # ./lib/player.rb:21:in `gets'
  82. # ./lib/player.rb:21:in `gets'
  83. # ./lib/player.rb:21:in `move_human'
  84. # ./spec/player_spec.rb:12:in `block (3 levels) in <top (required)>'
  85.  
  86. Finished in 0.00977 seconds
  87. 6 examples, 1 failure, 1 pending
  88.  
  89. Failed examples:
  90.  
  91. rspec ./spec/player_spec.rb:6 # Player move_human receives cli input
  92. gideon@thefonso ~/Documents/ca_ruby/rubytactoe (development)$
  93.  
  94. # These setup expectations for when "gets" and "puts" are called later...
  95. player_h.stub(:gets).and_return("some input from the user")
  96. player_h.should_receive(:puts).with("human move...")
  97.  
  98. # And then we run the method where those expectations above will get triggered:
  99. player_h.move_human('X', board)
  100.  
  101. player_h.stub(:gets).and_return("Some string")
Add Comment
Please, Sign In to add comment