Skip to content

Commit

Permalink
upgrade canvas_quiz_statistics to rspec 3 syntax
Browse files Browse the repository at this point in the history
refs CNVS-34040

test plan: specs should pass

Change-Id: Ic81ccbc5382dbc5c3b1e997281d2f988c7e350dc
Reviewed-on: https://gerrit.instructure.com/98413
Tested-by: Jenkins
Reviewed-by: Landon Wilkins <[email protected]>
Product-Review: Landon Wilkins <[email protected]>
QA-Review: Landon Wilkins <[email protected]>
  • Loading branch information
simonista committed Dec 27, 2016
1 parent b7fe665 commit e402017
Show file tree
Hide file tree
Showing 22 changed files with 193 additions and 197 deletions.
3 changes: 1 addition & 2 deletions gems/canvas_quiz_statistics/.rspec
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
--color
--format documentation
--require spec_helper
--format progress
3 changes: 2 additions & 1 deletion gems/canvas_quiz_statistics/canvas_quiz_statistics.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ Gem::Specification.new do |spec|

spec.add_development_dependency 'bundler', '~> 1.5'
spec.add_development_dependency 'rake'
spec.add_development_dependency 'rspec', "2.14.1"
spec.add_development_dependency 'rspec', "~> 3.5.0"
spec.add_development_dependency 'byebug'
spec.add_development_dependency 'guard'
spec.add_development_dependency 'guard-rspec'
spec.add_development_dependency 'terminal-notifier-guard'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Apple < Base
end
end

Apple.new({}).run([ {}, {} ]).should == { something: 2 }
expect(Apple.new({}).run([ {}, {} ])).to eq({ something: 2 })

unset Apple
end
Expand All @@ -38,8 +38,8 @@ class Orange < Base
end
end

Apple.new({}).run([{}]).should == { something: 1 }
Orange.new({}).run([{}]).should == { something_else: 1 }
expect(Apple.new({}).run([{}])).to eq({ something: 1 })
expect(Orange.new({}).run([{}])).to eq({ something_else: 1 })

unset Apple, Orange
end
Expand All @@ -58,7 +58,7 @@ def build_context(responses)

responses = [{ color: 'Red' }, { color: 'Green' }]

Apple.new({}).run(responses).should == { something: 'Red, Green' }
expect(Apple.new({}).run(responses)).to eq({ something: 'Red, Green' })

unset Apple
end
Expand All @@ -81,8 +81,8 @@ class Orange < Apple
end
end

Apple.new({}).run([{}]).should == { something: 1 }
Orange.new({}).run([{}]).should == { something: 1, something_else: 1 }
expect(Apple.new({}).run([{}])).to eq({ something: 1 })
expect(Orange.new({}).run([{}])).to eq({ something: 1, something_else: 1 })

unset Apple, Orange
end
Expand All @@ -104,8 +104,8 @@ class Orange < Apple
end
end

Apple.new({}).run([{}]).should == { something: 1 }
Orange.new({}).run([{}]).should == { something: 1, something_else: 1 }
expect(Apple.new({}).run([{}])).to eq({ something: 1 })
expect(Orange.new({}).run([{}])).to eq({ something: 1, something_else: 1 })

unset Apple, Orange
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
subject { described_class.new(question_data) }

it 'should not blow up when no responses are provided' do
expect { subject.run([]).should be_present }.to_not raise_error
expect { expect(subject.run([])).to be_present }.to_not raise_error
end

describe '[:graded]' do
Expand All @@ -15,7 +15,7 @@
{ correct: false }, { correct: 'false' }, {}
])

output[:graded].should == 2
expect(output[:graded]).to eq(2)
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

it 'should not blow up when no responses are provided' do
expect {
subject.run([]).should be_present
expect(subject.run([])).to be_present
}.to_not raise_error
end

Expand All @@ -15,13 +15,13 @@
describe 'output [#run]' do
describe '[:responses]' do
it 'should count students who have written anything' do
subject.run([{ text: 'foo' }])[:responses].should == 1
expect(subject.run([{ text: 'foo' }])[:responses]).to eq(1)
end

