Skip to content

Commit fb9b4f2

Browse files
committed
Use bundle exec for executable tests
`bundle install` installs executables from local source: ``` Using json_schemer 1.0.3 from source at `.` and installing its executables ``` Using `bundle exec` makes it easier to test things when switching between Ruby versions since it's not necessary to rebuild the gem manually. Ruby 2.5 emits a warning about RubyGems that I had to strip to get tests to pass.
1 parent a1c12c0 commit fb9b4f2

File tree

2 files changed

+5
-15
lines changed

2 files changed

+5
-15
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,4 @@ jobs:
1919
with:
2020
ruby-version: ${{ matrix.ruby }}
2121
bundler-cache: true
22-
- run: |
23-
mkdir -p tmp/gems
24-
gem build json_schemer.gemspec
25-
gem install --local --ignore-dependencies --no-document --install-dir tmp/gems json_schemer-*.gem
26-
rm json_schemer-*.gem
27-
bin/rake test
22+
- run: bin/rake test

test/exe_test.rb

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,14 @@
22
require 'open3'
33

44
class ExeTest < Minitest::Test
5-
GEM_PATH = File.join(__dir__, '..', 'tmp', 'gems')
6-
CMD = File.join(GEM_PATH, 'bin', 'json_schemer')
75
SCHEMA1 = File.join(__dir__, 'schemas', 'schema1.json')
86
VALID = { 'id' => 1, 'a' => 'valid' }
97
INVALID1 = { 'a' => 'invalid' }
108
INVALID2 = { 'id' => 1 }
119
INVALID3 = { 'id' => 1, 'a' => -1 }
1210
INVALID4 = { 'id' => 'invalid', 'a' => 'valid' }
1311
INVALID5 = { 'x' => 'invalid' }
12+
RUBY_2_5_WARNING_REGEX = /Your RubyGems version \([\d\.]+\) has a bug that prevents `required_ruby_version` from working for Bundler. Any scripts that use `gem install bundler` will break as soon as Bundler drops support for your Ruby version. Please upgrade RubyGems to avoid future breakage and silence this warning by running `gem update --system [\d\.]+`\n/
1413

1514
def test_help
1615
stdout, stderr, status = exe('-h')
@@ -175,13 +174,9 @@ def test_stdin
175174
private
176175

177176
def exe(*args, **kwargs)
178-
env = {
179-
'GEM_HOME' => Gem.dir,
180-
'GEM_PATH' => [GEM_PATH, *Gem.path].uniq.join(File::PATH_SEPARATOR),
181-
'GEM_SPEC_CACHE' => Gem.spec_cache_dir,
182-
'RUBYOPT' => nil # prevent bundler/setup
183-
}
184-
Open3.capture3(env, CMD, *args, **kwargs)
177+
Open3.capture3('bundle', 'exec', 'json_schemer', *args, **kwargs).tap do |_stdout, stderr, _status|
178+
stderr.gsub!(RUBY_2_5_WARNING_REGEX, '') if RUBY_ENGINE == 'ruby' && RUBY_VERSION.match?(/\A2\.5\.\d+\z/)
179+
end
185180
end
186181

187182
def tmp_json(*json)

0 commit comments

Comments
 (0)