barker 0.2.2

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 (91) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +3 -0
  3. data/.ruby-gemset +1 -0
  4. data/.ruby-version +1 -0
  5. data/.simplecov +7 -0
  6. data/Gemfile +6 -0
  7. data/Gemfile.lock +50 -0
  8. data/LICENSE +22 -0
  9. data/README.md +204 -0
  10. data/Rakefile +12 -0
  11. data/barker.gemspec +29 -0
  12. data/ci/run +20 -0
  13. data/lib/barker/answer.rb +11 -0
  14. data/lib/barker/api/base.rb +145 -0
  15. data/lib/barker/api/response/base.rb +25 -0
  16. data/lib/barker/api/response/candidate.rb +38 -0
  17. data/lib/barker/api/response/candidate_answer.rb +23 -0
  18. data/lib/barker/api/response/candidate_joker.rb +21 -0
  19. data/lib/barker/api/response/candidate_question.rb +51 -0
  20. data/lib/barker/api/response/error.rb +17 -0
  21. data/lib/barker/api/response/game_show.rb +43 -0
  22. data/lib/barker/api/response/round.rb +21 -0
  23. data/lib/barker/api/response.rb +15 -0
  24. data/lib/barker/api.rb +7 -0
  25. data/lib/barker/candidate.rb +52 -0
  26. data/lib/barker/candidate_answer.rb +42 -0
  27. data/lib/barker/candidate_joker.rb +30 -0
  28. data/lib/barker/candidate_question.rb +116 -0
  29. data/lib/barker/candidate_round.rb +32 -0
  30. data/lib/barker/entity.rb +15 -0
  31. data/lib/barker/game_show.rb +176 -0
  32. data/lib/barker/guideline/base.rb +33 -0
  33. data/lib/barker/guideline/llmcquiz/questions.yaml +300 -0
  34. data/lib/barker/guideline/llmcquiz.rb +28 -0
  35. data/lib/barker/guideline/mock.rb +17 -0
  36. data/lib/barker/guideline.rb +8 -0
  37. data/lib/barker/import/yaml.rb +22 -0
  38. data/lib/barker/import.rb +6 -0
  39. data/lib/barker/joker.rb +28 -0
  40. data/lib/barker/question.rb +12 -0
  41. data/lib/barker/quiz.rb +19 -0
  42. data/lib/barker/repo/memory/game_show.rb +38 -0
  43. data/lib/barker/repo/memory.rb +8 -0
  44. data/lib/barker/repo.rb +6 -0
  45. data/lib/barker/round.rb +68 -0
  46. data/lib/barker/stage.rb +38 -0
  47. data/lib/barker/store/memory.rb +158 -0
  48. data/lib/barker/store.rb +6 -0
  49. data/lib/barker/validations.rb +14 -0
  50. data/lib/barker/version.rb +3 -0
  51. data/lib/barker.rb +45 -0
  52. data/test/factories/answer.rb +21 -0
  53. data/test/factories/candidate.rb +23 -0
  54. data/test/factories/candidate_answer.rb +12 -0
  55. data/test/factories/candidate_joker.rb +8 -0
  56. data/test/factories/candidate_question.rb +16 -0
  57. data/test/factories/candidate_round.rb +8 -0
  58. data/test/factories/game_show.rb +12 -0
  59. data/test/factories/joker.rb +5 -0
  60. data/test/factories/question.rb +13 -0
  61. data/test/factories/quiz.rb +11 -0
  62. data/test/factories/round.rb +12 -0
  63. data/test/factories/stage.rb +12 -0
  64. data/test/fixtures/questions.yaml +20 -0
  65. data/test/test_helper.rb +72 -0
  66. data/test/test_mocks.rb +21 -0
  67. data/test/unit/answer_test.rb +49 -0
  68. data/test/unit/api/base_test.rb +207 -0
  69. data/test/unit/api/response/base_test.rb +35 -0
  70. data/test/unit/api/response/candidate_answer_test.rb +64 -0
  71. data/test/unit/api/response/candidate_joker_test.rb +60 -0
  72. data/test/unit/api/response/candidate_question_test.rb +99 -0
  73. data/test/unit/api/response/candidate_test.rb +82 -0
  74. data/test/unit/api/response/game_show_test.rb +105 -0
  75. data/test/unit/api/response/round_test.rb +49 -0
  76. data/test/unit/candidate_answer_test.rb +66 -0
  77. data/test/unit/candidate_question_test.rb +277 -0
  78. data/test/unit/candidate_round_test.rb +64 -0
  79. data/test/unit/candidate_test.rb +76 -0
  80. data/test/unit/game_show_test.rb +372 -0
  81. data/test/unit/guideline/base_test.rb +34 -0
  82. data/test/unit/guideline/llmcquiz_test.rb +35 -0
  83. data/test/unit/guideline/mock_test.rb +33 -0
  84. data/test/unit/import/yaml_test.rb +41 -0
  85. data/test/unit/joker_test.rb +32 -0
  86. data/test/unit/question_test.rb +55 -0
  87. data/test/unit/quiz_test.rb +37 -0
  88. data/test/unit/repo/memory/game_show_test.rb +54 -0
  89. data/test/unit/round_test.rb +167 -0
  90. data/test/unit/stage_test.rb +53 -0
  91. metadata +283 -0
