triviacrack 0.6.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ci.yml +7 -2
  3. data/.github/workflows/publish.yml +8 -3
  4. data/.rubocop.yml +23 -0
  5. data/.ruby-version +1 -1
  6. data/Gemfile +1 -2
  7. data/Gemfile.lock +31 -10
  8. data/Rakefile +4 -2
  9. data/lib/triviacrack/api/client.rb +7 -7
  10. data/lib/triviacrack/api/common.rb +10 -11
  11. data/lib/triviacrack/api/game.rb +11 -13
  12. data/lib/triviacrack/api/login.rb +7 -8
  13. data/lib/triviacrack/api/profile.rb +4 -4
  14. data/lib/triviacrack/api/question.rb +14 -15
  15. data/lib/triviacrack/api/user.rb +9 -11
  16. data/lib/triviacrack/category_statistics.rb +2 -2
  17. data/lib/triviacrack/errors/parse_error.rb +2 -0
  18. data/lib/triviacrack/errors/request_error.rb +5 -3
  19. data/lib/triviacrack/game.rb +3 -3
  20. data/lib/triviacrack/game_statistics.rb +3 -3
  21. data/lib/triviacrack/parsers/category_statistics_parser.rb +13 -15
  22. data/lib/triviacrack/parsers/game_parser.rb +39 -39
  23. data/lib/triviacrack/parsers/game_statistics_parser.rb +15 -15
  24. data/lib/triviacrack/parsers/profile_parser.rb +28 -28
  25. data/lib/triviacrack/parsers/question_parser.rb +11 -11
  26. data/lib/triviacrack/parsers/session_parser.rb +10 -10
  27. data/lib/triviacrack/parsers/time_parser.rb +4 -4
  28. data/lib/triviacrack/parsers/user_parser.rb +21 -21
  29. data/lib/triviacrack/profile.rb +3 -3
  30. data/lib/triviacrack/question.rb +3 -3
  31. data/lib/triviacrack/session.rb +2 -2
  32. data/lib/triviacrack/user.rb +3 -3
  33. data/lib/triviacrack/version.rb +3 -1
  34. data/lib/triviacrack.rb +12 -10
  35. data/spec/api/game_spec.rb +49 -29
  36. data/spec/api/login_spec.rb +22 -15
  37. data/spec/api/profile_spec.rb +34 -20
  38. data/spec/api/question_spec.rb +49 -30
  39. data/spec/api/user_spec.rb +31 -20
  40. data/spec/game_spec.rb +4 -4
  41. data/spec/parsers/category_statistics_parser_spec.rb +8 -8
  42. data/spec/parsers/game_parser_spec.rb +21 -19
  43. data/spec/parsers/game_statistics_parser_spec.rb +11 -11
  44. data/spec/parsers/profile_parser_spec.rb +10 -10
  45. data/spec/parsers/question_parser_spec.rb +15 -11
  46. data/spec/parsers/session_parser_spec.rb +8 -8
  47. data/spec/parsers/time_parser_spec.rb +5 -5
  48. data/spec/parsers/user_parser_spec.rb +11 -11
  49. data/spec/spec_helper.rb +30 -32
  50. data/spec/user_spec.rb +4 -4
  51. data/triviacrack.gemspec +21 -20
  52. metadata +32 -45
@@ -1,8 +1,9 @@
1
- require "spec_helper"
1
+ # frozen_string_literal: true
2
2
 
3
- describe TriviaCrack::API::Game do
3
+ require 'spec_helper'
4
4
 
5
- let(:session) { TriviaCrack::Session.new session_id: "session", user_id: 1 }
5
+ describe TriviaCrack::API::Game do
6
+ let(:session) { TriviaCrack::Session.new session_id: 'session', user_id: 1 }
6
7
  let(:client) { (Class.new(APIStub) { include TriviaCrack::API::Game }).new session }
7
8
 
8
9
  let(:response) { double(status: code, body: raw_data) }
