diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 661615a4..71d1f67e 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' ENV['RAILS_ENV'] ||= 'test' require_relative '../config/environment' @@ -6,7 +8,7 @@ abort('The Rails environment is running in production mode!') if Rails.env.produ require 'rspec/rails' # Add additional requires below this line. Rails is not loaded until this point! -Dir[Rails.root.join('spec', 'support', '**', '*.rb')].sort.each { |f| require f } +Dir[Rails.root.join('spec/support/**/*.rb')].sort.each { |f| require f } # Checks for pending migrations and applies them before tests are run. # If you are not using ActiveRecord, you can remove these lines. diff --git a/spec/requests/export_spec.rb b/spec/requests/export_spec.rb index 9bf49c4c..9957bee9 100644 --- a/spec/requests/export_spec.rb +++ b/spec/requests/export_spec.rb @@ -1,13 +1,18 @@ +# frozen_string_literal: true + require 'rails_helper' -RSpec.describe "Exports", type: :request do - describe "GET /create" do +RSpec.describe 'Exports', type: :request do + describe 'GET /create' do before do + stub_request(:any, 'https://api.github.com/repos/Freika/dawarich/tags') + .to_return(status: 200, body: '[{"name": "1.0.0"}]', headers: {}) + sign_in create(:user) end - it "returns http success" do - get "/export" + it 'returns http success' do + get '/export' expect(response).to have_http_status(:success) end end diff --git a/spec/requests/home_spec.rb b/spec/requests/home_spec.rb index 21901b89..ade7de88 100644 --- a/spec/requests/home_spec.rb +++ b/spec/requests/home_spec.rb @@ -1,9 +1,14 @@ require 'rails_helper' -RSpec.describe "Homes", type: :request do - describe "GET /" do - it "returns http success" do - get "/" +RSpec.describe 'Homes', type: :request do + describe 'GET /' do + before do + stub_request(:any, 'https://api.github.com/repos/Freika/dawarich/tags') + .to_return(status: 200, body: '[{"name": "1.0.0"}]', headers: {}) + end + + it 'returns http success' do + get '/' expect(response).to have_http_status(:success) end end diff --git a/spec/requests/imports_spec.rb b/spec/requests/imports_spec.rb index edc2e08e..7fb2144c 100644 --- a/spec/requests/imports_spec.rb +++ b/spec/requests/imports_spec.rb @@ -1,7 +1,12 @@ require 'rails_helper' -RSpec.describe "Imports", type: :request do - describe "GET /imports" do +RSpec.describe 'Imports', type: :request do + before do + stub_request(:any, 'https://api.github.com/repos/Freika/dawarich/tags') + .to_return(status: 200, body: '[{"name": "1.0.0"}]', headers: {}) + end + + describe 'GET /imports' do context 'when user is logged in' do let(:user) { create(:user) } @@ -9,7 +14,7 @@ RSpec.describe "Imports", type: :request do sign_in user end - it "returns http success" do + it 'returns http success' do get imports_path expect(response).to have_http_status(200) @@ -27,7 +32,7 @@ RSpec.describe "Imports", type: :request do end end - describe "POST /imports" do + describe 'POST /imports' do context 'when user is logged in' do let(:user) { create(:user) } let(:file) { fixture_file_upload('owntracks/export.json', 'application/json') } diff --git a/spec/requests/points_spec.rb b/spec/requests/points_spec.rb index 7d9f2705..56b96bd3 100644 --- a/spec/requests/points_spec.rb +++ b/spec/requests/points_spec.rb @@ -1,13 +1,20 @@ +# frozen_string_literal: true + require 'rails_helper' -RSpec.describe "Points", type: :request do - describe "GET /index" do +RSpec.describe 'Points', type: :request do + before do + stub_request(:any, 'https://api.github.com/repos/Freika/dawarich/tags') + .to_return(status: 200, body: '[{"name": "1.0.0"}]', headers: {}) + end + + describe 'GET /index' do context 'when user signed in' do before do sign_in create(:user) end - it "returns http success" do + it 'returns http success' do get points_path expect(response).to have_http_status(:success) @@ -15,7 +22,7 @@ RSpec.describe "Points", type: :request do end context 'when user not signed in' do - it "returns http success" do + it 'returns http success' do get points_path expect(response).to have_http_status(302) diff --git a/spec/requests/stats_spec.rb b/spec/requests/stats_spec.rb index ac3a7849..0b57f02d 100644 --- a/spec/requests/stats_spec.rb +++ b/spec/requests/stats_spec.rb @@ -1,9 +1,15 @@ +# frozen_string_literal: true + require 'rails_helper' -RSpec.describe "/stats", type: :request do +RSpec.describe '/stats', type: :request do + before do + stub_request(:any, 'https://api.github.com/repos/Freika/dawarich/tags') + .to_return(status: 200, body: '[{"name": "1.0.0"}]', headers: {}) + end - describe "GET /index" do - it "renders a successful response" do + describe 'GET /index' do + it 'renders a successful response' do get stats_url expect(response.status).to eq(302) end diff --git a/spec/support/devise.rb b/spec/support/devise.rb index b5aa99b4..5d8bf8de 100644 --- a/spec/support/devise.rb +++ b/spec/support/devise.rb @@ -8,14 +8,13 @@ module DeviseRequestSpecHelpers def sign_in(resource_or_scope, resource = nil) resource ||= resource_or_scope scope = Devise::Mapping.find_scope!(resource_or_scope) - login_as(resource, scope: scope) + login_as(resource, scope:) end def sign_out(resource_or_scope) scope = Devise::Mapping.find_scope!(resource_or_scope) logout(scope) end - end RSpec.configure do |config|