require 'rails_helper' RSpec.describe Game, type: :model do before(:each) { @game = Game.new(title: 'Test Game') } 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.players.new @game.players.new 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 @game.validate_startable 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 @game.players.new end @game.validate_startable expect(@game.startable?).to eq(false) expect(@game.errors[:players]) .to include 'Must be less than 5 players.' end end end end #it 'Can not be started if game is invalid' do #expect(@game.start).to raise_error #end end