@@ -10,76 +11,95 @@ describe TriviaCrack::API::Game do
10
11
  before { allow(Faraday).to receive(:get) { response } }
11
12
  before { allow(Faraday).to receive(:post) { response } }
12
13
 
13
- describe "#get_games" do
14
-
14
+ describe '#get_games' do
15
15
  subject { client.get_games[3] }
16
16
 
17
- let(:raw_data) { SpecData.get "dashboard.json" }
17
+ let(:raw_data) { SpecData.get 'dashboard.json' }
18
18
 
19
19
  context 'given that the request is successful' do
20
20
  let(:code) { 200 }
21
21
 
22
- it { expect(TriviaCrack::Parsers::GameParser).to receive(:parse).at_least 1; subject }
22
+ it {
23
+ expect(TriviaCrack::Parsers::GameParser).to receive(:parse).at_least 1
24
+ subject
25
+ }
23
26
  it { is_expected.to be_a TriviaCrack::Game }
24
27
  end
25
28
 
26
29
  context 'given that the request fails' do
27
30
  let(:code) { 400 }
28
31
 
29
- it { expect{ subject }.to raise_error TriviaCrack::Errors::RequestError }
30
- it { expect{ subject }.to raise_error(an_instance_of(TriviaCrack::Errors::RequestError)
31
- .and having_attributes(code: 400)) }
32
- it { expect{ subject }.to raise_error(an_instance_of(TriviaCrack::Errors::RequestError)
33
- .and having_attributes(url: "/api/users/#{session.user_id}/dashboard")) }
32
+ it { expect { subject }.to raise_error TriviaCrack::Errors::RequestError }
33
+ it {
34
+ expect { subject }.to raise_error(an_instance_of(TriviaCrack::Errors::RequestError)
35
+ .and(having_attributes(code: 400)))
36
+ }
37
+ it {
38
+ expect { subject }.to raise_error(an_instance_of(TriviaCrack::Errors::RequestError)
39
+ .and(having_attributes(url: "/api/users/#{session.user_id}/dashboard")))
40
+ }
34
41
  end
35
42
  end
36
43
 
37
- describe "#get_game" do
44
+ describe '#get_game' do
38
45
  let(:game_id) { 123 }
39
46
 
40
47
  subject { client.get_game game_id }
41
48
 
42
- let(:raw_data) { SpecData.get "game.json" }
49
+ let(:raw_data) { SpecData.get 'game.json' }
43
50
 
44
51
  context 'given that the request is successful' do
45
52
  let(:code) { 200 }
46
53
 
47
- it { expect(TriviaCrack::Parsers::GameParser).to receive(:parse).once; subject }
54
+ it {
55
+ expect(TriviaCrack::Parsers::GameParser).to receive(:parse).once
56
+ subject
57
+ }
48
58
  it { is_expected.to be_a TriviaCrack::Game }
49
59
  end
50
60
 
51
61
  context 'given that the request fails' do
52
62
  let(:code) { 400 }
53
63
 
54
- it { expect{ subject }.to raise_error TriviaCrack::Errors::RequestError }
55
- it { expect{ subject }.to raise_error(an_instance_of(TriviaCrack::Errors::RequestError)
56
- .and having_attributes(code: code)) }
57
- it { expect{ subject }.to raise_error(an_instance_of(TriviaCrack::Errors::RequestError)
58
- .and having_attributes(url: "/api/users/#{session.user_id}/games/#{game_id}")) }
64
+ it { expect { subject }.to raise_error TriviaCrack::Errors::RequestError }
65
+ it {
66
+ expect { subject }.to raise_error(an_instance_of(TriviaCrack::Errors::RequestError)
67
+ .and(having_attributes(code: code)))
68
+ }
69
+ it {
70
+ expect { subject }.to raise_error(an_instance_of(TriviaCrack::Errors::RequestError)
71
+ .and(having_attributes(url: "/api/users/#{session.user_id}/games/#{game_id}")))
72
+ }
59
73
  end
