2018-11-02 19:07:56 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
RSpec.describe "bundle open" do
|
2019-08-09 15:48:38 -04:00
|
|
|
context "when opening a regular gem" do
|
|
|
|
before do
|
|
|
|
install_gemfile <<-G
|
|
|
|
source "#{file_uri_for(gem_repo1)}"
|
|
|
|
gem "rails"
|
|
|
|
G
|
|
|
|
end
|
2018-11-02 19:07:56 -04:00
|
|
|
|
2019-08-09 15:48:38 -04:00
|
|
|
it "opens the gem with BUNDLER_EDITOR as highest priority" do
|
|
|
|
bundle "open rails", :env => { "EDITOR" => "echo editor", "VISUAL" => "echo visual", "BUNDLER_EDITOR" => "echo bundler_editor" }
|
|
|
|
expect(out).to include("bundler_editor #{default_bundle_path("gems", "rails-2.3.2")}")
|
|
|
|
end
|
2018-11-02 19:07:56 -04:00
|
|
|
|
2019-08-09 15:48:38 -04:00
|
|
|
it "opens the gem with VISUAL as 2nd highest priority" do
|
|
|
|
bundle "open rails", :env => { "EDITOR" => "echo editor", "VISUAL" => "echo visual", "BUNDLER_EDITOR" => "" }
|
|
|
|
expect(out).to include("visual #{default_bundle_path("gems", "rails-2.3.2")}")
|
|
|
|
end
|
2018-11-02 19:07:56 -04:00
|
|
|
|
2019-08-09 15:48:38 -04:00
|
|
|
it "opens the gem with EDITOR as 3rd highest priority" do
|
|
|
|
bundle "open rails", :env => { "EDITOR" => "echo editor", "VISUAL" => "", "BUNDLER_EDITOR" => "" }
|
|
|
|
expect(out).to include("editor #{default_bundle_path("gems", "rails-2.3.2")}")
|
|
|
|
end
|
2018-11-02 19:07:56 -04:00
|
|
|
|
2019-08-09 15:48:38 -04:00
|
|
|
it "complains if no EDITOR is set" do
|
|
|
|
bundle "open rails", :env => { "EDITOR" => "", "VISUAL" => "", "BUNDLER_EDITOR" => "" }
|
|
|
|
expect(out).to eq("To open a bundled gem, set $EDITOR or $BUNDLER_EDITOR")
|
|
|
|
end
|
2018-11-02 19:07:56 -04:00
|
|
|
|
2019-08-09 15:48:38 -04:00
|
|
|
it "complains if gem not in bundle" do
|
2020-06-03 12:43:17 -04:00
|
|
|
bundle "open missing", :env => { "EDITOR" => "echo editor", "VISUAL" => "", "BUNDLER_EDITOR" => "" }, :raise_on_error => false
|
2019-08-09 15:48:38 -04:00
|
|
|
expect(err).to match(/could not find gem 'missing'/i)
|
|
|
|
end
|
2018-11-02 19:07:56 -04:00
|
|
|
|
2019-08-09 15:48:38 -04:00
|
|
|
it "does not blow up if the gem to open does not have a Gemfile" do
|
|
|
|
git = build_git "foo"
|
|
|
|
ref = git.ref_for("master", 11)
|
2018-11-02 19:07:56 -04:00
|
|
|
|
2019-08-09 15:48:38 -04:00
|
|
|
install_gemfile <<-G
|
|
|
|
source "#{file_uri_for(gem_repo1)}"
|
|
|
|
gem 'foo', :git => "#{lib_path("foo-1.0")}"
|
|
|
|
G
|
2018-11-02 19:07:56 -04:00
|
|
|
|
2019-08-09 15:48:38 -04:00
|
|
|
bundle "open foo", :env => { "EDITOR" => "echo editor", "VISUAL" => "", "BUNDLER_EDITOR" => "" }
|
|
|
|
expect(out).to match("editor #{default_bundle_path.join("bundler/gems/foo-1.0-#{ref}")}")
|
|
|
|
end
|
2018-11-02 19:07:56 -04:00
|
|
|
|
2019-08-09 15:48:38 -04:00
|
|
|
it "suggests alternatives for similar-sounding gems" do
|
2020-06-03 12:43:17 -04:00
|
|
|
bundle "open Rails", :env => { "EDITOR" => "echo editor", "VISUAL" => "", "BUNDLER_EDITOR" => "" }, :raise_on_error => false
|
2019-08-09 15:48:38 -04:00
|
|
|
expect(err).to match(/did you mean rails\?/i)
|
|
|
|
end
|
2018-11-02 19:07:56 -04:00
|
|
|
|
2019-08-09 15:48:38 -04:00
|
|
|
it "opens the gem with short words" do
|
|
|
|
bundle "open rec", :env => { "EDITOR" => "echo editor", "VISUAL" => "echo visual", "BUNDLER_EDITOR" => "echo bundler_editor" }
|
2018-11-02 19:07:56 -04:00
|
|
|
|
2019-08-09 15:48:38 -04:00
|
|
|
expect(out).to include("bundler_editor #{default_bundle_path("gems", "activerecord-2.3.2")}")
|
2018-11-02 19:07:56 -04:00
|
|
|
end
|
|
|
|
|
2020-05-08 01:19:04 -04:00
|
|
|
it "select the gem from many match gems", :readline do
|
2019-08-09 15:48:38 -04:00
|
|
|
env = { "EDITOR" => "echo editor", "VISUAL" => "echo visual", "BUNDLER_EDITOR" => "echo bundler_editor" }
|
|
|
|
bundle "open active", :env => env do |input, _, _|
|
|
|
|
input.puts "2"
|
|
|
|
end
|
2018-11-02 19:07:56 -04:00
|
|
|
|
2019-08-09 15:48:38 -04:00
|
|
|
expect(out).to match(/bundler_editor #{default_bundle_path('gems', 'activerecord-2.3.2')}\z/)
|
2018-11-02 19:07:56 -04:00
|
|
|
end
|
|
|
|
|
2020-05-08 01:19:04 -04:00
|
|
|
it "allows selecting exit from many match gems", :readline do
|
2019-08-09 15:48:38 -04:00
|
|
|
env = { "EDITOR" => "echo editor", "VISUAL" => "echo visual", "BUNDLER_EDITOR" => "echo bundler_editor" }
|
2020-06-03 14:45:36 -04:00
|
|
|
bundle "open active", :env => env do |input, _, _|
|
2019-08-09 15:48:38 -04:00
|
|
|
input.puts "0"
|
|
|
|
end
|
|
|
|
end
|
2018-11-02 19:07:56 -04:00
|
|
|
|
2019-08-09 15:48:38 -04:00
|
|
|
it "performs an automatic bundle install" do
|
|
|
|
gemfile <<-G
|
|
|
|
source "#{file_uri_for(gem_repo1)}"
|
|
|
|
gem "rails"
|
|
|
|
gem "foo"
|
|
|
|
G
|
2018-11-02 19:07:56 -04:00
|
|
|
|
2019-08-09 15:48:38 -04:00
|
|
|
bundle "config set auto_install 1"
|
|
|
|
bundle "open rails", :env => { "EDITOR" => "echo editor", "VISUAL" => "", "BUNDLER_EDITOR" => "" }
|
|
|
|
expect(out).to include("Installing foo 1.0")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "opens the editor with a clean env" do
|
2020-06-03 12:43:17 -04:00
|
|
|
bundle "open", :env => { "EDITOR" => "sh -c 'env'", "VISUAL" => "", "BUNDLER_EDITOR" => "" }, :raise_on_error => false
|
2019-08-09 15:48:38 -04:00
|
|
|
expect(out).not_to include("BUNDLE_GEMFILE=")
|
|
|
|
end
|
2018-11-02 19:07:56 -04:00
|
|
|
end
|
2016-08-15 10:44:19 -04:00
|
|
|
|
Fix some bundler specs (#2380)
* These seem to consistenly pass already
* Show actual command when running `make test-bundler`
Current the setup command that installs the necessary gems for testing
bundler was printed, but not the actual command that runs the tests.
That was a bit confusing.
* Borrow trick from setproctitle specs
* A title that long doesn't get set sometimes
No idea why, but the test doesn't need that the title is that long.
* Fix most gem helper spec ruby-core failures
* Fix the rest of the gem helper failures
* Fix version spec by improving the assertion
* Remove unnecessary `BUNDLE_RUBY` environment var
We can use `RUBY` when necessary, and `BUNDLE_RUBY` is not a good name
because bundler considers `BUNDLE_*` variables as settings.
* Rename `BUNDLE_GEM` to `GEM_COMMAND`
This is more descriptive I think, and also friendlier for bundler
because `BUNDLE_` env variables are interpreted by bundler as settings,
and this is not a bundler setting.
This fixes one bundler spec failure in config specs against ruby-core.
* Fix quality spec when run in core
Use the proper path helper.
* Fix dummy lib builder to never load default gems
If a dummy library is named as a default gem, when requiring the library
from its executable, the default gem would be loaded when running from
core, because in core all default gems share path with bundler, and thus
they are always in the $LOAD_PATH. We fix the issue by loading lib
relatively inside dummy lib executables.
* More exact assertions
Sometimes I have the problem that I do some "print debugging" inside
specs, and suddently the spec passes. This happens when the assertion is
too relaxed, and the things I print make it match, specially when they
are simple strings like "1.0" than can be easily be part of gem paths
that I print for debugging.
I fix this by making a more exact assertion.
* Detect the correct shebang when ENV["RUBY"] is set
* Relax assertion
So that the spec passes even if another paths containing "ext" are in
the load path. This works to fix a ruby-core issue, but it's a better
assertion in general. We just want to know that the extension path was
added.
* Use folder structure independent path helper
It should fix this spec for ruby-core.
* Fix the last failing spec on ruby-core
* Skip `bundle open <default_gem>` spec when no default gems
2019-08-19 20:46:31 -04:00
|
|
|
context "when opening a default gem" do
|
|
|
|
let(:default_gems) do
|
2020-06-03 14:47:59 -04:00
|
|
|
ruby(<<-RUBY).split("\n")
|
Fix some bundler specs (#2380)
* These seem to consistenly pass already
* Show actual command when running `make test-bundler`
Current the setup command that installs the necessary gems for testing
bundler was printed, but not the actual command that runs the tests.
That was a bit confusing.
* Borrow trick from setproctitle specs
* A title that long doesn't get set sometimes
No idea why, but the test doesn't need that the title is that long.
* Fix most gem helper spec ruby-core failures
* Fix the rest of the gem helper failures
* Fix version spec by improving the assertion
* Remove unnecessary `BUNDLE_RUBY` environment var
We can use `RUBY` when necessary, and `BUNDLE_RUBY` is not a good name
because bundler considers `BUNDLE_*` variables as settings.
* Rename `BUNDLE_GEM` to `GEM_COMMAND`
This is more descriptive I think, and also friendlier for bundler
because `BUNDLE_` env variables are interpreted by bundler as settings,
and this is not a bundler setting.
This fixes one bundler spec failure in config specs against ruby-core.
* Fix quality spec when run in core
Use the proper path helper.
* Fix dummy lib builder to never load default gems
If a dummy library is named as a default gem, when requiring the library
from its executable, the default gem would be loaded when running from
core, because in core all default gems share path with bundler, and thus
they are always in the $LOAD_PATH. We fix the issue by loading lib
relatively inside dummy lib executables.
* More exact assertions
Sometimes I have the problem that I do some "print debugging" inside
specs, and suddently the spec passes. This happens when the assertion is
too relaxed, and the things I print make it match, specially when they
are simple strings like "1.0" than can be easily be part of gem paths
that I print for debugging.
I fix this by making a more exact assertion.
* Detect the correct shebang when ENV["RUBY"] is set
* Relax assertion
So that the spec passes even if another paths containing "ext" are in
the load path. This works to fix a ruby-core issue, but it's a better
assertion in general. We just want to know that the extension path was
added.
* Use folder structure independent path helper
It should fix this spec for ruby-core.
* Fix the last failing spec on ruby-core
* Skip `bundle open <default_gem>` spec when no default gems
2019-08-19 20:46:31 -04:00
|
|
|
if Gem::Specification.is_a?(Enumerable)
|
|
|
|
puts Gem::Specification.select(&:default_gem?).map(&:name)
|
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
end
|
|
|
|
|
2016-08-15 10:44:19 -04:00
|
|
|
before do
|
Fix some bundler specs (#2380)
* These seem to consistenly pass already
* Show actual command when running `make test-bundler`
Current the setup command that installs the necessary gems for testing
bundler was printed, but not the actual command that runs the tests.
That was a bit confusing.
* Borrow trick from setproctitle specs
* A title that long doesn't get set sometimes
No idea why, but the test doesn't need that the title is that long.
* Fix most gem helper spec ruby-core failures
* Fix the rest of the gem helper failures
* Fix version spec by improving the assertion
* Remove unnecessary `BUNDLE_RUBY` environment var
We can use `RUBY` when necessary, and `BUNDLE_RUBY` is not a good name
because bundler considers `BUNDLE_*` variables as settings.
* Rename `BUNDLE_GEM` to `GEM_COMMAND`
This is more descriptive I think, and also friendlier for bundler
because `BUNDLE_` env variables are interpreted by bundler as settings,
and this is not a bundler setting.
This fixes one bundler spec failure in config specs against ruby-core.
* Fix quality spec when run in core
Use the proper path helper.
* Fix dummy lib builder to never load default gems
If a dummy library is named as a default gem, when requiring the library
from its executable, the default gem would be loaded when running from
core, because in core all default gems share path with bundler, and thus
they are always in the $LOAD_PATH. We fix the issue by loading lib
relatively inside dummy lib executables.
* More exact assertions
Sometimes I have the problem that I do some "print debugging" inside
specs, and suddently the spec passes. This happens when the assertion is
too relaxed, and the things I print make it match, specially when they
are simple strings like "1.0" than can be easily be part of gem paths
that I print for debugging.
I fix this by making a more exact assertion.
* Detect the correct shebang when ENV["RUBY"] is set
* Relax assertion
So that the spec passes even if another paths containing "ext" are in
the load path. This works to fix a ruby-core issue, but it's a better
assertion in general. We just want to know that the extension path was
added.
* Use folder structure independent path helper
It should fix this spec for ruby-core.
* Fix the last failing spec on ruby-core
* Skip `bundle open <default_gem>` spec when no default gems
2019-08-19 20:46:31 -04:00
|
|
|
skip "No default gems available on this test run" if default_gems.empty?
|
|
|
|
|
2016-08-15 10:44:19 -04:00
|
|
|
install_gemfile <<-G
|
|
|
|
gem "json"
|
|
|
|
G
|
|
|
|
end
|
|
|
|
|
|
|
|
it "throws proper error when trying to open default gem" do
|
|
|
|
bundle "open json", :env => { "EDITOR" => "echo editor", "VISUAL" => "echo visual", "BUNDLER_EDITOR" => "echo bundler_editor" }
|
|
|
|
expect(out).to include("Unable to open json because it's a default gem, so the directory it would normally be installed to does not exist.")
|
|
|
|
end
|
|
|
|
end
|
2018-11-02 19:07:56 -04:00
|
|
|
end
|