diff --git a/spec/requests/tags_spec.rb b/spec/requests/tags_spec.rb index 006f9b726..3c197e253 100644 --- a/spec/requests/tags_spec.rb +++ b/spec/requests/tags_spec.rb @@ -1,6 +1,6 @@ require "rails_helper" -RSpec.describe "Tags", type: :request do +RSpec.describe "Tags", type: :request, proper_status: true do describe "GET /tags" do it "returns proper page" do get "/tags" @@ -22,7 +22,8 @@ RSpec.describe "Tags", type: :request do it "does not allow users who are not tag moderators" do sign_in unauthorized_user - expect { get "/t/#{tag}/edit" }.to raise_error(Pundit::NotAuthorizedError) + get "/t/#{tag}/edit" + expect(response).to have_http_status(:not_found) end it "allows super admins" do @@ -43,7 +44,8 @@ RSpec.describe "Tags", type: :request do end it "does not allow moderators of one tag to edit another tag" do - expect { get "/t/#{another_tag}/edit" }.to raise_error(Pundit::NotAuthorizedError) + get "/t/#{another_tag}/edit" + expect(response).to have_http_status(:not_found) end end end @@ -63,7 +65,8 @@ RSpec.describe "Tags", type: :request do it "does not allow unauthorized users" do sign_in unauthorized_user - expect { patch "/tag/#{tag.id}" }.to raise_error(Pundit::NotAuthorizedError) + patch "/tag/#{tag.id}" + expect(response).to have_http_status(:not_found) end it "allows super admins" do @@ -92,8 +95,8 @@ RSpec.describe "Tags", type: :request do end it "does not allow moderators of one tag to edit another tag" do - expect { patch("/tag/#{another_tag.id}", params: valid_params) }. - to raise_error(Pundit::NotAuthorizedError) + patch("/tag/#{another_tag.id}", params: valid_params) + expect(response).to have_http_status(:not_found) end end end diff --git a/spec/support/shared_context.rb b/spec/support/shared_context.rb new file mode 100644 index 000000000..f983bdc63 --- /dev/null +++ b/spec/support/shared_context.rb @@ -0,0 +1,15 @@ +RSpec.shared_context "proper status" do + before do + Rails.application.env_config["action_dispatch.show_detailed_exceptions"] = false + Rails.application.env_config["action_dispatch.show_exceptions"] = true + end + + after do + Rails.application.env_config["action_dispatch.show_detailed_exceptions"] = true + Rails.application.env_config["action_dispatch.show_exceptions"] = false + end +end + +RSpec.configure do |rspec| + rspec.include_context "proper status", proper_status: true +end