60
74
  end
61
75
 
62
- describe "#start_new_game" do
63
-
76
+ describe '#start_new_game' do
64
77
  subject { client.start_new_game }
65
78
 
66
- let(:raw_data) { SpecData.get "new_game.json" }
79
+ let(:raw_data) { SpecData.get 'new_game.json' }
67
80
 
68
81
  context 'given that the request is successful' do
69
82
  let(:code) { 201 }
70
83
 
71
- it { expect(TriviaCrack::Parsers::GameParser).to receive(:parse).once; subject }
84
+ it {
85
+ expect(TriviaCrack::Parsers::GameParser).to receive(:parse).once
86
+ subject
87
+ }
72
88
  it { is_expected.to be_a TriviaCrack::Game }
73
89
  end
74
90
 
75
91
  context 'given that the request fails' do
76
92
  let(:code) { 400 }
77
93
 
78
- it { expect{ subject }.to raise_error TriviaCrack::Errors::RequestError }
79
- it { expect{ subject }.to raise_error(an_instance_of(TriviaCrack::Errors::RequestError)
80
- .and having_attributes(code: code)) }
81
- it { expect{ subject }.to raise_error(an_instance_of(TriviaCrack::Errors::RequestError)
82
- .and having_attributes(url: "/api/users/#{session.user_id}/games")) }
94
+ it { expect { subject }.to raise_error TriviaCrack::Errors::RequestError }
95
+ it {
96
+ expect { subject }.to raise_error(an_instance_of(TriviaCrack::Errors::RequestError)
97
+ .and(having_attributes(code: code)))
98
+ }
99
+ it {
100
+ expect { subject }.to raise_error(an_instance_of(TriviaCrack::Errors::RequestError)
101
+ .and(having_attributes(url: "/api/users/#{session.user_id}/games")))
102
+ }
83
103
  end
84
104
  end
85
105
  end
@@ -1,38 +1,45 @@
1
- require "spec_helper"
1
+ # frozen_string_literal: true
2
2
 
3
- describe TriviaCrack::API::Login do
3
+ require 'spec_helper'
4
4
 
5
+ describe TriviaCrack::API::Login do
5
6
  let(:client) { (Class.new(APIStub) { include TriviaCrack::API::Login }).new }
6
7
 
7
8
  let(:response) { double(status: code, body: raw_data) }
8
9
 
9
10
  before { allow(Faraday).to receive(:post) { response } }
10
11
 
11
- describe "#login" do
12
-
12
+ describe '#login' do
13
13
  subject { client.login email, password }
14
14
 
15
- let(:email) { "user@example.com" }
16
- let(:password) { "password123" }
17
- let(:raw_data) { SpecData.get "login.json" }
15
+ let(:email) { 'user@example.com' }
16
+ let(:password) { 'password123' }
17
+ let(:raw_data) { SpecData.get 'login.json' }
18
18
 
19
19
  context 'given that the request is successful' do
20
20
  let(:code) { 200 }
21
21
 
22
- it { expect(TriviaCrack::Parsers::SessionParser).to receive(:parse).once; subject }
22
+ it {
23
+ expect(TriviaCrack::Parsers::SessionParser).to receive(:parse).once
24
+ subject
25
+ }
23
26
  its(:user_id) { is_expected.to be 111 }
24
- its(:username) { is_expected.to eq "example" }
25
- its(:session_id) { is_expected.to eq "session123" }
27
+ its(:username) { is_expected.to eq 'example' }
28
+ its(:session_id) { is_expected.to eq 'session123' }
26
29
  end
27
30
 
28
31
  context 'given that the request fails' do
29
32
  let(:code) { 400 }
30
33
 
