48 lines
1.2 KiB
Ruby

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 valid' do
@game.players.new
@game.players.new
expect(@game).to be_valid
end
end
context 'when there are less than 2 players' do
it 'fails validation with too few players' do
expect(@game).to_not be_valid
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
5.times do
@game.players.new
end
expect(@game).to_not be_valid
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 eq false
end
end