summaryrefslogtreecommitdiff
path: root/spec/support/shared/matchers/match_environment_variable.rb
blob: 393775ea291b007df226b3e20a5acdc7bac03663 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

require "rspec/expectations"
require "spec/support/platform_helpers"

RSpec::Matchers.define :match_environment_variable do |varname|
  match do |actual|
    expected = if windows? && ENV[varname].nil?
                 # On Windows, if an environment variable is not set, the command
                 # `echo %VARNAME%` outputs %VARNAME%
                 "%#{varname}%"
               else
                 ENV[varname].to_s
               end

    actual == expected
  end
end