require 'rails_helper' RSpec.describe Game, type: :model do before(:each) do @game = FactoryGirl.create(:game) @user1 = FactoryGirl.create(:user) @user2 = FactoryGirl.create(:user) end subject { @game } it { should respond_to(:title) } it '#title returns a string' do expect(@game.title).to match 'Test Game' end describe 'validations' do describe 'player_count' do context 'when there are between 2 and 4 players' do it 'is startable' do @game.add_player_from_user(@user1) @game.add_player_from_user(@user2) expect(@game.players.size).to eq(2) expect(@game.startable?).to eq(true) end end context 'when there are less than 2 players' do it 'is not startable with too few players' do expect{@game.validate_startable}.to raise_error StandardError expect(@game.players.size).to eq(0) expect(@game.startable?).to eq(false) expect(@game.errors[:players]) .to include 'Must be at least 2 players.' end end context 'when there are more than 4 players' do it 'fails validation with too many players' do 6.times do @user = FactoryGirl.create(:user) @player = @game.players.new(user_id: @user.id) @player.save end @game.players.new(user_id: User.last.id) expect{@game.validate_startable}.to raise_error StandardError expect(@game.startable?).to eq(false) expect(@game.errors[:players]) .to include 'Must be less than 5 players.' end end end end #when the game starts #the player with the lowest card goes first #it 'Can not be started if game is invalid' do #expect(@game.start).to raise_error #end end