barker 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
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,372 @@
1
+ require 'test_helper'
2
+
3
+ module Barker
4
+ class GameShowTest < Spec
5
+
6
+ test "interface" do
7
+ Barker::GameShow.new(quizzes, candidates)
8
+ end
9
+
10
+ test "invalid without stages" do
11
+ refute FactoryGirl.build(:game_show, :candidates => []).valid?
12
+ end
13
+
14
+ test "invalid without quizzes" do
15
+ refute FactoryGirl.build(:game_show, :quizzes => []).valid?
16
+ end
17
+
18
+ test "valid factory" do
19
+ FactoryGirl.build(:game_show).valid?
20
+ end
21
+
22
+ test "invalid factory" do
23
+ refute FactoryGirl.build(:game_show, :invalid).valid?
24
+ end
25
+
26
+ test "game_show_id" do
27
+ game_show = FactoryGirl.build(:game_show)
28
+ assert_equal game_show.id, game_show.game_show_id
29
+ end
30
+
31
+ test "candidates" do
32
+ assert_equal candidates, FactoryGirl.build(:game_show, :candidates => candidates).candidates
33
+ end
34
+
35
+ test "candidates joined on initialization" do
36
+ assert FactoryGirl.build(:game_show, :candidates => candidates).candidates.all?(&:joined?)
37
+ end
38
+
39
+ test "quizzes" do
40
+ assert_equal quizzes, FactoryGirl.build(:game_show, :quizzes => quizzes).quizzes
41
+ end
42
+
43
+ test "start set started_at to now only once" do
44
+ time_once = Time.now
45
+ time_twice = Time.now + 2.days
46
+
47
+ game_show = FactoryGirl.build(:game_show)
48
+ assert_nil game_show.started_at
49
+
50
+ Time.stubs(:now).returns(time_once)
51
+
52
+ game_show.start
53
+ assert_equal time_once, game_show.started_at
54
+
55
+ Time.stubs(:now).returns(time_twice)
56
+
57
+ game_show.start
58
+ assert_equal time_once, game_show.started_at
59
+ end
60
+
61
+ test "started?" do
62
+ game_show = FactoryGirl.build(:game_show)
63
+
64
+ refute game_show.started?
65
+ game_show.start
66
+ assert game_show.started?
67
+ end
68
+
69
+ test "finish set started_at to now only once" do
70
+ time_once = Time.now
71
+ time_twice = Time.now + 2.days
72
+
73
+ game_show = FactoryGirl.build(:game_show)
74
+ assert_nil game_show.finished_at
75
+
76
+ Time.stubs(:now).returns(time_once)
77
+
78
+ game_show.finish
79
+ assert_equal time_once, game_show.finished_at
80
+
81
+ Time.stubs(:now).returns(time_twice)
82
+
83
+ game_show.finish
84
+ assert_equal time_once, game_show.finished_at
85
+ end
86
+
87
+ test "finished?" do
88
+ game_show = FactoryGirl.build(:game_show)
89
+
90
+ refute game_show.finished?
91
+ game_show.finish
92
+ assert game_show.finished?
93
+ end
94
+
95
+ test "abort set started_at to now only once" do
96
+ time_once = Time.now
97
+ time_twice = Time.now + 2.days
98
+
99
+ game_show = FactoryGirl.build(:game_show)
100
+ assert_nil game_show.aborted_at
101
+
102
+ Time.stubs(:now).returns(time_once)
103
+
104
+ game_show.abort
105
+ assert_equal time_once, game_show.aborted_at
106
+
107
+ Time.stubs(:now).returns(time_twice)
108
+
109
+ game_show.abort
110
+ assert_equal time_once, game_show.aborted_at
111
+ end
112
+
113
+ test "aborted?" do
114
+ game_show = FactoryGirl.build(:game_show)
115
+
116
+ refute game_show.aborted?
117
+ game_show.abort
118
+ assert game_show.aborted?
119
+ end
120
+
121
+ test "running? - start" do
122
+ game_show = FactoryGirl.build(:game_show)
123
+
124
+ refute game_show.running?
125
+ game_show.start
126
+ assert game_show.running?
127
+ end
128
+
129
+ test "running? - finish" do
130
+ game_show = FactoryGirl.build(:game_show)
131
+
132
+ game_show.start
133
+ game_show.finish
134
+ refute game_show.running?
135
+ end
136
+
137
+ test "running? - abort" do
138
+ game_show = FactoryGirl.build(:game_show)
139
+
140
+ game_show.start
141
+ game_show.abort
142
+ refute game_show.running?
143
+ end
144
+
145
+ test "next_stage" do
146
+ game_show = FactoryGirl.build(:game_show)
147
+ game_show.start
148
+
149
+ game_show.next_stage
150
+ assert_equal game_show.stages[0], game_show.current_stage
151
+ game_show.next_stage
152
+ assert_equal game_show.stages[1], game_show.current_stage
153
+ end
154
+
155
+ test "next_stage?" do
156
+ game_show = FactoryGirl.build(:game_show)
157
+ game_show.start
158
+
159
+ assert game_show.next_stage?
160
+ game_show.next_stage
161
+ assert game_show.next_stage?
162
+ game_show.next_stage
163
+ refute game_show.next_stage?
164
+ end
165
+
166
+ test "next_round" do
167
+ game_show = FactoryGirl.build(:game_show)
168
+ game_show.start
169
+
170
+ game_show.next_stage
171
+ game_show.next_round
172
+ assert_equal game_show.stages[0].rounds[0], game_show.current_round
173
+ game_show.next_round
174
+ assert_equal game_show.stages[0].rounds[1], game_show.current_round
175
+ end
176
+
177
+ test "next_round?" do
178
+ game_show = FactoryGirl.build(:game_show)
179
+ game_show.start
180
+
181
+ # first stage
182
+ game_show.next_stage
183
+ assert_equal 2, game_show.current_stage.rounds.size
184
+
185
+ assert game_show.next_round?
186
+ game_show.next_round
187
+ assert game_show.next_round?
188
+ game_show.next_round
189
+ refute game_show.next_round?
190
+
191
+ # second stage
192
+ game_show.next_stage
193
+ assert_equal 2, game_show.current_stage.rounds.size
194
+
195
+ assert game_show.next_round?
196
+ game_show.next_round
197
+ assert game_show.next_round?
198
+ game_show.next_round
199
+ refute game_show.next_round?
200
+ end
201
+
202
+ test "ask delegation" do
203
+ game_show = FactoryGirl.build(:game_show)
204
+ round = Minitest::Mock.new
205
+ candidate_id = :candidate_id
206
+
207
+ round.expect(:ask, :candidate_question, [candidate_id, {}])
208
+
209
+ game_show.stub :current_round, round do
210
+ assert_equal :candidate_question, game_show.ask(candidate_id)
211
+ end
212
+
213
+ assert round.verify
214
+ end
215
+
216
+ test "answer delegation" do
217
+ game_show = FactoryGirl.build(:game_show)
218
+ round = Minitest::Mock.new
219
+ candidate_id = :candidate_id
220
+ answer_id = :answer_id
221
+
222
+ round.expect(:answer, :candidate_answer, [candidate_id, answer_id])
223
+ round.expect(:candidate_round, :round, [candidate_id])
224
+
225
+ game_show.stub :current_round, round do
226
+ assert_equal :candidate_answer, game_show.answer(candidate_id, answer_id)
227
+ end
228
+
229
+ assert round.verify
230
+ end
231
+
232
+ test "given answer delegation" do
233
+ game_show = FactoryGirl.build(:game_show)
234
+ round = Minitest::Mock.new
235
+ candidate_id = :candidate_id
236
+
237
+ round.expect(:given_answer, :candidate_answer, [candidate_id])
238
+
239
+ game_show.stub :current_round, round do
240
+ assert_equal :candidate_answer, game_show.given_answer(candidate_id)
241
+ end
242
+
243
+ assert round.verify
244
+ end
245
+
246
+ test "join before start" do
247
+ candidates = FactoryGirl.build_list(:candidate, 1)
248
+ candidate = FactoryGirl.build(:candidate)
249
+ expected = candidates + [candidate]
250
+ game_show = FactoryGirl.build(:game_show, :candidates => candidates)
251
+
252
+ refute candidate.joined?
253
+ assert_equal candidate, game_show.join(candidate)
254
+ assert candidate.joined?
255
+
256
+ assert_equal expected, game_show.candidates
257
+ end
258
+
259
+ test "join after start" do
260
+ candidates = FactoryGirl.build_list(:candidate, 1)
261
+ candidate = FactoryGirl.build(:candidate)
262
+ game_show = FactoryGirl.build(:game_show, :candidates => candidates)
263
+
264
+ game_show.start
265
+
266
+ assert_raises Barker::Errors::AlreadyStartedError do
267
+ game_show.join(candidate)
268
+ end
269
+
270
+ assert_equal candidates, game_show.candidates
271
+ end
272
+
273
+ test "leave" do
274
+ game_show = FactoryGirl.build(:game_show)
275
+ game_show.start
276
+
277
+ candidate = game_show.candidates[0]
278
+ candidate_id = candidate.id
279
+
280
+ refute candidate.leaved?
281
+ assert_equal candidate, game_show.leave(candidate_id)
282
+ assert candidate.leaved?
283
+ end
284
+
285
+ test "no jokers by default" do
286
+ assert_equal [], FactoryGirl.build(:game_show).jokers
287
+ end
288
+
289
+ test "candidate use joker" do
290
+ quizzes = FactoryGirl.build_list(:quiz, 1)
291
+ candidates = FactoryGirl.build_list(:candidate, 1)
292
+ candidate = candidates[0]
293
+ candidate_id = candidate.id
294
+ game_show = Barker::GameShow.new(quizzes, candidates, :guideline => :mock)
295
+
296
+ game_show.start
297
+ game_show.next_stage
298
+ game_show.next_round
299
+
300
+ used_at = Time.now
301
+ Time.stubs(:now).returns(used_at)
302
+
303
+ assert_equal [], candidate.jokers
304
+
305
+ joker = game_show.joker(candidate_id, 'fifty_fifty')
306
+
307
+ assert_kind_of CandidateJoker, joker
308
+ assert_equal used_at, joker.used_at
309
+ assert_equal game_show.ask(candidate_id), joker.used_in
310
+
311
+ assert_equal [joker], candidate.jokers
312
+
313
+ assert_raises Barker::Errors::JokerAlreadyUsedError do
314
+ game_show.joker(candidate_id, 'fifty_fifty')
315
+ end
316
+ end
317
+
318
+ test "candidate use joker on game show without jokers" do
319
+ game_show = Barker::GameShow.new(quizzes, candidates)
320
+
321
+ game_show.start
322
+ game_show.next_stage
323
+ game_show.next_round
324
+
325
+ assert_raises Barker::Errors::UnknownJokerError do
326
+ game_show.joker(game_show.candidates[0].id, 'fifty_fifty')
327
+ end
328
+ end
329
+
330
+ test "candidate use unknown joker" do
331
+ game_show = Barker::GameShow.new(quizzes, candidates)
332
+
333
+ game_show.start
334
+ game_show.next_stage
335
+ game_show.next_round
336
+
337
+ assert_raises Barker::Errors::UnknownJokerError do
338
+ game_show.joker(game_show.candidates[0].id, 'fifty_fifty')
339
+ end
340
+ end
341
+
342
+ test "load serialized game show" do
343
+ game_show = FactoryGirl.build(:game_show)
344
+ serialized = game_show.serialize
345
+ assert_equal game_show, Barker::GameShow.load(serialized)
346
+ end
347
+
348
+ test "default guideline" do
349
+ game_show = FactoryGirl.build(:game_show)
350
+ assert_kind_of Barker::Guideline::Base, game_show.guideline
351
+ end
352
+
353
+ test "optional guideline" do
354
+ game_show = Barker::GameShow.new(quizzes, candidates, :guideline => :mock)
355
+ assert_kind_of Barker::Guideline::Mock, game_show.guideline
356
+ end
357
+
358
+ test "round_time mock" do
359
+ assert_equal nil, Barker::GameShow.new(quizzes, candidates, :guideline => :mock).round_time
360
+ end
361
+
362
+ test "round_time llmcquiz" do
363
+ assert_equal 35, Barker::GameShow.new(quizzes, candidates, :guideline => :llmcquiz).round_time
364
+ end
365
+
366
+ private
367
+
368
+ let(:candidates) { FactoryGirl.build_list(:candidate, 2) }
369
+ let(:quizzes) { FactoryGirl.build_list(:quiz, 2) }
370
+
371
+ end
372
+ end
@@ -0,0 +1,34 @@
1
+ require 'test_helper'
2
+
3
+ module Barker
4
+ module Guideline
5
+ class BaseTest < Spec
6
+
7
+ test "quizzes" do
8
+ assert_equal [], guideline.quizzes
9
+ end
10
+
11
+ test "jokers" do
12
+ assert_equal [], guideline.jokers
13
+ end
14
+
15
+ test "candidates" do
16
+ assert_equal [], guideline.candidates
17
+ end
18
+
19
+ test "round_time" do
20
+ assert_nil guideline.round_time
21
+ end
22
+
23
+ test "answer" do
24
+ assert_nil guideline.answer(nil, nil, nil)
25
+ end
26
+
27
+ private
28
+
29
+ let(:guideline) { Barker::Guideline::Base.new }
30
+
31
+ end
32
+ end
33
+ end
34
+
@@ -0,0 +1,35 @@
1
+ require 'test_helper'
2
+
3
+ module Barker
4
+ module Guideline
5
+ class LlmcquizTest < Spec
6
+
7
+ test "one quiz with 5 random questions" do
8
+ assert_equal 1, guideline.quizzes.size
9
+ assert_equal 5, guideline.quizzes[0].questions.size
10
+ end
11
+
12
+ test "questions" do
13
+ assert_equal 15, guideline.questions.size
14
+ end
15
+
16
+ test "round_time" do
17
+ assert_equal 35, guideline.round_time
18
+ end
19
+
20
+ test "jokers" do
21
+ assert_equal ['fifty_fifty'], guideline.jokers
22
+ end
23
+
24
+ test "candidates" do
25
+ assert_equal [], guideline.candidates
26
+ end
27
+
28
+ private
29
+
30
+ let(:guideline) { Barker::Guideline::Llmcquiz.new }
31
+ let(:api) { Barker::Api::Base.new }
32
+
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,33 @@
1
+ require 'test_helper'
2
+
3
+ module Barker
4
+ module Guideline
5
+ class MockTest < Spec
6
+
7
+ test "quizzes" do
8
+ assert_kind_of Barker::Quiz, guideline.quizzes[0]
9
+ end
10
+
11
+ test "jokers" do
12
+ assert_equal ['fifty_fifty'], guideline.jokers
13
+ end
14
+
15
+ test "candidates" do
16
+ assert_equal [], guideline.candidates
17
+ end
18
+
19
+ test "round_time" do
20
+ assert_nil guideline.round_time
21
+ end
22
+
23
+ test "answer" do
24
+ assert_nil guideline.answer(nil, nil, nil)
25
+ end
26
+
27
+ private
28
+
29
+ let(:guideline) { Barker::Guideline::Mock.new }
30
+
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,41 @@
1
+ require 'test_helper'
2
+
3
+ module Barker
4
+ module Import
5
+ class YamlTest < Spec
6
+
7
+ test "process" do
8
+ path = File.expand_path "#{File.dirname(__FILE__)}/../../fixtures/questions.yaml"
9
+ questions = Barker::Import::Yaml.process(path)
10
+
11
+ question = questions[0]
12
+ assert_equal 1, question.id
13
+ assert_equal "Wann ist der SuperCode nach Kauf einlösbar?", question.label['de']
14
+
15
+ assert_equal "10 Minuten", question.answers[0].label['de']
16
+ assert_equal 1, question.answers[0].id
17
+ refute question.answers[0].correct?
18
+
19
+ assert_equal "30 Minuten", question.answers[1].label['de']
20
+ assert_equal 2, question.answers[1].id
21
+ assert question.answers[1].correct?
22
+
23
+ assert_equal "5 Minuten", question.answers[2].label['de']
24
+ assert_equal 3, question.answers[2].id
25
+ refute question.answers[2].correct?
26
+
27
+ assert_equal "sofort", question.answers[3].label['de']
28
+ assert_equal 4, question.answers[3].id
29
+ refute question.answers[3].correct?
30
+ end
31
+
32
+ test "file not exist" do
33
+ assert_raises Barker::Errors::FileNotExistError do
34
+ Barker::Import::Yaml.process('questions.yaml')
35
+ end
36
+ end
37
+
38
+ end
39
+ end
40
+ end
41
+
@@ -0,0 +1,32 @@
1
+ require 'test_helper'
2
+
3
+ module Barker
4
+ class JokerTest < Spec
5
+
6
+ describe "fifty_fifty" do
7
+ it "reveal 2 wrong answers" do
8
+ question = FactoryGirl.build(:question, :answers => FactoryGirl.build_list(:answer, 4))
9
+ candidate_question = FactoryGirl.build(:candidate_question, :question => question)
10
+ joker = Barker::Joker.new('fifty_fifty')
11
+ candidate_joker = Barker::CandidateJoker.new(candidate_question, joker)
12
+
13
+ answers = candidate_question.answers
14
+ correct_answers = answers.select {|a| a.correct? }
15
+ wrong_answers = answers.reject {|a| a.correct? }
16
+
17
+ assert_equal 4, answers.size
18
+ assert_equal 2, correct_answers.size
19
+ assert_equal 2, wrong_answers.size
20
+
21
+ assert_equal 0, correct_answers.select {|a| a.revealed? }.size
22
+ assert_equal 0, wrong_answers.select {|a| a.revealed? }.size
23
+
24
+ candidate_joker.call
25
+
26
+ assert_equal 0, correct_answers.select {|a| a.revealed? }.size
27
+ assert_equal 2, wrong_answers.select {|a| a.revealed? }.size
28
+ end
29
+ end
30
+
31
+ end
32
+ end
@@ -0,0 +1,55 @@
1
+ require 'test_helper'
2
+
3
+ module Barker
4
+ class QuestionTest < Spec
5
+
6
+ test "interface" do
7
+ Barker::Question.new(1, {"en" => "label"}, [FactoryGirl.build(:answer)])
8
+ end
9
+
10
+ test "valid factory" do
11
+ assert FactoryGirl.build(:question).valid?
12
+ end
13
+
14
+ test "invalid factory" do
15
+ refute FactoryGirl.build(:question, :invalid).valid?
16
+ end
17
+
18
+ test "validate numerically of id" do
19
+ assert FactoryGirl.build(:question, :id => 1).valid?
20
+ refute FactoryGirl.build(:question, :id => 1.5).valid?
21
+ refute FactoryGirl.build(:question, :id => "1").valid?
22
+ end
23
+
24
+ test "invalid if one or more answers are invalid" do
25
+ assert FactoryGirl.build(:question, :answers => [FactoryGirl.build(:answer), FactoryGirl.build(:answer)]).valid?
26
+ refute FactoryGirl.build(:question, :answers => [FactoryGirl.build(:answer, :invalid), FactoryGirl.build(:answer)]).valid?
27
+ end
28
+
29
+ test "equality by id" do
30
+ assert_equal FactoryGirl.build(:question, :id => 1), FactoryGirl.build(:question, :id => 1)
31
+ refute_equal FactoryGirl.build(:question, :id => 1), FactoryGirl.build(:question, :id => 2)
32
+ end
33
+
34
+ test "id" do
35
+ assert_equal 1, FactoryGirl.build(:question, :id => 1).id
36
+ end
37
+
38
+ test "label" do
39
+ label = { "en" => "question", "de" => "frage" }
40
+ assert_equal label, FactoryGirl.build(:question, :label => label).label
41
+ end
42
+
43
+ test "answers" do
44
+ assert_equal answers, question.answers
45
+ end
46
+
47
+ private
48
+
49
+ let(:correct) { FactoryGirl.build(:answer, :correct) }
50
+ let(:wrong) { FactoryGirl.build(:answer, :wrong) }
51
+ let(:answers) { [correct, wrong] }
52
+ let(:question){ FactoryGirl.build(:question, :answers => answers) }
53
+
54
+ end
55
+ end
@@ -0,0 +1,37 @@
1
+ require 'test_helper'
2
+
3
+ module Barker
4
+ class QuizTest < Spec
5
+
6
+ test "interface" do
7
+ Barker::Quiz.new(questions)
8
+ end
9
+
10
+ test "valid factory" do
11
+ assert FactoryGirl.build(:quiz).valid?
12
+ end
13
+
14
+ test "invalid factory" do
15
+ refute FactoryGirl.build(:quiz, :invalid).valid?
16
+ end
17
+
18
+ test "questions" do
19
+ assert_equal questions, FactoryGirl.build(:quiz, :questions => questions).questions
20
+ end
21
+
22
+ test "equality by questions" do
23
+ assert_equal FactoryGirl.build(:quiz, :questions => questions), FactoryGirl.build(:quiz, :questions => questions)
24
+ refute_equal FactoryGirl.build(:quiz, :questions => questions), FactoryGirl.build(:quiz, :questions => [FactoryGirl.build(:question)])
25
+ end
26
+
27
+ test "invalid if one or more questions are invalid" do
28
+ assert FactoryGirl.build(:quiz, :questions => [FactoryGirl.build(:question), FactoryGirl.build(:question)]).valid?
29
+ refute FactoryGirl.build(:quiz, :questions => [FactoryGirl.build(:question, :invalid), FactoryGirl.build(:question)]).valid?
30
+ end
31
+
32
+ private
33
+
34
+ let(:questions) { FactoryGirl.build_list(:question, 2) }
35
+
36
+ end
37
+ end
@@ -0,0 +1,54 @@
1
+ require 'test_helper'
2
+
3
+ module Barker
4
+ module Repo
5
+ module Memory
6
+ class GameShowTest < Spec
7
+
8
+ test "store" do
9
+ assert_kind_of Barker::Store::Memory, repo.send(:store)
10
+ end
11
+
12
+ test "add" do
13
+ refute game_show.id
14
+ repo.add(game_show)
15
+ assert game_show.id
16
+ end
17
+
18
+ test "get" do
19
+ repo.add game_show
20
+ assert_equal game_show, repo.get(game_show.id)
21
+ end
22
+
23
+ test "get unknown id" do
24
+ assert_raises Barker::Errors::RecordNotFound do
25
+ refute repo.get(nil)
26
+ end
27
+ end
28
+
29
+ test "update" do
30
+ refute game_show.started?
31
+ repo.add game_show
32
+ game_show.start
33
+ repo.update(game_show)
34
+ assert repo.get(game_show.id).started?
35
+ end
36
+
37
+ test "remove" do
38
+ repo.add game_show
39
+ assert repo.get(game_show.id)
40
+ repo.remove(game_show)
41
+ assert_raises Barker::Errors::RecordNotFound do
42
+ refute repo.get(game_show.id)
43
+ end
44
+ end
45
+
46
+ private
47
+
48
+ let(:repo) { Barker::Repo::Memory::GameShow.new }
49
+ let(:game_show) { FactoryGirl.build(:game_show) }
50
+
51
+ end
52
+ end
53
+ end
54
+ end