@@ -0,0 +1,167 @@
1
+ require 'test_helper'
2
+
3
+ module Barker
4
+ class RoundRest < Spec
5
+
6
+ test "interface" do
7
+ Barker::Round.new(question, candidates)
8
+ end
9
+
10
+ test "valid factory" do
11
+ assert FactoryGirl.build(:round).valid?
12
+ end
13
+
14
+ test "invalid factory" do
15
+ refute FactoryGirl.build(:round, :invalid).valid?
16
+ end
17
+
18
+ test "invalid without candidates" do
19
+ refute FactoryGirl.build(:round, :candidates => []).valid?
20
+ end
21
+
22
+ test "invalid with invalid question" do
23
+ refute FactoryGirl.build(:round, :question => invalid_question).valid?
24
+ end
25
+
26
+ test "start set start_at only once" do
27
+ started_at = Time.now
28
+ started_again_at = Time.now + 100
29
+ Time.stubs(:now).returns(started_at)
30
+
31
+ round = FactoryGirl.build(:round)
32
+
33
+ assert_nil round.started_at
34
+ round.start
35
+ assert_equal started_at, round.started_at
36
+
37
+ Time.stubs(:now).returns(started_again_at)
38
+ round.start
39
+ assert_equal started_at, round.started_at
40
+ end
41
+
42
+ test "started?" do
43
+ round = FactoryGirl.build(:round)
44
+ refute round.started?
45
+ round.start
46
+ assert round.started?
47
+ end
48
+
49
+ test "finish set start_at only once" do
50
+ finished_at = Time.now
51
+ finished_again_at = Time.now + 100
52
+ Time.stubs(:now).returns(finished_at)
53
+
54
+ round = FactoryGirl.build(:round)
55
+
56
+ assert_nil round.finished_at
57
+ round.finish
58
+ assert_equal finished_at, round.finished_at
59
+
60
+ Time.stubs(:now).returns(finished_again_at)
61
+ round.start
62
+ assert_equal finished_at, round.finished_at
63
+ end
64
+
65
+ test "finished?" do
66
+ round = FactoryGirl.build(:round)
67
+ refute round.finished?
68
+ round.finish
69
+ assert round.finished?
70
+ end
71
+
72
+ test "running?" do
73
+ round = FactoryGirl.build(:round)
74
+
75
+ refute round.running?
76
+ round.start
77
+ assert round.running?
78
+ round.finish
79
+ refute round.running?
80
+ end
81
+
82
+ test "candidate_round" do
83
+ round = FactoryGirl.build(:round)
84
+
85
+ refute round.candidates.empty?
86
+
87
+ round.candidates.each do |candidate|
88
+ candidate_round = round.send(:candidate_round, candidate.id)
89
+ assert_kind_of CandidateRound, candidate_round
90
+ assert_equal round, candidate_round.round
91
+ assert_equal candidate, candidate_round.candidate
92
+ end
93
+ end
94
+
95
+ test "ask return candidate question" do
96
+ round = FactoryGirl.build(:round)
97
+ candidate_id = round.candidates[0].id
98
+ assert_kind_of CandidateQuestion, round.ask(candidate_id)
99
+ end
100
+
101
+ test "ask delegation" do
102
+ candidate_round = Minitest::Mock.new
103
+ round = Round.new(nil, nil)
104
+
105
+ candidate_round.expect(:ask, :candidate_question, [{}])
106
+
107
+ round.stub :candidate_round, candidate_round do
108
+ assert_equal :candidate_question, round.ask(:candidate_id)
109
+ end
110
+
111
+ assert candidate_round.verify
112
+ end
113
+
114
+ test "answer return candidate answer" do
115
+ round = FactoryGirl.build(:round)
116
+ candidate_id = round.candidates[0].id
117
+ answer_id = round.question.answers[0].id
118
+
119
+ assert_kind_of CandidateAnswer, round.answer(candidate_id, answer_id)
120
+ end
121
+
122
+ test "answer delegation" do
123
+ candidate_round = Minitest::Mock.new
124
+ round = FactoryGirl.build(:round)
125
+ candidate_id = :candidate_id
126
+ answer_index = 0
127
+
128
+ candidate_round.expect(:answer, :candidate_answer, [answer_index])
129
+
130
+ round.stub :candidate_round, candidate_round do
131
+ assert_equal :candidate_answer, round.answer(candidate_id, answer_index)
132
+ end
133
+
134
+ assert candidate_round.verify
135
+ end
136
+
137
+ test "given answer return candidate answer" do
138
+ round = FactoryGirl.build(:round)
139
+ candidate_id = round.candidates[0].id
140
+ answer_id = round.question.answers[0].id
141
+
142
+ round.answer(candidate_id, answer_id)
143
+ assert_kind_of CandidateAnswer, round.given_answer(candidate_id)
144
+ end
145
+
146
+ test "answer delegation" do
147
+ candidate_round = Minitest::Mock.new
148
+ round = FactoryGirl.build(:round)
149
+ candidate_id = :candidate_id
150
+
151
+ candidate_round.expect(:given_answer, :candidate_answer)
152
+
153
+ round.stub :candidate_round, candidate_round do
154
+ assert_equal :candidate_answer, round.given_answer(candidate_id)
155
+ end
156
+
157
+ assert candidate_round.verify
158
+ end
159
+
160
+ private
161
+
162
+ let(:question) { FactoryGirl.build(:question) }
163
+ let(:invalid_question) { FactoryGirl.build(:question, :invalid) }
164
+ let(:candidates) { FactoryGirl.build_list(:candidate, 2) }
165
+
166
+ end
167
+ end
@@ -0,0 +1,53 @@
1
+ require 'test_helper'
2
+
3
+ module Barker
4
+ class StageTest < Spec
5
+
6
+ test "interface" do
7
+ Barker::Stage.new(FactoryGirl.build(:quiz), FactoryGirl.build_list(:candidate, 2))
8
+ end
9
+
10
+ test "valid factory" do
11
+ assert FactoryGirl.build(:stage).valid?
12
+ end
13
+
14
+ test "invalid factory" do
15
+ refute FactoryGirl.build(:stage, :invalid).valid?
16
+ end
17
+
18
+ test "invalid if quiz is invalid" do
19
+ assert FactoryGirl.build(:stage, :quiz => FactoryGirl.build(:quiz)).valid?
20
+ refute FactoryGirl.build(:stage, :quiz => FactoryGirl.build(:quiz, :invalid)).valid?
21
+ end
22
+
23
+ test "invalid without candidates" do
24
+ assert FactoryGirl.build(:stage, :candidates => FactoryGirl.build_list(:candidate, 1)).valid?
25
+ refute FactoryGirl.build(:stage, :candidates => []).valid?
26
+ end
27
+
28
+ test "candidates" do
29
+ quiz = FactoryGirl.build(:quiz, :questions => FactoryGirl.build_list(:question, 2))
30
+ candidates = FactoryGirl.build_list(:candidate, 2)
31
+ assert_equal candidates, FactoryGirl.build(:stage, :candidates => candidates).candidates
32
+ end
33
+
34
+ test "rounds" do
35
+ quiz = FactoryGirl.build(:quiz, :questions => FactoryGirl.build_list(:question, 2))
36
+ stage = FactoryGirl.build(:stage, :quiz => quiz, :candidates => candidates)
37
+
38
+ assert_equal 2, stage.rounds.size
39
+ assert_kind_of Barker::Round, stage.rounds[0]
40
+ end
41
+
42
+ test "next_round" do
43
+ quiz = FactoryGirl.build(:quiz, :questions => FactoryGirl.build_list(:question, 2))
44
+ stage = FactoryGirl.build(:stage, :quiz => quiz, :candidates => candidates)
45
+
46
+ stage.next_round
47
+ assert_equal stage.rounds[0], stage.current_round
48
+ stage.next_round
49
+ assert_equal stage.rounds[1], stage.current_round
50
+ end
51
+
52
+ end
53
+ end
metadata ADDED
@@ -0,0 +1,283 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: barker
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.2
5
+ platform: ruby
6
+ authors:
7
+ - Jan Owiesniak
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-07-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rack
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: factory_girl
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: mocha
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: activesupport
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: activemodel
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: thread_safe
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ description: barker
126
+ email:
127
+ - jo@neopoly.de
128
+ executables: []
129
+ extensions: []
130
+ extra_rdoc_files: []
131
+ files:
132
+ - .gitignore
133
+ - .ruby-gemset
134
+ - .ruby-version
135
+ - .simplecov
136
+ - Gemfile
137
+ - Gemfile.lock
138
+ - LICENSE
139
+ - README.md
140
+ - Rakefile
141
+ - barker.gemspec
142
+ - ci/run
143
+ - lib/barker.rb
144
+ - lib/barker/answer.rb
145
+ - lib/barker/api.rb
146
+ - lib/barker/api/base.rb
147
+ - lib/barker/api/response.rb
148
+ - lib/barker/api/response/base.rb
149
+ - lib/barker/api/response/candidate.rb
150
+ - lib/barker/api/response/candidate_answer.rb
151
+ - lib/barker/api/response/candidate_joker.rb
152
+ - lib/barker/api/response/candidate_question.rb
153
+ - lib/barker/api/response/error.rb
154
+ - lib/barker/api/response/game_show.rb
155
+ - lib/barker/api/response/round.rb
156
+ - lib/barker/candidate.rb
157
+ - lib/barker/candidate_answer.rb
158
+ - lib/barker/candidate_joker.rb
159
+ - lib/barker/candidate_question.rb
160
+ - lib/barker/candidate_round.rb
161
+ - lib/barker/entity.rb
162
+ - lib/barker/game_show.rb
163
+ - lib/barker/guideline.rb
164
+ - lib/barker/guideline/base.rb
165
+ - lib/barker/guideline/llmcquiz.rb
166
+ - lib/barker/guideline/llmcquiz/questions.yaml
167
+ - lib/barker/guideline/mock.rb
168
+ - lib/barker/import.rb
169
+ - lib/barker/import/yaml.rb
170
+ - lib/barker/joker.rb
171
+ - lib/barker/question.rb
172
+ - lib/barker/quiz.rb
173
+ - lib/barker/repo.rb
174
+ - lib/barker/repo/memory.rb
175
+ - lib/barker/repo/memory/game_show.rb
176
+ - lib/barker/round.rb
177
+ - lib/barker/stage.rb
178
+ - lib/barker/store.rb
179
+ - lib/barker/store/memory.rb
180
+ - lib/barker/validations.rb
181
+ - lib/barker/version.rb
182
+ - test/factories/answer.rb
183
+ - test/factories/candidate.rb
184
+ - test/factories/candidate_answer.rb
185
+ - test/factories/candidate_joker.rb
186
+ - test/factories/candidate_question.rb
187
+ - test/factories/candidate_round.rb
188
+ - test/factories/game_show.rb
189
+ - test/factories/joker.rb
190
+ - test/factories/question.rb
191
+ - test/factories/quiz.rb
192
+ - test/factories/round.rb
193
+ - test/factories/stage.rb
194
+ - test/fixtures/questions.yaml
195
+ - test/test_helper.rb
196
+ - test/test_mocks.rb
197
+ - test/unit/answer_test.rb
198
+ - test/unit/api/base_test.rb
199
+ - test/unit/api/response/base_test.rb
200
+ - test/unit/api/response/candidate_answer_test.rb
201
+ - test/unit/api/response/candidate_joker_test.rb
202
+ - test/unit/api/response/candidate_question_test.rb
203
+ - test/unit/api/response/candidate_test.rb
204
+ - test/unit/api/response/game_show_test.rb
205
+ - test/unit/api/response/round_test.rb
206
+ - test/unit/candidate_answer_test.rb
207
+ - test/unit/candidate_question_test.rb
208
+ - test/unit/candidate_round_test.rb
209
+ - test/unit/candidate_test.rb
210
+ - test/unit/game_show_test.rb
211
+ - test/unit/guideline/base_test.rb
212
+ - test/unit/guideline/llmcquiz_test.rb
213
+ - test/unit/guideline/mock_test.rb
214
+ - test/unit/import/yaml_test.rb
215
+ - test/unit/joker_test.rb
216
+ - test/unit/question_test.rb
217
+ - test/unit/quiz_test.rb
218
+ - test/unit/repo/memory/game_show_test.rb
219
+ - test/unit/round_test.rb
220
+ - test/unit/stage_test.rb
221
+ homepage: ''
222
+ licenses: []
223
+ metadata: {}
224
+ post_install_message:
225
+ rdoc_options: []
226
+ require_paths:
227
+ - lib
228
+ required_ruby_version: !ruby/object:Gem::Requirement
229
+ requirements:
230
+ - - '>='
231
+ - !ruby/object:Gem::Version
232
+ version: '0'
233
+ required_rubygems_version: !ruby/object:Gem::Requirement
234
+ requirements:
235
+ - - '>='
236
+ - !ruby/object:Gem::Version
237
+ version: '0'
238
+ requirements: []
239
+ rubyforge_project:
240
+ rubygems_version: 2.0.3
241
+ signing_key:
242
+ specification_version: 4
243
+ summary: barker
244
+ test_files:
245
+ - test/factories/answer.rb
246
+ - test/factories/candidate.rb
247
+ - test/factories/candidate_answer.rb
248
+ - test/factories/candidate_joker.rb
249
+ - test/factories/candidate_question.rb
250
+ - test/factories/candidate_round.rb
251
+ - test/factories/game_show.rb
252
+ - test/factories/joker.rb
253
+ - test/factories/question.rb
254
+ - test/factories/quiz.rb
255
+ - test/factories/round.rb
256
+ - test/factories/stage.rb
257
+ - test/fixtures/questions.yaml
258
+ - test/test_helper.rb
259
+ - test/test_mocks.rb
260
+ - test/unit/answer_test.rb
261
+ - test/unit/api/base_test.rb
262
+ - test/unit/api/response/base_test.rb
263
+ - test/unit/api/response/candidate_answer_test.rb
264
+ - test/unit/api/response/candidate_joker_test.rb
265
+ - test/unit/api/response/candidate_question_test.rb
266
+ - test/unit/api/response/candidate_test.rb
267
+ - test/unit/api/response/game_show_test.rb
268
+ - test/unit/api/response/round_test.rb
269
+ - test/unit/candidate_answer_test.rb
270
+ - test/unit/candidate_question_test.rb
271
+ - test/unit/candidate_round_test.rb
272
+ - test/unit/candidate_test.rb
273
+ - test/unit/game_show_test.rb
274
+ - test/unit/guideline/base_test.rb
275
+ - test/unit/guideline/llmcquiz_test.rb
276
+ - test/unit/guideline/mock_test.rb
277
+ - test/unit/import/yaml_test.rb
278
+ - test/unit/joker_test.rb
279
+ - test/unit/question_test.rb
280
+ - test/unit/quiz_test.rb
281
+ - test/unit/repo/memory/game_show_test.rb
282
+ - test/unit/round_test.rb
283
+ - test/unit/stage_test.rb