|
4 | 4 | let(:game) { Game.create!(name: 'Starship Battle', slug: 'starship-battle') } |
5 | 5 |
|
6 | 6 | describe "GET show" do |
7 | | - context "url is not parameterized" do |
8 | | - before :each do |
9 | | - get URI::encode("/games/#{game.name}") |
10 | | - end |
11 | | - |
12 | | - it { expect(Game.count).to eq(1) } |
13 | | - end |
14 | | - |
15 | 7 | context "player is signed in" do |
16 | 8 | let(:player) { Player.create! } |
17 | 9 |
|
18 | 10 | before :each do |
19 | 11 | allow_any_instance_of(ApplicationController).to receive(:current_player).and_return(player) |
20 | 12 | end |
21 | 13 |
|
| 14 | + context "url is not parameterized" do |
| 15 | + before :each do |
| 16 | + game.update(state: 'awaiting_opponent') |
| 17 | + allow_any_instance_of(ApplicationController).to receive(:current_player).and_return(player) |
| 18 | + get URI::encode("/games/#{game.name}") |
| 19 | + end |
| 20 | + |
| 21 | + it { expect(Game.count).to eq(1) } |
| 22 | + end |
| 23 | + |
22 | 24 | context "game is full" do |
23 | | - before { 2.times { Player.create(game: game) } } |
| 25 | + before :each do |
| 26 | + game.update(state: 'running') |
| 27 | + 2.times { Player.create(game: game) } |
| 28 | + get "/games/#{game.to_param}" |
| 29 | + end |
24 | 30 |
|
25 | | - before { get "/games/#{game.to_param}" } |
26 | 31 |
|
27 | 32 | it { expect(response.body).to include("already full") } |
28 | 33 | it { expect(player.reload.game).to_not eq(game) } |
29 | 34 | end |
30 | 35 |
|
31 | | - context "player joined the game and refresh the page" do |
| 36 | + context "player joined the game and refresh the page" do |
32 | 37 | let!(:opponent) { Player.create(game: game) } |
33 | 38 |
|
34 | 39 | before :each do |
| 40 | + game.update(state: 'running') |
35 | 41 | player.update(game: game) |
36 | 42 |
|
37 | 43 | get "/games/#{game.to_param}" |
|
45 | 51 | let(:other_game) { Game.create!(name: 'Other game', slug: 'other-game') } |
46 | 52 |
|
47 | 53 | before :each do |
| 54 | + other_game.update(state: 'awaiting_opponent') |
48 | 55 | player.update(game: game, nickname: "Rico", life: 3) |
49 | 56 | get "/games/#{other_game.to_param}" |
50 | 57 | end |
|
84 | 91 | end |
85 | 92 |
|
86 | 93 | context "game is already full" do |
87 | | - before { 2.times { Player.create!(game: game) } } |
88 | | - |
89 | | - before { get "/games/#{game.to_param}" } |
| 94 | + before :each do |
| 95 | + game.update(state: 'running') |
| 96 | + 2.times { Player.create!(game: game) } |
| 97 | + get "/games/#{game.to_param}" |
| 98 | + end |
90 | 99 |
|
91 | 100 | it { expect(response).to have_http_status(200) } |
92 | 101 | it { expect(Player.count).to eq(2) } |
|
0 commit comments