Defining methods inside RSpec.configure blocks still defines them on Object. Use config.include with a module to define these only in the specs and not globally. For matcher methods, define them in RSpec::Matchers::DSL::Matcher. Change rubocop config to allow this inside of the RSpec.configure blocks (technically, any constant inside any block). Add an Object.method_added hook that raises an exception if defining a method on object, other than Nokogiri, which is defined by the nokogiri gem. This will result in the specs raising an error without executing anything if you attempt to define a method on Object.
35 lines
948 B
Ruby
35 lines
948 B
Ruby
# frozen_string_literal: true
|
|
|
|
require_relative "../spec_helper"
|
|
|
|
RSpec.configure do |config|
|
|
config.include(Module.new do
|
|
def login_api
|
|
@use_pat = true
|
|
end
|
|
|
|
def project_with_default_policy(account, name: "project-1")
|
|
project = account.create_project_with_default_policy(name)
|
|
|
|
if @use_pat
|
|
@pat = account.api_keys.first || ApiKey.create_personal_access_token(account, project:)
|
|
header "Authorization", "Bearer pat-#{@pat.ubid}-#{@pat.key}"
|
|
SubjectTag.first(project_id: project.id, name: "Admin").add_subject(@pat.id)
|
|
end
|
|
|
|
project
|
|
end
|
|
end)
|
|
|
|
config.define_derived_metadata(file_path: %r{\A\./spec/routes/api/}) do |metadata|
|
|
metadata[:clover_api] = true
|
|
end
|
|
|
|
config.before do |example|
|
|
next unless example.metadata[:clover_api]
|
|
header "Host", "api.ubicloud.com"
|
|
header "Content-Type", "application/json"
|
|
header "Accept", "application/json"
|
|
end
|
|
end
|