diff options
Diffstat (limited to 'spec/support')
-rw-r--r-- | spec/support/api/schema_matcher.rb | 24 | ||||
-rw-r--r-- | spec/support/helpers/graphql_helpers.rb | 10 | ||||
-rw-r--r-- | spec/support/helpers/stub_object_storage.rb | 12 | ||||
-rw-r--r-- | spec/support/helpers/test_env.rb | 10 |
4 files changed, 32 insertions, 24 deletions
diff --git a/spec/support/api/schema_matcher.rb b/spec/support/api/schema_matcher.rb index f7d74df0656..4cf34d43117 100644 --- a/spec/support/api/schema_matcher.rb +++ b/spec/support/api/schema_matcher.rb @@ -1,10 +1,16 @@ module SchemaPath - def self.expand(schema, dir = '') - Rails.root.join(dir, 'spec', "fixtures/api/schemas/#{schema}.json").to_s + def self.expand(schema, dir = nil) + if Gitlab.ee? && dir.nil? + ee_path = expand(schema, 'ee') + + return ee_path if File.exist?(ee_path) + end + + Rails.root.join(dir.to_s, 'spec', "fixtures/api/schemas/#{schema}.json").to_s end end -RSpec::Matchers.define :match_response_schema do |schema, dir: '', **options| +RSpec::Matchers.define :match_response_schema do |schema, dir: nil, **options| match do |response| @errors = JSON::Validator.fully_validate( SchemaPath.expand(schema, dir), response.body, options) @@ -18,8 +24,16 @@ RSpec::Matchers.define :match_response_schema do |schema, dir: '', **options| end end -RSpec::Matchers.define :match_schema do |schema, dir: '', **options| +RSpec::Matchers.define :match_schema do |schema, dir: nil, **options| match do |data| - JSON::Validator.validate!(SchemaPath.expand(schema, dir), data, options) + @errors = JSON::Validator.fully_validate( + SchemaPath.expand(schema, dir), data, options) + + @errors.empty? + end + + failure_message do |response| + "didn't match the schema defined by #{SchemaPath.expand(schema, dir)}" \ + " The validation errors were:\n#{@errors.join("\n")}" end end diff --git a/spec/support/helpers/graphql_helpers.rb b/spec/support/helpers/graphql_helpers.rb index 6cdc19ac2e5..ca28325eab9 100644 --- a/spec/support/helpers/graphql_helpers.rb +++ b/spec/support/helpers/graphql_helpers.rb @@ -18,12 +18,10 @@ module GraphqlHelpers # Runs a block inside a BatchLoader::Executor wrapper def batch(max_queries: nil, &blk) wrapper = proc do - begin - BatchLoader::Executor.ensure_current - yield - ensure - BatchLoader::Executor.clear_current - end + BatchLoader::Executor.ensure_current + yield + ensure + BatchLoader::Executor.clear_current end if max_queries diff --git a/spec/support/helpers/stub_object_storage.rb b/spec/support/helpers/stub_object_storage.rb index e0c50e533a6..30c8477f16a 100644 --- a/spec/support/helpers/stub_object_storage.rb +++ b/spec/support/helpers/stub_object_storage.rb @@ -23,15 +23,13 @@ module StubObjectStorage Fog.mock! ::Fog::Storage.new(connection_params).tap do |connection| - begin - connection.directories.create(key: remote_directory) + connection.directories.create(key: remote_directory) - # Cleanup remaining files - connection.directories.each do |directory| - directory.files.map(&:destroy) - end - rescue Excon::Error::Conflict + # Cleanup remaining files + connection.directories.each do |directory| + directory.files.map(&:destroy) end + rescue Excon::Error::Conflict end end diff --git a/spec/support/helpers/test_env.rb b/spec/support/helpers/test_env.rb index 80a22134021..dc902d373b8 100644 --- a/spec/support/helpers/test_env.rb +++ b/spec/support/helpers/test_env.rb @@ -202,12 +202,10 @@ module TestEnv socket = Gitlab::GitalyClient.address('default').sub('unix:', '') Integer(sleep_time / sleep_interval).times do - begin - Socket.unix(socket) - return - rescue - sleep sleep_interval - end + Socket.unix(socket) + return + rescue + sleep sleep_interval end raise "could not connect to gitaly at #{socket.inspect} after #{sleep_time} seconds" |