This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class MockSession | |
| def initialize(cookies) | |
| @cookies = cookies | |
| @data = cookies['rack.session'] ## Gets session hash as base64 encoded marshalled data set | |
| if @data | |
| @data = @data.unpack("m*").first ### Decodes data as string | |
| @data = Marshal.load(@data) ### Converts serialized data into a Ruby hash | |
| else | |
| @data = {} | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'spec_helper' | |
| describe 'AppController', :type => :feature do | |
| include GameHelpers | |
| before :each do | |
| def session # Creates new rack mock session object | |
| MockSession.new(rack_mock_session.cookie_jar) # (from mixin) Creates rack mock session object, Assigns new session to Cookie Jar object | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'ruby_ttt' | |
| module GameHelpers | |
| include RubyTictactoe::TictactoeConstants | |
| def get_game | |
| settings = get_settings | |
| WebGame.new(settings) | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| get '/' do | |
| session.clear | |
| erb :index | |
| end | |
| get '/play' do | |
| redirect '/' if session[:player_one_type].nil? | |
| player_first_move_check | |
| game = get_game | |
| @board = game.board |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'sinatra' | |
| require "sinatra/base" | |
| require 'rack/test' | |
| require 'ruby_ttt' | |
| require 'web_board' | |
| require 'web_game' | |
| require 'web_game_setup' | |
| require './game_helpers.rb' | |
| require './app.rb' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'spec_helper' | |
| describe 'AppController' do | |
| describe "GET '/'" do | |
| it "loads homepage" do | |
| get '/' | |
| expect(last_response).to be_ok | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.io.OutputStream; | |
| import java.io.PrintStream; | |
| import java.util.ArrayList; | |
| public class MockPrintStream extends PrintStream { | |
| public ArrayList<String> printCallHistory; | |
| public void setPrintCallHistory(ArrayList<String> printCallHistory) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.io.IOException; | |
| import java.io.OutputStream; | |
| import java.util.ArrayList; | |
| public class MockOutputStream extends OutputStream { | |
| @Override | |
| public void write(int i) throws IOException { | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.io.BufferedReader; | |
| import java.io.Reader; | |
| import java.util.ArrayList; | |
| import java.io.InputStreamReader; | |
| import java.io.IOException; | |
| public class MockBufferedReader extends BufferedReader { | |
| public ArrayList<String> inputHistory; | |
| public void setInputHistory(ArrayList<String> inputHistory) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class CLIBoardTest { | |
| private CLIBoard cliBoard; | |
| private MockPrintStream printStream; | |
| @Before | |
| public void setUp() throws Exception { | |
| MockOutputStream outputStream = new MockOutputStream(); | |
| printStream = new MockPrintStream(outputStream); | |
| printStream.setPrintCallHistory(new ArrayList<String>()); | |
| cliBoard = new CLIBoard(printStream); |