diff --git a/spec/controllers/exercises_controller_spec.rb b/spec/controllers/exercises_controller_spec.rb index a5330424..fe79e849 100644 --- a/spec/controllers/exercises_controller_spec.rb +++ b/spec/controllers/exercises_controller_spec.rb @@ -414,11 +414,11 @@ describe ExercisesController do it 'renders the correct contents as json' do post_request - expect(JSON.parse(response.body).symbolize_keys[:message]).to eq('message') - expect(JSON.parse(response.body).symbolize_keys[:actions]).to( + expect(response.parsed_body.symbolize_keys[:message]).to eq('message') + expect(response.parsed_body.symbolize_keys[:actions]).to( include('button').and(include('Abort').and(include('Export'))) ) - expect(JSON.parse(response.body).symbolize_keys[:actions]).to( + expect(response.parsed_body.symbolize_keys[:actions]).to( not_include('Retry').and(not_include('Hide')) ) end @@ -428,11 +428,11 @@ describe ExercisesController do it 'renders the correct contents as json' do post_request - expect(JSON.parse(response.body).symbolize_keys[:message]).to eq('message') - expect(JSON.parse(response.body).symbolize_keys[:actions]).to( + expect(response.parsed_body.symbolize_keys[:message]).to eq('message') + expect(response.parsed_body.symbolize_keys[:actions]).to( include('button').and(include('Abort')).and(include('Retry')) ) - expect(JSON.parse(response.body).symbolize_keys[:actions]).to( + expect(response.parsed_body.symbolize_keys[:actions]).to( not_include('Export').and(not_include('Hide')) ) end @@ -443,11 +443,11 @@ describe ExercisesController do it 'renders the correct contents as json' do post_request - expect(JSON.parse(response.body).symbolize_keys[:message]).to eq('message') - expect(JSON.parse(response.body).symbolize_keys[:actions]).to( + expect(response.parsed_body.symbolize_keys[:message]).to eq('message') + expect(response.parsed_body.symbolize_keys[:actions]).to( include('button').and(include('Abort')) ) - expect(JSON.parse(response.body).symbolize_keys[:actions]).to( + expect(response.parsed_body.symbolize_keys[:actions]).to( not_include('Retry').and(not_include('Export')).and(not_include('Hide')) ) end @@ -471,10 +471,10 @@ describe ExercisesController do post_request expect(response).to have_http_status(:success) - expect(JSON.parse(response.body).symbolize_keys[:message]).to(include('successfully exported')) - expect(JSON.parse(response.body).symbolize_keys[:status]).to(eql('success')) - expect(JSON.parse(response.body).symbolize_keys[:actions]).to(include('button').and(include('Close'))) - expect(JSON.parse(response.body).symbolize_keys[:actions]).to(not_include('Retry').and(not_include('Abort'))) + expect(response.parsed_body.symbolize_keys[:message]).to(include('successfully exported')) + expect(response.parsed_body.symbolize_keys[:status]).to(eql('success')) + expect(response.parsed_body.symbolize_keys[:actions]).to(include('button').and(include('Close'))) + expect(response.parsed_body.symbolize_keys[:actions]).to(not_include('Retry').and(not_include('Abort'))) end context 'when an error occurs' do @@ -483,10 +483,10 @@ describe ExercisesController do it 'renders correct response' do post_request expect(response).to have_http_status(:success) - expect(JSON.parse(response.body).symbolize_keys[:message]).to(include('failed').and(include('exampleerror'))) - expect(JSON.parse(response.body).symbolize_keys[:status]).to(eql('fail')) - expect(JSON.parse(response.body).symbolize_keys[:actions]).to(include('button').and(include('Retry')).and(include('Close'))) - expect(JSON.parse(response.body).symbolize_keys[:actions]).to(not_include('Abort')) + expect(response.parsed_body.symbolize_keys[:message]).to(include('failed').and(include('exampleerror'))) + expect(response.parsed_body.symbolize_keys[:status]).to(eql('fail')) + expect(response.parsed_body.symbolize_keys[:actions]).to(include('button').and(include('Retry')).and(include('Close'))) + expect(response.parsed_body.symbolize_keys[:actions]).to(not_include('Abort')) end end end @@ -504,8 +504,8 @@ describe ExercisesController do post_request expect(response).to have_http_status(:success) - expect(JSON.parse(response.body).symbolize_keys[:uuid_found]).to be true - expect(JSON.parse(response.body).symbolize_keys[:update_right]).to be true + expect(response.parsed_body.symbolize_keys[:uuid_found]).to be true + expect(response.parsed_body.symbolize_keys[:update_right]).to be true end context 'when api_key is incorrect' do @@ -524,8 +524,8 @@ describe ExercisesController do post_request expect(response).to have_http_status(:success) - expect(JSON.parse(response.body).symbolize_keys[:uuid_found]).to be true - expect(JSON.parse(response.body).symbolize_keys[:update_right]).to be false + expect(response.parsed_body.symbolize_keys[:uuid_found]).to be true + expect(response.parsed_body.symbolize_keys[:update_right]).to be false end end @@ -536,7 +536,7 @@ describe ExercisesController do post_request expect(response).to have_http_status(:success) - expect(JSON.parse(response.body).symbolize_keys[:uuid_found]).to be false + expect(response.parsed_body.symbolize_keys[:uuid_found]).to be false end end end diff --git a/spec/controllers/submissions_controller_spec.rb b/spec/controllers/submissions_controller_spec.rb index efa28cfb..cecf7732 100644 --- a/spec/controllers/submissions_controller_spec.rb +++ b/spec/controllers/submissions_controller_spec.rb @@ -192,7 +192,7 @@ describe SubmissionsController do %i[run test].each do |action| describe "##{action}_url" do - let(:url) { JSON.parse(response.body).with_indifferent_access.fetch("#{action}_url") } + let(:url) { response.parsed_body.with_indifferent_access.fetch("#{action}_url") } it "starts like the #{action} path" do filename = File.basename(__FILE__) @@ -206,7 +206,7 @@ describe SubmissionsController do end describe '#render_url' do - let(:supported_urls) { JSON.parse(response.body).with_indifferent_access.fetch('render_url') } + let(:supported_urls) { response.parsed_body.with_indifferent_access.fetch('render_url') } let(:file) { submission.collect_files.detect(&:main_file?) } let(:url) { supported_urls.find {|hash| hash[:filepath] == file.filepath }['url'] } @@ -220,7 +220,7 @@ describe SubmissionsController do end describe '#score_url' do - let(:url) { JSON.parse(response.body).with_indifferent_access.fetch('score_url') } + let(:url) { response.parsed_body.with_indifferent_access.fetch('score_url') } it 'corresponds to the score path' do expect(url).to eq(Rails.application.routes.url_helpers.score_submission_path(submission, format: :json))