31
- it { expect{ subject }.to raise_error TriviaCrack::Errors::RequestError }
32
- it { expect{ subject }.to raise_error(an_instance_of(TriviaCrack::Errors::RequestError)
33
- .and having_attributes(code: code)) }
34
- it { expect{ subject }.to raise_error(an_instance_of(TriviaCrack::Errors::RequestError)
35
- .and having_attributes(url: '/api/login')) }
34
+ it { expect { subject }.to raise_error TriviaCrack::Errors::RequestError }
35
+ it {
36
+ expect { subject }.to raise_error(an_instance_of(TriviaCrack::Errors::RequestError)
37
+ .and(having_attributes(code: code)))
38
+ }
39
+ it {
40
+ expect { subject }.to raise_error(an_instance_of(TriviaCrack::Errors::RequestError)
41
+ .and(having_attributes(url: '/api/login')))
42
+ }
36
43
  end
37
44
  end
38
45
  end
@@ -1,60 +1,74 @@
1
- require "spec_helper"
1
+ # frozen_string_literal: true
2
2
 
3
- describe TriviaCrack::API::Profile do
3
+ require 'spec_helper'
4
4
 
5
- let(:session) { TriviaCrack::Session.new session_id: "session", user_id: 1 }
5
+ describe TriviaCrack::API::Profile do
6
+ let(:session) { TriviaCrack::Session.new session_id: 'session', user_id: 1 }
6
7
  let(:client) { (Class.new(APIStub) { include TriviaCrack::API::Profile }).new session }
7
8
 
8
9
  let(:response) { double(status: code, body: raw_data) }
9
10
 
10
11
  before { allow(Faraday).to receive(:get) { response } }
11
12
 
12
- describe "#get_profile" do
13
+ describe '#get_profile' do
13
14
  let(:user_id) { 111 }
14
15
 
15
16
  subject { client.get_profile user_id }
16
17
 
17
- let(:raw_data) { SpecData.get "profile.json" }
18
+ let(:raw_data) { SpecData.get 'profile.json' }
18
19
 
19
20
  context 'given that the request is successful' do
20
21
  let(:code) { 200 }
21
22
 
22
- it { expect(TriviaCrack::Parsers::ProfileParser).to receive(:parse).once; subject }
23
+ it {
24
+ expect(TriviaCrack::Parsers::ProfileParser).to receive(:parse).once
25
+ subject
26
+ }
23
27
  it { is_expected.to be_a TriviaCrack::Profile }
24
28
  end
25
29
 
26
30
  context 'given that the request fails' do
27
31
  let(:code) { 400 }
28
32
 
29
- it { expect{ subject }.to raise_error TriviaCrack::Errors::RequestError }
30
- it { expect{ subject }.to raise_error(an_instance_of(TriviaCrack::Errors::RequestError)
31
- .and having_attributes(code: code)) }
32
- it { expect{ subject }.to raise_error(an_instance_of(TriviaCrack::Errors::RequestError)
33
- .and having_attributes(url: "/api/users/#{session.user_id}/profiles/#{user_id}")) }
33
+ it { expect { subject }.to raise_error TriviaCrack::Errors::RequestError }
34
+ it {
35
+ expect { subject }.to raise_error(an_instance_of(TriviaCrack::Errors::RequestError)
36
+ .and(having_attributes(code: code)))
37
+ }
38
+ it {
39
+ expect { subject }.to raise_error(an_instance_of(TriviaCrack::Errors::RequestError)
40
+ .and(having_attributes(url: "/api/users/#{session.user_id}/profiles/#{user_id}")))
41
+ }
34
42
  end
35
43
  end
36
44
 
37
- describe "#get_my_profile" do
38
-
45
+ describe '#get_my_profile' do
39
46
  subject { client.get_my_profile }
40
47
 
41
- let(:raw_data) { SpecData.get "my_profile.json" }
48
+ let(:raw_data) { SpecData.get 'my_profile.json' }
42
49
 
43
50
  context 'given that the request is successful' do
44
51
  let(:code) { 200 }
45
52
 
