@@ -229,38 +229,37 @@ def expect_alternative(trial, alternative_name)
229229 end
230230
231231 describe "#complete!" do
232- let ( :trial ) { Split ::Trial . new ( :user => user , :experiment => experiment ) }
233232 context 'when there are no goals' do
233+ let ( :trial ) { Split ::Trial . new ( :user => user , :experiment => experiment ) }
234234 it 'should complete the trial' do
235235 trial . choose!
236236 old_completed_count = trial . alternative . completed_count
237237 trial . complete!
238- expect ( trial . alternative . completed_count ) . to be ( old_completed_count + 1 )
238+ expect ( trial . alternative . completed_count ) . to eq ( old_completed_count + 1 )
239239 end
240240 end
241241
242- context ' when there are many goals' do
243- let ( :goals ) { [ 'first' , 'second' ] }
242+ context " when there are many goals" do
243+ let ( :goals ) { [ "goal1" , "goal2" ] }
244244 let ( :trial ) { Split ::Trial . new ( :user => user , :experiment => experiment , :goals => goals ) }
245- shared_examples_for "goal completion" do
246- it 'should not complete the trial' do
247- trial . choose!
248- old_completed_count = trial . alternative . completed_count
249- trial . complete! ( goal )
250- expect ( trial . alternative . completed_count ) . to_not be ( old_completed_count +1 )
251- end
252- end
253245
254- describe 'Array of Goals' do
255- let ( :goal ) { [ goals . first ] }
256- it_behaves_like 'goal completion'
246+ it "increments the completed count corresponding to the goals" do
247+ trial . choose!
248+ old_completed_counts = goals . map { |goal | [ goal , trial . alternative . completed_count ( goal ) ] } . to_h
249+ trial . complete!
250+ goals . each { | goal | expect ( trial . alternative . completed_count ( goal ) ) . to eq ( old_completed_counts [ goal ] + 1 ) }
257251 end
252+ end
258253
259- describe 'String of Goal' do
260- let ( :goal ) { goals . first }
261- it_behaves_like 'goal completion'
254+ context "when there is 1 goal of type string" do
255+ let ( :goal ) { "goal" }
256+ let ( :trial ) { Split ::Trial . new ( :user => user , :experiment => experiment , :goals => goal ) }
257+ it "increments the completed count corresponding to the goal" do
258+ trial . choose!
259+ old_completed_count = trial . alternative . completed_count ( goal )
260+ trial . complete!
261+ expect ( trial . alternative . completed_count ( goal ) ) . to eq ( old_completed_count + 1 )
262262 end
263-
264263 end
265264 end
266265
0 commit comments