diff --git a/backend/spec/requests/api/v1/hello_word_request_spec.rb b/backend/spec/requests/api/v1/hello_word_request_spec.rb index 93df43b..1187190 100644 --- a/backend/spec/requests/api/v1/hello_word_request_spec.rb +++ b/backend/spec/requests/api/v1/hello_word_request_spec.rb @@ -18,19 +18,7 @@ describe "GET /api/v1/private_method" do let(:user) { create(:user) } - context "when user is not authenticated" do - before do - get "/api/v1/private_method" - end - - it "renders json with message" do - expect(response.body).to include("error", "Invalid token") - end - - it "receives http status unauthorized" do - expect(response).to have_http_status(:unauthorized) - end - end + include_context "when user is not authenticated" context "when user is authenticated" do let(:instance_token) { Devise::Api::TokensService::Create.new(resource_owner: user, previous_refresh_token: nil) } diff --git a/backend/spec/support/shared_examples/requests.rb b/backend/spec/support/shared_examples/requests.rb new file mode 100644 index 0000000..edaed10 --- /dev/null +++ b/backend/spec/support/shared_examples/requests.rb @@ -0,0 +1,13 @@ +RSpec.shared_context "when user is not authenticated" do + before do + get "/api/v1/private_method" + end + + it "renders json with message" do + expect(response.body).to include("error", "Invalid token") + end + + it "receives http status unauthorized" do + expect(response).to have_http_status(:unauthorized) + end +end