46
- it { expect(TriviaCrack::Parsers::ProfileParser).to receive(:parse).once; subject }
53
+ it {
54
+ expect(TriviaCrack::Parsers::ProfileParser).to receive(:parse).once
55
+ subject
56
+ }
47
57
  it { is_expected.to be_a TriviaCrack::Profile }
48
58
  end
49
59
 
50
60
  context 'given that the request fails' do
51
61
  let(:code) { 400 }
52
62
 
53
- it { expect{ subject }.to raise_error TriviaCrack::Errors::RequestError }
54
- it { expect{ subject }.to raise_error(an_instance_of(TriviaCrack::Errors::RequestError)
55
- .and having_attributes(code: code)) }
56
- it { expect{ subject }.to raise_error(an_instance_of(TriviaCrack::Errors::RequestError)
57
- .and having_attributes(url: "/api/users/#{session.user_id}/profiles/#{session.user_id}")) }
63
+ it { expect { subject }.to raise_error TriviaCrack::Errors::RequestError }
64
+ it {
65
+ expect { subject }.to raise_error(an_instance_of(TriviaCrack::Errors::RequestError)
66
+ .and(having_attributes(code: code)))
67
+ }
68
+ it {
69
+ expect { subject }.to raise_error(an_instance_of(TriviaCrack::Errors::RequestError)
70
+ .and(having_attributes(url: "/api/users/#{session.user_id}/profiles/#{session.user_id}")))
71
+ }
58
72
  end
59
73
  end
60
74
  end
@@ -1,27 +1,30 @@
1
- require "spec_helper"
1
+ # frozen_string_literal: true
2
2
 
3
- describe TriviaCrack::API::Question do
3
+ require 'spec_helper'
4
4
 
5
- let(:session) { TriviaCrack::Session.new session_id: "session", user_id: 1 }
5
+ describe TriviaCrack::API::Question do
6
+ let(:session) { TriviaCrack::Session.new session_id: 'session', user_id: 1 }
6
7
  let(:client) { (Class.new(APIStub) { include TriviaCrack::API::Question }).new session }
7
8
 
8
9
  let(:response) { double(status: code, body: raw_data) }
9
10
 
10
11
  before { allow(Faraday).to receive(:post) { response } }
11
12
 
12
- describe "#answer_question" do
13
-
13
+ describe '#answer_question' do
14
14
  subject { client.answer_question game_id, question, answer }
15
15
 
16
- let(:raw_data) { SpecData.get "answer.json" }
17
- let(:question) { double(id: 1, correct_answer: 1, type: "NORMAL", category: "SPORTS") }
16
+ let(:raw_data) { SpecData.get 'answer.json' }
17
+ let(:question) { double(id: 1, correct_answer: 1, type: 'NORMAL', category: 'SPORTS') }
18
18
  let(:game_id) { 22 }
19
19
 
20
20
  context 'given that the question was answered correctly' do
21
21
  let(:code) { 200 }
22
22
  let(:answer) { 1 }
23
23
 
24
- it { expect(TriviaCrack::Parsers::GameParser).to receive(:parse).once; subject }
24
+ it {
25
+ expect(TriviaCrack::Parsers::GameParser).to receive(:parse).once
26
+ subject
27
+ }
25
28
  it { expect(subject[0]).to be_a TriviaCrack::Game }
26
29
  it { expect(subject[1]).to be true }
27
30
  end
@@ -30,7 +33,10 @@ describe TriviaCrack::API::Question do
30
33
  let(:code) { 200 }
31
34
  let(:answer) { 0 }
32
35
 
33
- it { expect(TriviaCrack::Parsers::GameParser).to receive(:parse).once; subject }
36
+ it {
37
+ expect(TriviaCrack::Parsers::GameParser).to receive(:parse).once
38
+ subject
39
+ }
34
40
  it { expect(subject[0]).to be_a TriviaCrack::Game }
35
41
  it { expect(subject[1]).to be false }
36
42
  end
@@ -39,29 +45,35 @@ describe TriviaCrack::API::Question do
39
45
  let(:code) { 400 }
