added tests

This commit is contained in:
Hauke Klement
2015-02-23 17:37:48 +01:00
parent f3c5d17662
commit 821b911ebb

View File

@ -107,48 +107,56 @@ describe Lti do
let(:consumer) { FactoryGirl.create(:consumer) }
let(:score) { 0.5 }
context 'with a tool provider' do
before(:each) do
controller.session[:consumer_id] = consumer.id
controller.session[:lti_parameters] = {}
end
context 'when grading is not supported' do
it 'returns a corresponding status' do
expect_any_instance_of(IMS::LTI::ToolProvider).to receive(:outcome_service?).and_return(false)
expect(controller.send(:send_score, score)[:status]).to eq('unsupported')
end
end
context 'when grading is supported' do
let(:response) { double }
before(:each) do
expect_any_instance_of(IMS::LTI::ToolProvider).to receive(:outcome_service?).and_return(true)
expect_any_instance_of(IMS::LTI::ToolProvider).to receive(:post_replace_result!).with(score).and_return(response)
expect(response).to receive(:response_code).at_least(:once).and_return(200)
expect(response).to receive(:post_response).and_return(response)
expect(response).to receive(:body).at_least(:once).and_return('')
expect(response).to receive(:code_major).at_least(:once).and_return('success')
end
it 'sends the score' do
controller.send(:send_score, score)
end
it 'returns code, message, and status' do
result = controller.send(:send_score, score)
expect(result[:code]).to eq(response.response_code)
expect(result[:message]).to eq(response.body)
expect(result[:status]).to eq(response.code_major)
end
context 'with an invalid score' do
it 'raises an exception' do
expect { controller.send(:send_score, Lti::MAXIMUM_SCORE * 2) }.to raise_error(Lti::Error)
end
end
context 'without a tool provider' do
it 'returns a corresponding status' do
expect(controller).to receive(:build_tool_provider).and_return(nil)
expect(controller.send(:send_score, score)[:status]).to eq('error')
context 'with an valid score' do
context 'with a tool provider' do
before(:each) do
controller.session[:consumer_id] = consumer.id
controller.session[:lti_parameters] = {}
end
context 'when grading is not supported' do
it 'returns a corresponding status' do
expect_any_instance_of(IMS::LTI::ToolProvider).to receive(:outcome_service?).and_return(false)
expect(controller.send(:send_score, score)[:status]).to eq('unsupported')
end
end
context 'when grading is supported' do
let(:response) { double }
before(:each) do
expect_any_instance_of(IMS::LTI::ToolProvider).to receive(:outcome_service?).and_return(true)
expect_any_instance_of(IMS::LTI::ToolProvider).to receive(:post_replace_result!).with(score).and_return(response)
expect(response).to receive(:response_code).at_least(:once).and_return(200)
expect(response).to receive(:post_response).and_return(response)
expect(response).to receive(:body).at_least(:once).and_return('')
expect(response).to receive(:code_major).at_least(:once).and_return('success')
end
it 'sends the score' do
controller.send(:send_score, score)
end
it 'returns code, message, and status' do
result = controller.send(:send_score, score)
expect(result[:code]).to eq(response.response_code)
expect(result[:message]).to eq(response.body)
expect(result[:status]).to eq(response.code_major)
end
end
end
context 'without a tool provider' do
it 'returns a corresponding status' do
expect(controller).to receive(:build_tool_provider).and_return(nil)
expect(controller.send(:send_score, score)[:status]).to eq('error')
end
end
end
end