summaryrefslogtreecommitdiff
path: root/spec/support/integration_specs.rb
blob: 431167d77a0fb5fe3d3288aad5d71bf15ce1811d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
require File.expand_path('../../../lib/hashie/extensions/ruby_version', __FILE__)

# Generates the bundle command for running an integration test
#
# @param [String] integration the integration folder to run
# @param [String] command the command to run
# @return [String]
def integration_command(integration, command)
  if Hashie::Extensions::RubyVersion.new(RUBY_VERSION) >=
     Hashie::Extensions::RubyVersion.new('3.1.0')
     ruby_opts = "RUBYOPT=--disable-error_highlight "
  end

  "#{ruby_opts}#{integration_gemfile(integration)} #{command}"
end

# Generates the Gemfile for an integration
#
# @param [String] integration the integration test name
# @return [String]
def integration_gemfile(integration)
  "BUNDLE_GEMFILE=#{integration_path(integration)}/Gemfile"
end

# Generates the path to the integration
#
# @param [String] integration the integration test name
# @return [String]
def integration_path(integration)
  "spec/integration/#{integration}"
end

# Runs all integration specs in their own environment
def run_all_integration_specs(handler: ->(_code) {}, logger: ->(_msg) {})
  Dir['spec/integration/*']
    .map { |directory| directory.split('/').last }
    .each do |integration|
      logger.call(%(Running "#{integration}" integration spec))
      system(integration_command(integration, 'bundle --quiet'))
      system(integration_command(integration, "bundle exec rspec #{integration_path(integration)}"))
      handler.call($CHILD_STATUS.exitstatus)
    end
end