40
46
  let(:answer) { 1 }
41
47
 
42
- it { expect{ subject }.to raise_error TriviaCrack::Errors::RequestError }
43
- it { expect{ subject }.to raise_error(an_instance_of(TriviaCrack::Errors::RequestError)
44
- .and having_attributes(code: code)) }
45
- it { expect{ subject }.to raise_error(an_instance_of(TriviaCrack::Errors::RequestError)
46
- .and having_attributes(url: "/api/users/#{session.user_id}/games/#{game_id}/answers")) }
48
+ it { expect { subject }.to raise_error TriviaCrack::Errors::RequestError }
49
+ it {
50
+ expect { subject }.to raise_error(an_instance_of(TriviaCrack::Errors::RequestError)
51
+ .and(having_attributes(code: code)))
52
+ }
53
+ it {
54
+ expect { subject }.to raise_error(an_instance_of(TriviaCrack::Errors::RequestError)
55
+ .and(having_attributes(url: "/api/users/#{session.user_id}/games/#{game_id}/answers")))
56
+ }
47
57
  end
48
58
  end
49
59
 
50
- describe "#answer_questions" do
51
-
60
+ describe '#answer_questions' do
52
61
  subject { client.answer_questions game_id, questions, answers }
53
62
 
54
- let(:raw_data) { SpecData.get "answer.json" }
55
- let(:question_one) { double(id: 1, correct_answer: 1, type: "DUEL", category: "SPORTS") }
56
- let(:question_two) { double(id: 2, correct_answer: 2, type: "DUEL", category: "ART") }
63
+ let(:raw_data) { SpecData.get 'answer.json' }
64
+ let(:question_one) { double(id: 1, correct_answer: 1, type: 'DUEL', category: 'SPORTS') }
65
+ let(:question_two) { double(id: 2, correct_answer: 2, type: 'DUEL', category: 'ART') }
57
66
  let(:questions) { [question_one, question_two] }
58
67
  let(:game_id) { 22 }
59
68
 
60
69
  context 'given that the questions were answered correctly' do
61
70
  let(:code) { 200 }
62
- let(:answers) { {1 => 1, 2 => 2} }
71
+ let(:answers) { { 1 => 1, 2 => 2 } }
63
72
 
64
- it { expect(TriviaCrack::Parsers::GameParser).to receive(:parse).once; subject }
73
+ it {
74
+ expect(TriviaCrack::Parsers::GameParser).to receive(:parse).once
75
+ subject
76
+ }
65
77
  it { expect(subject[0]).to be_a TriviaCrack::Game }
66
78
  it { expect(subject[1][1]).to be true }
67
79
  it { expect(subject[1][2]).to be true }
@@ -69,9 +81,12 @@ describe TriviaCrack::API::Question do
69
81
 
70
82
  context 'given that a question was answered incorrectly' do
71
83
  let(:code) { 200 }
72
- let(:answers) { {1 => 1, 2 => 3} }
84
+ let(:answers) { { 1 => 1, 2 => 3 } }
73
85
 
74
- it { expect(TriviaCrack::Parsers::GameParser).to receive(:parse).once; subject }
86
+ it {
87
+ expect(TriviaCrack::Parsers::GameParser).to receive(:parse).once
88
+ subject
89
+ }
75
90
  it { expect(subject[0]).to be_a TriviaCrack::Game }
76
91
  it { expect(subject[1][1]).to be true }
77
92
  it { expect(subject[1][2]).to be false }
@@ -79,13 +94,17 @@ describe TriviaCrack::API::Question do
79
94
 
80
95
  context 'given that the request fails' do
81
96
  let(:code) { 400 }