it 'should not count students who have written a blank response' do
subject.run([{ }])[:responses].should == 0
subject.run([{ text: nil }])[:responses].should == 0
subject.run([{ text: '' }])[:responses].should == 0
expect(subject.run([{ }])[:responses]).to eq(0)
expect(subject.run([{ text: nil }])[:responses]).to eq(0)
expect(subject.run([{ text: '' }])[:responses]).to eq(0)
end
end

Expand All @@ -30,7 +30,7 @@
{ correct: 'defined' }, { correct: 'undefined' }
])

output[:graded].should == 1
expect(output[:graded]).to eq(1)
end

describe ':full_credit' do
Expand All @@ -43,28 +43,28 @@
{ points: 3 }, { points: 2 }, { points: 3 }
])

output[:full_credit].should == 2
expect(output[:full_credit]).to eq(2)
end

it 'should count students who received more than full credit' do
output = subject.run([
{ points: 3 }, { points: 2 }, { points: 5 }
])

output[:full_credit].should == 2
expect(output[:full_credit]).to eq(2)
end

it 'should be 0 otherwise' do
output = subject.run([
{ points: 1 }
])

output[:full_credit].should == 0
expect(output[:full_credit]).to eq(0)
end

it 'should count those who exceed the maximum points possible' do
output = subject.run([{ points: 5 }])
output[:full_credit].should == 1
expect(output[:full_credit]).to eq(1)
end
end

Expand Down Expand Up @@ -93,22 +93,22 @@
bottom = answers[2]
expect(bottom[:responses]).to eq 2
expect(bottom[:user_names]).to include('Joe1')
expect(bottom[:full_credit]).to be_false
expect(bottom[:full_credit]).to be_falsey

middle = answers[1]
expect(middle[:responses]).to eq 5
expect(middle[:user_names]).to include('Joe6')
expect(middle[:full_credit]).to be_false
expect(middle[:full_credit]).to be_falsey

top = answers[0]
expect(top[:responses]).to eq 2
expect(top[:user_names]).to include('Joe10')
expect(top[:full_credit]).to be_true
expect(top[:full_credit]).to be_truthy

undefined = answers[3]
expect(undefined[:responses]).to eq 3
expect(undefined[:user_names].uniq).to eq ['Joe0']
expect(undefined[:full_credit]).to be_false
expect(undefined[:full_credit]).to be_falsey
end
end

Expand All @@ -120,9 +120,9 @@
{ points: nil, user_id: 5 }
])

output[:point_distribution].should include({ score: nil, count: 1 })
output[:point_distribution].should include({ score: 1, count: 1 })
output[:point_distribution].should include({ score: 3, count: 2 })
expect(output[:point_distribution]).to include({ score: nil, count: 1 })
expect(output[:point_distribution]).to include({ score: 1, count: 1 })
expect(output[:point_distribution]).to include({ score: 3, count: 2 })
end

it 'should sort them in score ascending mode' do
Expand All @@ -132,7 +132,7 @@
{ points: nil, user_id: 5 }
])

output[:point_distribution].map { |v| v[:score] }.should == [ nil, 1, 3 ]
expect(output[:point_distribution].map { |v| v[:score] }).to eq([ nil, 1, 3 ])
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@
subject { described_class.new(question_data) }

it 'should not blow up when no responses are provided' do
expect { subject.run([]).should be_present }.to_not raise_error
expect { expect(subject.run([])).to be_present }.to_not raise_error
end

describe '[:responses]' do
it 'should count students who have uploaded an attachment' do
subject.run([
expect(subject.run([
{},
{ attachment_ids: nil },
{ attachment_ids: [] },
{ attachment_ids: ['1'] }
])[:responses].should == 1
])[:responses]).to eq(1)
end
end
end
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
require 'spec_helper'

