|
1 | 1 | require "rails_helper" |
2 | 2 |
|
3 | 3 | RSpec.describe "Attacks", type: :request do |
4 | | - let(:game) { Game.create!(name: 'Starship Battle') } |
| 4 | + let(:game) { Game.create!(name: 'Starship Battle', state: 'running') } |
5 | 5 | let(:player) { game.players.create!(nickname: "Rico") } |
6 | 6 |
|
7 | 7 | before :each do |
|
54 | 54 |
|
55 | 55 | context 'when provided word has already been played with a different case' do |
56 | 56 | before :each do |
| 57 | + allow_words("battletype") |
57 | 58 | game.words.create!(value: 'BattleType') |
58 | 59 | end |
59 | 60 |
|
|
65 | 66 | it 'broadcasts an error message' do |
66 | 67 | allow(ActionCable.server).to receive(:broadcast) |
67 | 68 | post "/attacks", params: { word: 'battletype' } |
68 | | - expect(ActionCable.server).to have_received(:broadcast).with(anything, code: 'failed_attack', player_id: player.id, word: 'battletype', error_codes: ["unique_case_insensitive_word", "english_word"]) |
| 69 | + expect(ActionCable.server).to have_received(:broadcast).with(anything, code: 'failed_attack', player_id: player.id, word: 'battletype', error_codes: ["unique_case_insensitive_word"]) |
| 70 | + end |
| 71 | + end |
| 72 | + |
| 73 | + context 'when game is finished' do |
| 74 | + before :each do |
| 75 | + allow_words("finished") |
| 76 | + game.update(state: 'finished') |
| 77 | + end |
| 78 | + |
| 79 | + it 'returns 200 HTTP status' do |
| 80 | + post "/attacks", params: { word: 'finished' } |
| 81 | + expect(response).to have_http_status(200) |
| 82 | + end |
| 83 | + |
| 84 | + it 'broadcasts an error message' do |
| 85 | + allow(ActionCable.server).to receive(:broadcast) |
| 86 | + post "/attacks", params: { word: 'finished' } |
| 87 | + expect(ActionCable.server).to have_received(:broadcast).with(anything, code: 'failed_attack', word: 'finished', player_id: player.id, error_codes: ['not_running'] ) |
69 | 88 | end |
70 | 89 | end |
71 | 90 | end |
|
0 commit comments