82
- let(:answers) { {1 => 1, 2 => 2} }
83
-
84
- it { expect{ subject }.to raise_error TriviaCrack::Errors::RequestError }
85
- it { expect{ subject }.to raise_error(an_instance_of(TriviaCrack::Errors::RequestError)
86
- .and having_attributes(code: code)) }
87
- it { expect{ subject }.to raise_error(an_instance_of(TriviaCrack::Errors::RequestError)
88
- .and having_attributes(url: "/api/users/#{session.user_id}/games/#{game_id}/answers")) }
97
+ let(:answers) { { 1 => 1, 2 => 2 } }
98
+
99
+ it { expect { subject }.to raise_error TriviaCrack::Errors::RequestError }
100
+ it {
101
+ expect { subject }.to raise_error(an_instance_of(TriviaCrack::Errors::RequestError)
102
+ .and(having_attributes(code: code)))
103
+ }
104
+ it {
105
+ expect { subject }.to raise_error(an_instance_of(TriviaCrack::Errors::RequestError)
106
+ .and(having_attributes(url: "/api/users/#{session.user_id}/games/#{game_id}/answers")))
107
+ }
89
108
  end
90
109
  end
91
110
  end
@@ -1,20 +1,21 @@
1
- require "spec_helper"
1
+ # frozen_string_literal: true
2
2
 
3
- describe TriviaCrack::API::User do
3
+ require 'spec_helper'
4
4
 
5
- let(:session) { TriviaCrack::Session.new session_id: "session", user_id: 1 }
5
+ describe TriviaCrack::API::User do
6
+ let(:session) { TriviaCrack::Session.new session_id: 'session', user_id: 1 }
6
7
  let(:client) { (Class.new(APIStub) { include TriviaCrack::API::User }).new session }
7
8
 
8
9
  let(:response) { double(status: code, body: raw_data) }
9
10
 
10
11
  before { allow(Faraday).to receive(:get) { response } }
11
12
 
12
- describe "#get_user_id" do
13
- let(:username) { "example.2" }
13
+ describe '#get_user_id' do
14
+ let(:username) { 'example.2' }
14
15
 
15
16
  subject { client.get_user_id username }
16
17
 
17
- let(:raw_data) { SpecData.get "search.json" }
18
+ let(:raw_data) { SpecData.get 'search.json' }
18
19
 
19
20
  context 'given that the request is successful' do
20
21
  let(:code) { 200 }
@@ -25,35 +26,45 @@ describe TriviaCrack::API::User do
25
26
  context 'given that the request fails' do
26
27
  let(:code) { 400 }
27
28
 
28
- it { expect{ subject }.to raise_error TriviaCrack::Errors::RequestError }
29
- it { expect{ subject }.to raise_error(an_instance_of(TriviaCrack::Errors::RequestError)
30
- .and having_attributes(code: code)) }
31
- it { expect{ subject }.to raise_error(an_instance_of(TriviaCrack::Errors::RequestError)
32
- .and having_attributes(url: "/api/search?username=#{username}")) }
29
+ it { expect { subject }.to raise_error TriviaCrack::Errors::RequestError }
30
+ it {
31
+ expect { subject }.to raise_error(an_instance_of(TriviaCrack::Errors::RequestError)
32
+ .and(having_attributes(code: code)))
33
+ }
34
+ it {
35
+ expect { subject }.to raise_error(an_instance_of(TriviaCrack::Errors::RequestError)
36
+ .and(having_attributes(url: "/api/search?username=#{username}")))
37
+ }
33
38
  end
34
39
  end
35
40
 
36
- describe "#get_user" do
37
-
41
+ describe '#get_user' do
38
42
  subject { client.get_user }
39
43
 
40
- let(:raw_data) { SpecData.get "dashboard.json" }
44
+ let(:raw_data) { SpecData.get 'dashboard.json' }
41
45
 
42
46
  context 'given that the request is successful' do
43
47
  let(:code) { 200 }
44
48
 
45
- it { expect(TriviaCrack::Parsers::UserParser).to receive(:parse).once; subject }
49
+ it {
50
+ expect(TriviaCrack::Parsers::UserParser).to receive(:parse).once
51
+ subject
52
+ }
46
53
  it { is_expected.to be_a TriviaCrack::User }