describe CanvasQuizStatistics::Analyzers::FillInMultipleBlanks do
Constants = CanvasQuizStatistics::Analyzers::Base::Constants

let(:question_data) { QuestionHelpers.fixture('fill_in_multiple_blanks_question') }
subject { described_class.new(question_data) }

Expand All @@ -24,7 +22,7 @@

answer_set = stats[:answer_sets].detect { |as| as[:text] == 'color1' }
answer = answer_set[:answers].detect { |a| a[:text] == 'Red' }
answer[:responses].should == 1
expect(answer[:responses]).to eq(1)
end

it 'should stringify ids' do
Expand All @@ -37,7 +35,7 @@

answer_set = stats[:answer_sets].detect { |as| as[:text] == 'color1' }
answer = answer_set[:answers].detect { |a| a[:text] == 'Red' }
answer[:responses].should == 1
expect(answer[:responses]).to eq(1)
end

it 'should count those who filled in an unknown answer' do
Expand All @@ -50,8 +48,8 @@

answer_set = stats[:answer_sets].detect { |as| as[:text] == 'color1' }
answer = answer_set[:answers].detect { |a| a[:id] == Constants::UnknownAnswerKey }
answer.should be_present
answer[:responses].should == 1
expect(answer).to be_present
expect(answer[:responses]).to eq(1)
end

it 'should count those who did not fill in any answer' do
Expand All @@ -64,8 +62,8 @@

answer_set = stats[:answer_sets].detect { |as| as[:text] == 'color1' }
answer = answer_set[:answers].detect { |a| a[:id] == Constants::MissingAnswerKey }
answer.should be_present
answer[:responses].should == 1
expect(answer).to be_present
expect(answer[:responses]).to eq(1)
end

it 'should not generate the unknown or missing answers unless needed' do
Expand All @@ -80,17 +78,17 @@
unknown_answer = answer_set[:answers].detect { |a| a[:id] == Constants::UnknownAnswerKey }
missing_answer = answer_set[:answers].detect { |a| a[:id] == Constants::MissingAnswerKey }

unknown_answer.should_not be_present
missing_answer.should_not be_present
expect(unknown_answer).not_to be_present
expect(missing_answer).not_to be_present
end

stats[:answer_sets].detect { |as| as[:text] == 'color2' }.tap do |answer_set|
unknown_answer = answer_set[:answers].detect { |a| a[:id] == Constants::UnknownAnswerKey }
missing_answer = answer_set[:answers].detect { |a| a[:id] == Constants::MissingAnswerKey }

unknown_answer.should_not be_present
missing_answer.should be_present
missing_answer[:responses].should == 1
expect(unknown_answer).not_to be_present
expect(missing_answer).to be_present
expect(missing_answer[:responses]).to eq(1)
end
end
end
Expand All @@ -108,21 +106,21 @@
}
])

stats[:responses].should == 1
expect(stats[:responses]).to eq(1)
end

it 'should not count students who didnt' do
subject.run([{}])[:responses].should == 0
expect(subject.run([{}])[:responses]).to eq(0)
end

it "should not consider an answer to be present if it's empty" do
subject.run([{
expect(subject.run([{
answer_for_color: ''
}])[:responses].should == 0
}])[:responses]).to eq(0)

subject.run([{
expect(subject.run([{
answer_for_color: nil
}])[:responses].should == 0
}])[:responses]).to eq(0)
end
end

Expand All @@ -135,7 +133,7 @@
}
])

stats[:answered].should == 1
expect(stats[:answered]).to eq(1)
end

it 'should count students who have filled every blank, even if incorrectly' do
Expand All @@ -146,7 +144,7 @@
}
])

stats[:answered].should == 1
expect(stats[:answered]).to eq(1)
end

it 'should not count a student who has left any blank' do
Expand All @@ -156,7 +154,7 @@
}
])

stats[:answered].should == 0
expect(stats[:answered]).to eq(0)
end
end
end
Loading

0 comments on commit e402017

Please sign in to comment.