I am trying to build my Rspec testing test to test out a ruby app I am building. I know I should build first but test later. The code does work 100% I am just having issues getting Rspec to even look at my code.
The full code on github: https://github.com/EsdrasEtrenne/tictactoe
The only file that im running with rspec so far is ruby/spec/game_spec.rb
the game_spec.rb file looks like this:
require_relative "../tictactoe"
Rspec.describe Tasks do
before(:each)do
@game = Tictactoe::Game.new
end
it "has a working method called play" do
expect{@game.play}.to output("WELCOME! To the unbeatable Tic-tac-toe").to_stdout
end
end
It requires tictactoe as a relative:
require "./components/tasks.rb"
require "./components/board.rb"
require "./components/player.rb"
require "./components/player_types/computer.rb"
require "./components/player_types/human.rb"
module Tictactoe
class Game
attr_reader :board, :player, :opponent, :tasks
def initialize
@board = Board.new
@tasks = Tasks.new
end
def play
@tasks.greet_players
@player, @opponent = @tasks.get_order
current_player, current_opponent = @player, @opponent
@tasks.print_board(@board)
until @board.game_is_over || @board.tie
@tasks.tell_turn(current_player)
current_player.move(@board)
@tasks.print_board(@board)
if @board.game_is_over || @board.tie
@tasks.game_over(@board)
if @tasks.end_options
game = Tictactoe::Game.new
game.play
end
else
current_player, current_opponent = current_opponent, current_player
end
end
end
end
end
game = Tictactoe::Game.new
game.play
Then I get this error when I run rspec game_spec.rb:
An error occurred while loading ./game_spec.rb.
Failure/Error: return gem_original_require(path)
LoadError:
cannot load such file -- ./components/tasks.rb
# /Users/Esdras/Desktop/first_vagrant_box/coding_challenges/ruby/tictactoe.rb:1:in `<top (required)>'
# ./game_spec.rb:1:in `require_relative'
# ./game_spec.rb:1:in `<top (required)>'
No examples found.
Finished in 0.00028 seconds (files took 0.08732 seconds to load)
0 examples, 0 failures, 1 error occurred outside of examples
The game works 100% regularly. I just am looking to make the first test pass and from there the rest should be really straight forward.