Skip to content

Commit

Permalink
Merge pull request textmate#121 from die-antwort/fix-120
Browse files Browse the repository at this point in the history
  • Loading branch information
noniq authored Aug 8, 2018
2 parents 7471355 + d5aa369 commit 9e70114
Show file tree
Hide file tree
Showing 9 changed files with 93 additions and 45 deletions.
5 changes: 5 additions & 0 deletions Support/Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# This Gemfile is only required for running the tests.

source "https://rubygems.org"

gem "minitest", "~> 5.11"
13 changes: 13 additions & 0 deletions Support/Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
GEM
remote: https://rubygems.org/
specs:
minitest (5.11.3)

PLATFORMS
ruby

DEPENDENCIES
minitest (~> 5.11)

BUNDLED WITH
1.16.2
5 changes: 2 additions & 3 deletions Support/lib/executable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ class << self
# → `TM_RSPEC` etc. Alternatively, you can use the `env_var` argument
# to explicitly specify the name.)
# 2. If a binstub (`bin/name`) exists, it is returned.
# 3. If a Gemfile.lock exists and has an entry for `name`, `[bundle exec
# name]` is returned.
# 3. If a Gemfile exists, `[bundle exec name]` is returned.
# 4. If `name` is found in the search path, it is returned. (Special case:
# If `name` looks like an rbenv shim, also check if the executable has
# been installed for the current Ruby version.)
Expand Down Expand Up @@ -71,7 +70,7 @@ def find(name, env_var = nil)
elsif File.exist?("bin/#{name}")
prefix + ["bin/#{name}"]

elsif File.exist?('Gemfile.lock') && File.read('Gemfile.lock') =~ /^ #{name} /
elsif File.exist?('Gemfile')
prefix + %W(bundle exec #{name})

elsif (path = `#{prefix.map(&:shellescape).join(' ')} which #{name}`.chomp) != ''
Expand Down
40 changes: 0 additions & 40 deletions Support/test/fixtures/sample_project/Gemfile.lock

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
source 'https://rubygems.org'

gem 'rubocop'
gem 'rspec'
gem 'rspec-core'
33 changes: 33 additions & 0 deletions Support/test/fixtures/sample_project_with_gemfile/Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
GEM
remote: https://rubygems.org/
specs:
ast (2.4.0)
jaro_winkler (1.5.1)
parallel (1.12.1)
parser (2.5.1.2)
ast (~> 2.4.0)
powerpack (0.1.2)
rainbow (3.0.0)
rspec-core (3.7.1)
rspec-support (~> 3.7.0)
rspec-support (3.7.1)
rubocop (0.58.2)
jaro_winkler (~> 1.5.1)
parallel (~> 1.10)
parser (>= 2.5, != 2.5.1.1)
powerpack (~> 0.1)
rainbow (>= 2.2.2, < 4.0)
ruby-progressbar (~> 1.7)
unicode-display_width (~> 1.0, >= 1.0.1)
ruby-progressbar (1.9.0)
unicode-display_width (1.4.0)

PLATFORMS
ruby

DEPENDENCIES
rspec-core
rubocop

BUNDLED WITH
1.16.2
17 changes: 17 additions & 0 deletions Support/test/fixtures/sample_project_with_gemfile/bin/rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env ruby
# frozen_string_literal: true
#
# This file was generated by Bundler.
#
# The application 'rspec' is installed as part of a gem, and
# this file is here to facilitate running it.
#

require "pathname"
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
Pathname.new(__FILE__).realpath)

require "rubygems"
require "bundler/setup"

load Gem.bin_path("rspec-core", "rspec")
17 changes: 17 additions & 0 deletions Support/test/fixtures/sample_project_with_gemfile/other/rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env ruby
# frozen_string_literal: true
#
# This file was generated by Bundler.
#
# The application 'rspec' is installed as part of a gem, and
# this file is here to facilitate running it.
#

require "pathname"
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
Pathname.new(__FILE__).realpath)

require "rubygems"
require "bundler/setup"

load Gem.bin_path("rspec-core", "rspec")
6 changes: 5 additions & 1 deletion Support/test/test_executable.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# When running tests from TextMate, make sure to set the “project directory” to the directory containing the Gemfile.
require 'bundler/setup'
require 'minitest/autorun'
require 'shellwords'
require "#{__dir__}/../lib/executable"
Expand Down Expand Up @@ -97,10 +99,12 @@ def test_find_binstub_with_rvm
end

def test_find_in_gemfile
Dir.chdir("#{__dir__}/fixtures/sample_project_with_gemfile")
assert_equal %w(bundle exec rubocop), Executable.find('rubocop')
end

def test_find_in_gemfile_with_rvm
Dir.chdir("#{__dir__}/fixtures/sample_project_with_gemfile")
with_rvm_installed do
assert_equal %W(#{@rvm_prefix} bundle exec rubocop), Executable.find('rubocop')
end
Expand Down Expand Up @@ -152,7 +156,7 @@ def test_find_precedence
assert_equal %w(rspec), Executable.find('rspec')

# Using a Gemfile comes next
FileUtils.cp(Dir.glob("#{__dir__}/fixtures/sample_project/Gemfile.*"), dir)
FileUtils.cp(Dir.glob("#{__dir__}/fixtures/sample_project_with_gemfile/Gemfile*"), dir)
assert_equal %w(bundle exec rspec), Executable.find('rspec')

# Using a binstub has an even higher precedence
Expand Down

0 comments on commit 9e70114

Please sign in to comment.