47
54
  end
48
55
 
49
56
  context 'given that the request fails' do
50
57
  let(:code) { 400 }
51
58
 
52
- it { expect{ subject }.to raise_error TriviaCrack::Errors::RequestError }
53
- it { expect{ subject }.to raise_error(an_instance_of(TriviaCrack::Errors::RequestError)
54
- .and having_attributes(code: code)) }
55
- it { expect{ subject }.to raise_error(an_instance_of(TriviaCrack::Errors::RequestError)
56
- .and having_attributes(url: "/api/users/#{session.user_id}")) }
59
+ it { expect { subject }.to raise_error TriviaCrack::Errors::RequestError }
60
+ it {
61
+ expect { subject }.to raise_error(an_instance_of(TriviaCrack::Errors::RequestError)
62
+ .and(having_attributes(code: code)))
63
+ }
64
+ it {
65
+ expect { subject }.to raise_error(an_instance_of(TriviaCrack::Errors::RequestError)
66
+ .and(having_attributes(url: "/api/users/#{session.user_id}")))
67
+ }
57
68
  end
58
69
  end
59
70
  end
data/spec/game_spec.rb CHANGED
@@ -1,12 +1,12 @@
1
- require_relative "spec_helper"
1
+ # frozen_string_literal: true
2
2
 
3
- describe TriviaCrack::Game do
3
+ require_relative 'spec_helper'
4
4
 
5
+ describe TriviaCrack::Game do
5
6
  let(:game_id) { 1111 }
6
7
  let(:game) { TriviaCrack::Game.new id: game_id, my_turn: my_turn, game_status: game_status }
7
8
 
8
- describe "#playable?" do
9
-
9
+ describe '#playable?' do
10
10
  subject { game.playable? }
11
11
 
12
12
  context 'when the game status is active' do
@@ -1,15 +1,15 @@
1
- require "spec_helper"
1
+ # frozen_string_literal: true
2
2
 
3
- describe TriviaCrack::Parsers::CategoryStatisticsParser do
4
-
5
- describe ".parse" do
3
+ require 'spec_helper'
6
4
 
5
+ describe TriviaCrack::Parsers::CategoryStatisticsParser do
6
+ describe '.parse' do
7
7
  subject { TriviaCrack::Parsers::CategoryStatisticsParser.parse(category_data).values.first }
8
8
 
9
- let(:category_data) { raw_data["statistics"]["player_one_statistics"]["category_questions"] }
9
+ let(:category_data) { raw_data['statistics']['player_one_statistics']['category_questions'] }
10
10
 
11
11
  context 'when given data from the games API' do
12
- let(:raw_data) { SpecData.get_json "game.json" }
12
+ let(:raw_data) { SpecData.get_json 'game.json' }
13
13
 
14
14
  it { is_expected.to be_a TriviaCrack::CategoryStatistics }
15
15
  its(:category) { is_expected.to be :geography }
@@ -19,7 +19,7 @@ describe TriviaCrack::Parsers::CategoryStatisticsParser do
19
19
  end
20
20
 
21
21
  context 'when given data from the dashboard API' do
22
- let(:raw_data) { SpecData.get_json("dashboard.json")["list"][3] }
22
+ let(:raw_data) { SpecData.get_json('dashboard.json')['list'][3] }
23
23
 
24
24
  it { is_expected.to be_a TriviaCrack::CategoryStatistics }
25
25
  its(:category) { is_expected.to eq :arts }
@@ -29,7 +29,7 @@ describe TriviaCrack::Parsers::CategoryStatisticsParser do
29
29
  end
30
30
 
31
31
  context 'when given data from the answers API' do
32
- let(:raw_data) { SpecData.get_json "answer.json" }
32
+ let(:raw_data) { SpecData.get_json 'answer.json' }
33
33
 
34
34
  it { is_expected.to be_a TriviaCrack::CategoryStatistics }
35
35
  its(:category) { is_expected.to eq :sports }