2018-11-02 19:07:56 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
RSpec.describe "bundle gem" do
|
2019-11-11 03:57:45 -05:00
|
|
|
def gem_skeleton_assertions
|
2018-11-02 19:07:56 -04:00
|
|
|
expect(bundled_app("#{gem_name}/#{gem_name}.gemspec")).to exist
|
|
|
|
expect(bundled_app("#{gem_name}/README.md")).to exist
|
|
|
|
expect(bundled_app("#{gem_name}/Gemfile")).to exist
|
|
|
|
expect(bundled_app("#{gem_name}/Rakefile")).to exist
|
2019-11-11 03:57:45 -05:00
|
|
|
expect(bundled_app("#{gem_name}/lib/#{require_path}.rb")).to exist
|
|
|
|
expect(bundled_app("#{gem_name}/lib/#{require_path}/version.rb")).to exist
|
2018-11-02 19:07:56 -04:00
|
|
|
end
|
|
|
|
|
2019-11-11 03:57:45 -05:00
|
|
|
let(:generated_gemspec) { Bundler.load_gemspec_uncached(bundled_app(gem_name).join("#{gem_name}.gemspec")) }
|
|
|
|
|
|
|
|
let(:gem_name) { "mygem" }
|
|
|
|
|
|
|
|
let(:require_path) { "mygem" }
|
2019-06-17 04:23:24 -04:00
|
|
|
|
2018-11-02 19:07:56 -04:00
|
|
|
before do
|
2019-06-01 05:49:40 -04:00
|
|
|
global_config "BUNDLE_GEM__MIT" => "false", "BUNDLE_GEM__TEST" => "false", "BUNDLE_GEM__COC" => "false"
|
2018-11-02 19:07:56 -04:00
|
|
|
git_config_content = <<-EOF
|
|
|
|
[user]
|
|
|
|
name = "Bundler User"
|
|
|
|
email = user@example.com
|
|
|
|
[github]
|
|
|
|
user = bundleuser
|
|
|
|
EOF
|
|
|
|
@git_config_location = ENV["GIT_CONFIG"]
|
2019-11-11 03:57:45 -05:00
|
|
|
path = "#{tmp}/test_git_config.txt"
|
2018-11-02 19:07:56 -04:00
|
|
|
File.open(path, "w") {|f| f.write(git_config_content) }
|
|
|
|
ENV["GIT_CONFIG"] = path
|
|
|
|
end
|
|
|
|
|
|
|
|
after do
|
|
|
|
FileUtils.rm(ENV["GIT_CONFIG"]) if File.exist?(ENV["GIT_CONFIG"])
|
|
|
|
ENV["GIT_CONFIG"] = @git_config_location
|
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples_for "git config is present" do
|
|
|
|
context "git config user.{name,email} present" do
|
|
|
|
it "sets gemspec author to git user.name if available" do
|
2019-06-17 04:23:47 -04:00
|
|
|
expect(generated_gemspec.authors.first).to eq("Bundler User")
|
2018-11-02 19:07:56 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "sets gemspec email to git user.email if available" do
|
2019-06-17 04:23:47 -04:00
|
|
|
expect(generated_gemspec.email.first).to eq("user@example.com")
|
2018-11-02 19:07:56 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples_for "git config is absent" do
|
|
|
|
it "sets gemspec author to default message if git user.name is not set or empty" do
|
2019-06-17 04:23:47 -04:00
|
|
|
expect(generated_gemspec.authors.first).to eq("TODO: Write your name")
|
2018-11-02 19:07:56 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "sets gemspec email to default message if git user.email is not set or empty" do
|
2019-06-17 04:23:47 -04:00
|
|
|
expect(generated_gemspec.email.first).to eq("TODO: Write your email address")
|
2018-11-02 19:07:56 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-07-24 06:24:55 -04:00
|
|
|
describe "git repo initialization" do
|
|
|
|
shared_examples_for "a gem with an initial git repo" do
|
|
|
|
before do
|
2019-11-11 03:57:45 -05:00
|
|
|
bundle! "gem #{gem_name} #{flags}"
|
2019-07-24 06:24:55 -04:00
|
|
|
end
|
2019-11-11 03:57:45 -05:00
|
|
|
|
2019-07-24 06:24:55 -04:00
|
|
|
it "generates a gem skeleton with a .git folder" do
|
2019-11-11 03:57:45 -05:00
|
|
|
gem_skeleton_assertions
|
|
|
|
expect(bundled_app("#{gem_name}/.git")).to exist
|
2019-07-24 06:24:55 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when using the default" do
|
|
|
|
it_behaves_like "a gem with an initial git repo" do
|
|
|
|
let(:flags) { "" }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when explicitly passing --git" do
|
|
|
|
it_behaves_like "a gem with an initial git repo" do
|
|
|
|
let(:flags) { "--git" }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when passing --no-git" do
|
|
|
|
before do
|
2019-11-11 03:57:45 -05:00
|
|
|
bundle! "gem #{gem_name} --no-git"
|
2019-07-24 06:24:55 -04:00
|
|
|
end
|
|
|
|
it "generates a gem skeleton without a .git folder" do
|
2019-11-11 03:57:45 -05:00
|
|
|
gem_skeleton_assertions
|
|
|
|
expect(bundled_app("#{gem_name}/.git")).not_to exist
|
2019-07-24 06:24:55 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-11-02 19:07:56 -04:00
|
|
|
shared_examples_for "--mit flag" do
|
|
|
|
before do
|
2019-11-11 03:57:45 -05:00
|
|
|
bundle! "gem #{gem_name} --mit"
|
2018-11-02 19:07:56 -04:00
|
|
|
end
|
|
|
|
it "generates a gem skeleton with MIT license" do
|
2019-11-11 03:57:45 -05:00
|
|
|
gem_skeleton_assertions
|
|
|
|
expect(bundled_app("#{gem_name}/LICENSE.txt")).to exist
|
|
|
|
expect(generated_gemspec.license).to eq("MIT")
|
2018-11-02 19:07:56 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples_for "--no-mit flag" do
|
|
|
|
before do
|
2019-11-11 03:57:45 -05:00
|
|
|
bundle! "gem #{gem_name} --no-mit"
|
2018-11-02 19:07:56 -04:00
|
|
|
end
|
|
|
|
it "generates a gem skeleton without MIT license" do
|
2019-11-11 03:57:45 -05:00
|
|
|
gem_skeleton_assertions
|
|
|
|
expect(bundled_app("#{gem_name}/LICENSE.txt")).to_not exist
|
2018-11-02 19:07:56 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples_for "--coc flag" do
|
|
|
|
before do
|
2019-11-11 03:57:45 -05:00
|
|
|
bundle! "gem #{gem_name} --coc"
|
2018-11-02 19:07:56 -04:00
|
|
|
end
|
|
|
|
it "generates a gem skeleton with MIT license" do
|
2019-11-11 03:57:45 -05:00
|
|
|
gem_skeleton_assertions
|
|
|
|
expect(bundled_app("#{gem_name}/CODE_OF_CONDUCT.md")).to exist
|
2018-11-02 19:07:56 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
describe "README additions" do
|
|
|
|
it "generates the README with a section for the Code of Conduct" do
|
2019-11-11 03:57:45 -05:00
|
|
|
expect(bundled_app("#{gem_name}/README.md").read).to include("## Code of Conduct")
|
|
|
|
expect(bundled_app("#{gem_name}/README.md").read).to include("https://github.com/bundleuser/#{gem_name}/blob/master/CODE_OF_CONDUCT.md")
|
2018-11-02 19:07:56 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples_for "--no-coc flag" do
|
|
|
|
before do
|
2019-11-11 03:57:45 -05:00
|
|
|
bundle! "gem #{gem_name} --no-coc"
|
2018-11-02 19:07:56 -04:00
|
|
|
end
|
|
|
|
it "generates a gem skeleton without Code of Conduct" do
|
2019-11-11 03:57:45 -05:00
|
|
|
gem_skeleton_assertions
|
|
|
|
expect(bundled_app("#{gem_name}/CODE_OF_CONDUCT.md")).to_not exist
|
2018-11-02 19:07:56 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
describe "README additions" do
|
|
|
|
it "generates the README without a section for the Code of Conduct" do
|
2019-11-11 03:57:45 -05:00
|
|
|
expect(bundled_app("#{gem_name}/README.md").read).not_to include("## Code of Conduct")
|
|
|
|
expect(bundled_app("#{gem_name}/README.md").read).not_to include("https://github.com/bundleuser/#{gem_name}/blob/master/CODE_OF_CONDUCT.md")
|
2018-11-02 19:07:56 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "README.md" do
|
|
|
|
context "git config github.user present" do
|
|
|
|
before do
|
2019-11-11 03:57:45 -05:00
|
|
|
bundle! "gem #{gem_name}"
|
2018-11-02 19:07:56 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "contribute URL set to git username" do
|
2019-11-11 03:57:45 -05:00
|
|
|
expect(bundled_app("#{gem_name}/README.md").read).not_to include("[USERNAME]")
|
|
|
|
expect(bundled_app("#{gem_name}/README.md").read).to include("github.com/bundleuser")
|
2018-11-02 19:07:56 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "git config github.user is absent" do
|
|
|
|
before do
|
|
|
|
sys_exec("git config --unset github.user")
|
|
|
|
bundle "gem #{gem_name}"
|
|
|
|
end
|
|
|
|
|
|
|
|
it "contribute URL set to [USERNAME]" do
|
2019-11-11 03:57:45 -05:00
|
|
|
expect(bundled_app("#{gem_name}/README.md").read).to include("[USERNAME]")
|
|
|
|
expect(bundled_app("#{gem_name}/README.md").read).not_to include("github.com/bundleuser")
|
2018-11-02 19:07:56 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it "creates a new git repository" do
|
2019-11-11 03:57:45 -05:00
|
|
|
bundle "gem #{gem_name}"
|
|
|
|
expect(bundled_app("#{gem_name}/.git")).to exist
|
2018-11-02 19:07:56 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context "when git is not available" do
|
|
|
|
# This spec cannot have `git` available in the test env
|
|
|
|
before do
|
2019-11-11 03:57:45 -05:00
|
|
|
load_paths = [lib_dir, spec_dir]
|
2018-11-02 19:07:56 -04:00
|
|
|
load_path_str = "-I#{load_paths.join(File::PATH_SEPARATOR)}"
|
|
|
|
|
2019-04-14 02:01:35 -04:00
|
|
|
sys_exec "#{Gem.ruby} #{load_path_str} #{bindir.join("bundle")} gem #{gem_name}", "PATH" => ""
|
2018-11-02 19:07:56 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "creates the gem without the need for git" do
|
|
|
|
expect(bundled_app("#{gem_name}/README.md")).to exist
|
|
|
|
end
|
|
|
|
|
|
|
|
it "doesn't create a git repo" do
|
|
|
|
expect(bundled_app("#{gem_name}/.git")).to_not exist
|
|
|
|
end
|
|
|
|
|
|
|
|
it "doesn't create a .gitignore file" do
|
|
|
|
expect(bundled_app("#{gem_name}/.gitignore")).to_not exist
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
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
|
|
|
it "generates a valid gemspec" do
|
2018-11-02 19:07:56 -04:00
|
|
|
bundle! "gem newgem --bin"
|
|
|
|
|
2019-05-31 05:03:11 -04:00
|
|
|
prepare_gemspec(bundled_app("newgem", "newgem.gemspec"))
|
2018-11-02 19:07:56 -04:00
|
|
|
|
|
|
|
Dir.chdir(bundled_app("newgem")) do
|
2019-08-15 10:47:44 -04:00
|
|
|
gems = ["rake-12.3.2"]
|
2018-11-02 19:07:56 -04:00
|
|
|
system_gems gems, :path => :bundle_path
|
|
|
|
bundle! "exec rake build"
|
|
|
|
end
|
|
|
|
|
|
|
|
expect(last_command.stdboth).not_to include("ERROR")
|
|
|
|
end
|
|
|
|
|
|
|
|
context "gem naming with relative paths" do
|
|
|
|
it "resolves ." do
|
|
|
|
create_temporary_dir("tmp")
|
|
|
|
|
|
|
|
bundle "gem ."
|
|
|
|
|
|
|
|
expect(bundled_app("tmp/lib/tmp.rb")).to exist
|
|
|
|
end
|
|
|
|
|
|
|
|
it "resolves .." do
|
|
|
|
create_temporary_dir("temp/empty_dir")
|
|
|
|
|
|
|
|
bundle "gem .."
|
|
|
|
|
|
|
|
expect(bundled_app("temp/lib/temp.rb")).to exist
|
|
|
|
end
|
|
|
|
|
|
|
|
it "resolves relative directory" do
|
|
|
|
create_temporary_dir("tmp/empty/tmp")
|
|
|
|
|
|
|
|
bundle "gem ../../empty"
|
|
|
|
|
|
|
|
expect(bundled_app("tmp/empty/lib/empty.rb")).to exist
|
|
|
|
end
|
|
|
|
|
|
|
|
def create_temporary_dir(dir)
|
|
|
|
FileUtils.mkdir_p(dir)
|
|
|
|
Dir.chdir(dir)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-11-11 03:57:45 -05:00
|
|
|
shared_examples_for "generating a gem" do
|
2018-11-02 19:07:56 -04:00
|
|
|
it "generates a gem skeleton" do
|
2019-11-11 03:57:45 -05:00
|
|
|
bundle! "gem #{gem_name}"
|
|
|
|
|
|
|
|
expect(bundled_app("#{gem_name}/#{gem_name}.gemspec")).to exist
|
|
|
|
expect(bundled_app("#{gem_name}/Gemfile")).to exist
|
|
|
|
expect(bundled_app("#{gem_name}/Rakefile")).to exist
|
|
|
|
expect(bundled_app("#{gem_name}/lib/#{require_path}.rb")).to exist
|
|
|
|
expect(bundled_app("#{gem_name}/lib/#{require_path}/version.rb")).to exist
|
|
|
|
expect(bundled_app("#{gem_name}/.gitignore")).to exist
|
2018-11-02 19:07:56 -04:00
|
|
|
|
2019-11-11 03:57:45 -05:00
|
|
|
expect(bundled_app("#{gem_name}/bin/setup")).to exist
|
|
|
|
expect(bundled_app("#{gem_name}/bin/console")).to exist
|
|
|
|
expect(bundled_app("#{gem_name}/bin/setup")).to be_executable
|
|
|
|
expect(bundled_app("#{gem_name}/bin/console")).to be_executable
|
2018-11-02 19:07:56 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "starts with version 0.1.0" do
|
2019-11-11 03:57:45 -05:00
|
|
|
bundle! "gem #{gem_name}"
|
2018-11-02 19:07:56 -04:00
|
|
|
|
2019-11-11 03:57:45 -05:00
|
|
|
expect(bundled_app("#{gem_name}/lib/#{require_path}/version.rb").read).to match(/VERSION = "0.1.0"/)
|
2018-11-02 19:07:56 -04:00
|
|
|
end
|
|
|
|
|
2019-11-11 03:57:45 -05:00
|
|
|
context "git config user.{name,email} is set" do
|
|
|
|
before do
|
|
|
|
bundle! "gem #{gem_name}"
|
|
|
|
end
|
|
|
|
|
|
|
|
it_should_behave_like "git config is present"
|
|
|
|
end
|
2018-11-02 19:07:56 -04:00
|
|
|
|
|
|
|
context "git config user.{name,email} is not set" do
|
|
|
|
before do
|
|
|
|
`git config --unset user.name`
|
|
|
|
`git config --unset user.email`
|
|
|
|
bundle "gem #{gem_name}"
|
|
|
|
end
|
|
|
|
|
|
|
|
it_should_behave_like "git config is absent"
|
|
|
|
end
|
|
|
|
|
2019-04-14 02:01:35 -04:00
|
|
|
it "sets gemspec metadata['allowed_push_host']" do
|
2019-11-11 03:57:45 -05:00
|
|
|
bundle! "gem #{gem_name}"
|
|
|
|
|
2019-06-17 04:23:47 -04:00
|
|
|
expect(generated_gemspec.metadata["allowed_push_host"]).
|
2018-11-02 19:07:56 -04:00
|
|
|
to match(/mygemserver\.com/)
|
|
|
|
end
|
|
|
|
|
2016-03-26 06:47:43 -04:00
|
|
|
it "sets a minimum ruby version" do
|
2019-11-11 03:57:45 -05:00
|
|
|
bundle! "gem #{gem_name}"
|
|
|
|
|
2019-08-16 02:45:11 -04:00
|
|
|
bundler_gemspec = Bundler::GemHelper.new(gemspec_dir).gemspec
|
2016-03-26 06:47:43 -04:00
|
|
|
|
|
|
|
expect(bundler_gemspec.required_ruby_version).to eq(generated_gemspec.required_ruby_version)
|
|
|
|
end
|
|
|
|
|
2018-11-02 19:07:56 -04:00
|
|
|
it "requires the version file" do
|
2019-11-11 03:57:45 -05:00
|
|
|
bundle! "gem #{gem_name}"
|
|
|
|
|
|
|
|
expect(bundled_app("#{gem_name}/lib/#{require_path}.rb").read).to match(%r{require "#{require_path}/version"})
|
2018-11-02 19:07:56 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "creates a base error class" do
|
2019-11-11 03:57:45 -05:00
|
|
|
bundle! "gem #{gem_name}"
|
|
|
|
|
|
|
|
expect(bundled_app("#{gem_name}/lib/#{require_path}.rb").read).to match(/class Error < StandardError; end$/)
|
2018-11-02 19:07:56 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "runs rake without problems" do
|
2019-11-11 03:57:45 -05:00
|
|
|
bundle! "gem #{gem_name}"
|
|
|
|
|
2019-04-14 02:01:35 -04:00
|
|
|
system_gems ["rake-12.3.2"]
|
2018-11-02 19:07:56 -04:00
|
|
|
|
|
|
|
rakefile = strip_whitespace <<-RAKEFILE
|
|
|
|
task :default do
|
|
|
|
puts 'SUCCESS'
|
|
|
|
end
|
|
|
|
RAKEFILE
|
2019-11-11 03:57:45 -05:00
|
|
|
File.open(bundled_app("#{gem_name}/Rakefile"), "w") do |file|
|
2018-11-02 19:07:56 -04:00
|
|
|
file.puts rakefile
|
|
|
|
end
|
|
|
|
|
|
|
|
Dir.chdir(bundled_app(gem_name)) do
|
|
|
|
sys_exec(rake)
|
|
|
|
expect(out).to include("SUCCESS")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "--exe parameter set" do
|
|
|
|
before do
|
|
|
|
bundle "gem #{gem_name} --exe"
|
|
|
|
end
|
|
|
|
|
|
|
|
it "builds exe skeleton" do
|
2019-11-11 03:57:45 -05:00
|
|
|
expect(bundled_app("#{gem_name}/exe/#{gem_name}")).to exist
|
2018-11-02 19:07:56 -04:00
|
|
|
end
|
|
|
|
|
2019-11-11 03:57:45 -05:00
|
|
|
it "requires the main file" do
|
|
|
|
expect(bundled_app("#{gem_name}/exe/#{gem_name}").read).to match(/require "#{require_path}"/)
|
2018-11-02 19:07:56 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "--bin parameter set" do
|
|
|
|
before do
|
|
|
|
bundle "gem #{gem_name} --bin"
|
|
|
|
end
|
|
|
|
|
|
|
|
it "builds exe skeleton" do
|
2019-11-11 03:57:45 -05:00
|
|
|
expect(bundled_app("#{gem_name}/exe/#{gem_name}")).to exist
|
2018-11-02 19:07:56 -04:00
|
|
|
end
|
|
|
|
|
2019-11-11 03:57:45 -05:00
|
|
|
it "requires the main file" do
|
|
|
|
expect(bundled_app("#{gem_name}/exe/#{gem_name}").read).to match(/require "#{require_path}"/)
|
2018-11-02 19:07:56 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "no --test parameter" do
|
|
|
|
before do
|
|
|
|
bundle "gem #{gem_name}"
|
|
|
|
end
|
|
|
|
|
|
|
|
it "doesn't create any spec/test file" do
|
2019-11-11 03:57:45 -05:00
|
|
|
expect(bundled_app("#{gem_name}/.rspec")).to_not exist
|
|
|
|
expect(bundled_app("#{gem_name}/spec/#{require_path}_spec.rb")).to_not exist
|
|
|
|
expect(bundled_app("#{gem_name}/spec/spec_helper.rb")).to_not exist
|
|
|
|
expect(bundled_app("#{gem_name}/test/#{require_path}.rb")).to_not exist
|
|
|
|
expect(bundled_app("#{gem_name}/test/minitest_helper.rb")).to_not exist
|
2018-11-02 19:07:56 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "--test parameter set to rspec" do
|
|
|
|
before do
|
|
|
|
bundle "gem #{gem_name} --test=rspec"
|
|
|
|
end
|
|
|
|
|
|
|
|
it "builds spec skeleton" do
|
2019-11-11 03:57:45 -05:00
|
|
|
expect(bundled_app("#{gem_name}/.rspec")).to exist
|
|
|
|
expect(bundled_app("#{gem_name}/spec/#{require_path}_spec.rb")).to exist
|
|
|
|
expect(bundled_app("#{gem_name}/spec/spec_helper.rb")).to exist
|
2018-11-02 19:07:56 -04:00
|
|
|
end
|
|
|
|
|
2019-06-26 10:35:49 -04:00
|
|
|
it "depends on a specific version of rspec in generated Gemfile" do
|
2019-11-11 03:57:45 -05:00
|
|
|
Dir.chdir(bundled_app(gem_name)) do
|
2019-06-26 10:35:49 -04:00
|
|
|
builder = Bundler::Dsl.new
|
2019-11-11 03:57:45 -05:00
|
|
|
builder.eval_gemfile(bundled_app("#{gem_name}/Gemfile"))
|
2019-06-26 10:35:49 -04:00
|
|
|
builder.dependencies
|
|
|
|
rspec_dep = builder.dependencies.find {|d| d.name == "rspec" }
|
|
|
|
expect(rspec_dep).to be_specific
|
|
|
|
end
|
2018-11-02 19:07:56 -04:00
|
|
|
end
|
|
|
|
|
2019-11-11 03:57:45 -05:00
|
|
|
it "requires the main file" do
|
|
|
|
expect(bundled_app("#{gem_name}/spec/spec_helper.rb").read).to include(%(require "#{require_path}"))
|
2018-11-02 19:07:56 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "creates a default test which fails" do
|
2019-11-11 03:57:45 -05:00
|
|
|
expect(bundled_app("#{gem_name}/spec/#{require_path}_spec.rb").read).to include("expect(false).to eq(true)")
|
2018-11-02 19:07:56 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "gem.test setting set to rspec" do
|
|
|
|
before do
|
2019-04-14 02:01:35 -04:00
|
|
|
bundle "config set gem.test rspec"
|
2018-11-02 19:07:56 -04:00
|
|
|
bundle "gem #{gem_name}"
|
|
|
|
end
|
|
|
|
|
|
|
|
it "builds spec skeleton" do
|
2019-11-11 03:57:45 -05:00
|
|
|
expect(bundled_app("#{gem_name}/.rspec")).to exist
|
|
|
|
expect(bundled_app("#{gem_name}/spec/#{require_path}_spec.rb")).to exist
|
|
|
|
expect(bundled_app("#{gem_name}/spec/spec_helper.rb")).to exist
|
2018-11-02 19:07:56 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "gem.test setting set to rspec and --test is set to minitest" do
|
|
|
|
before do
|
2019-04-14 02:01:35 -04:00
|
|
|
bundle "config set gem.test rspec"
|
2018-11-02 19:07:56 -04:00
|
|
|
bundle "gem #{gem_name} --test=minitest"
|
|
|
|
end
|
|
|
|
|
|
|
|
it "builds spec skeleton" do
|
2019-11-11 03:57:45 -05:00
|
|
|
expect(bundled_app("#{gem_name}/test/#{require_path}_test.rb")).to exist
|
|
|
|
expect(bundled_app("#{gem_name}/test/test_helper.rb")).to exist
|
2018-11-02 19:07:56 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "--test parameter set to minitest" do
|
|
|
|
before do
|
|
|
|
bundle "gem #{gem_name} --test=minitest"
|
|
|
|
end
|
|
|
|
|
2019-04-14 02:01:35 -04:00
|
|
|
it "depends on a specific version of minitest" do
|
2019-11-11 03:57:45 -05:00
|
|
|
Dir.chdir(bundled_app(gem_name)) do
|
2019-06-26 10:35:49 -04:00
|
|
|
builder = Bundler::Dsl.new
|
2019-11-11 03:57:45 -05:00
|
|
|
builder.eval_gemfile(bundled_app("#{gem_name}/Gemfile"))
|
2019-06-26 10:35:49 -04:00
|
|
|
builder.dependencies
|
|
|
|
minitest_dep = builder.dependencies.find {|d| d.name == "minitest" }
|
|
|
|
expect(minitest_dep).to be_specific
|
|
|
|
end
|
2018-11-02 19:07:56 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "builds spec skeleton" do
|
2019-11-11 03:57:45 -05:00
|
|
|
expect(bundled_app("#{gem_name}/test/#{require_path}_test.rb")).to exist
|
|
|
|
expect(bundled_app("#{gem_name}/test/test_helper.rb")).to exist
|
2018-11-02 19:07:56 -04:00
|
|
|
end
|
|
|
|
|
2019-11-11 03:57:45 -05:00
|
|
|
it "requires the main file" do
|
|
|
|
expect(bundled_app("#{gem_name}/test/test_helper.rb").read).to include(%(require "#{require_path}"))
|
2018-11-02 19:07:56 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "requires 'minitest_helper'" do
|
2019-11-11 03:57:45 -05:00
|
|
|
expect(bundled_app("#{gem_name}/test/#{require_path}_test.rb").read).to include(%(require "test_helper"))
|
2018-11-02 19:07:56 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "creates a default test which fails" do
|
2019-11-11 03:57:45 -05:00
|
|
|
expect(bundled_app("#{gem_name}/test/#{require_path}_test.rb").read).to include("assert false")
|
2018-11-02 19:07:56 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "gem.test setting set to minitest" do
|
|
|
|
before do
|
2019-04-14 02:01:35 -04:00
|
|
|
bundle "config set gem.test minitest"
|
2018-11-02 19:07:56 -04:00
|
|
|
bundle "gem #{gem_name}"
|
|
|
|
end
|
|
|
|
|
|
|
|
it "creates a default rake task to run the test suite" do
|
|
|
|
rakefile = strip_whitespace <<-RAKEFILE
|
|
|
|
require "bundler/gem_tasks"
|
|
|
|
require "rake/testtask"
|
|
|
|
|
|
|
|
Rake::TestTask.new(:test) do |t|
|
|
|
|
t.libs << "test"
|
|
|
|
t.libs << "lib"
|
|
|
|
t.test_files = FileList["test/**/*_test.rb"]
|
|
|
|
end
|
|
|
|
|
|
|
|
task :default => :test
|
|
|
|
RAKEFILE
|
|
|
|
|
2019-11-11 03:57:45 -05:00
|
|
|
expect(bundled_app("#{gem_name}/Rakefile").read).to eq(rakefile)
|
2018-11-02 19:07:56 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "--test with no arguments" do
|
|
|
|
before do
|
|
|
|
bundle "gem #{gem_name} --test"
|
|
|
|
end
|
|
|
|
|
|
|
|
it "defaults to rspec" do
|
2019-11-11 03:57:45 -05:00
|
|
|
expect(bundled_app("#{gem_name}/spec/spec_helper.rb")).to exist
|
|
|
|
expect(bundled_app("#{gem_name}/test/minitest_helper.rb")).to_not exist
|
2018-11-02 19:07:56 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "creates a .travis.yml file to test the library against the current Ruby version on Travis CI" do
|
2019-11-11 03:57:45 -05:00
|
|
|
expect(bundled_app("#{gem_name}/.travis.yml").read).to match(/- #{RUBY_VERSION}/)
|
2018-11-02 19:07:56 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "--edit option" do
|
|
|
|
it "opens the generated gemspec in the user's text editor" do
|
|
|
|
output = bundle "gem #{gem_name} --edit=echo"
|
|
|
|
gemspec_path = File.join(Dir.pwd, gem_name, "#{gem_name}.gemspec")
|
|
|
|
expect(output).to include("echo \"#{gemspec_path}\"")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "testing --mit and --coc options against bundle config settings" do
|
|
|
|
let(:gem_name) { "test-gem" }
|
|
|
|
|
2019-11-11 03:57:45 -05:00
|
|
|
let(:require_path) { "test/gem" }
|
|
|
|
|
2018-11-02 19:07:56 -04:00
|
|
|
context "with mit option in bundle config settings set to true" do
|
|
|
|
before do
|
|
|
|
global_config "BUNDLE_GEM__MIT" => "true", "BUNDLE_GEM__TEST" => "false", "BUNDLE_GEM__COC" => "false"
|
|
|
|
end
|
|
|
|
it_behaves_like "--mit flag"
|
|
|
|
it_behaves_like "--no-mit flag"
|
|
|
|
end
|
|
|
|
|
|
|
|
context "with mit option in bundle config settings set to false" do
|
|
|
|
it_behaves_like "--mit flag"
|
|
|
|
it_behaves_like "--no-mit flag"
|
|
|
|
end
|
|
|
|
|
|
|
|
context "with coc option in bundle config settings set to true" do
|
|
|
|
before do
|
|
|
|
global_config "BUNDLE_GEM__MIT" => "false", "BUNDLE_GEM__TEST" => "false", "BUNDLE_GEM__COC" => "true"
|
|
|
|
end
|
|
|
|
it_behaves_like "--coc flag"
|
|
|
|
it_behaves_like "--no-coc flag"
|
|
|
|
end
|
|
|
|
|
|
|
|
context "with coc option in bundle config settings set to false" do
|
|
|
|
it_behaves_like "--coc flag"
|
|
|
|
it_behaves_like "--no-coc flag"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-11-11 03:57:45 -05:00
|
|
|
context "gem naming with underscore" do
|
|
|
|
let(:gem_name) { "test_gem" }
|
2018-11-02 19:07:56 -04:00
|
|
|
|
2019-11-11 03:57:45 -05:00
|
|
|
let(:require_path) { "test_gem" }
|
2018-11-02 19:07:56 -04:00
|
|
|
|
2019-11-11 03:57:45 -05:00
|
|
|
let(:flags) { nil }
|
2018-11-02 19:07:56 -04:00
|
|
|
|
2019-11-11 03:57:45 -05:00
|
|
|
before do
|
|
|
|
bundle! ["gem", gem_name, flags].compact.join(" ")
|
2018-11-02 19:07:56 -04:00
|
|
|
end
|
|
|
|
|
2019-11-11 03:57:45 -05:00
|
|
|
it "does not nest constants" do
|
|
|
|
expect(bundled_app("#{gem_name}/lib/#{require_path}/version.rb").read).to match(/module TestGem/)
|
|
|
|
expect(bundled_app("#{gem_name}/lib/#{require_path}.rb").read).to match(/module TestGem/)
|
2018-11-02 19:07:56 -04:00
|
|
|
end
|
|
|
|
|
2019-11-11 03:57:45 -05:00
|
|
|
include_examples "generating a gem"
|
2018-11-02 19:07:56 -04:00
|
|
|
|
|
|
|
context "--ext parameter set" do
|
2019-11-11 03:57:45 -05:00
|
|
|
let(:flags) { "--ext" }
|
2018-11-02 19:07:56 -04:00
|
|
|
|
|
|
|
it "builds ext skeleton" do
|
2019-11-11 03:57:45 -05:00
|
|
|
expect(bundled_app("#{gem_name}/ext/#{gem_name}/extconf.rb")).to exist
|
|
|
|
expect(bundled_app("#{gem_name}/ext/#{gem_name}/#{gem_name}.h")).to exist
|
|
|
|
expect(bundled_app("#{gem_name}/ext/#{gem_name}/#{gem_name}.c")).to exist
|
2018-11-02 19:07:56 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "includes rake-compiler" do
|
2019-11-11 03:57:45 -05:00
|
|
|
expect(bundled_app("#{gem_name}/Gemfile").read).to include('gem "rake-compiler"')
|
2018-11-02 19:07:56 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "depends on compile task for build" do
|
|
|
|
rakefile = strip_whitespace <<-RAKEFILE
|
|
|
|
require "bundler/gem_tasks"
|
|
|
|
require "rake/extensiontask"
|
|
|
|
|
|
|
|
task :build => :compile
|
|
|
|
|
2019-11-11 03:57:45 -05:00
|
|
|
Rake::ExtensionTask.new("#{gem_name}") do |ext|
|
|
|
|
ext.lib_dir = "lib/#{gem_name}"
|
2018-11-02 19:07:56 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
task :default => [:clobber, :compile, :spec]
|
|
|
|
RAKEFILE
|
|
|
|
|
2019-11-11 03:57:45 -05:00
|
|
|
expect(bundled_app("#{gem_name}/Rakefile").read).to eq(rakefile)
|
2018-11-02 19:07:56 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-11-11 03:57:45 -05:00
|
|
|
context "gem naming with dashed" do
|
|
|
|
let(:gem_name) { "test-gem" }
|
|
|
|
|
|
|
|
let(:require_path) { "test/gem" }
|
|
|
|
|
|
|
|
before do
|
|
|
|
bundle! "gem #{gem_name}"
|
|
|
|
end
|
|
|
|
|
|
|
|
it "nests constants so they work" do
|
|
|
|
expect(bundled_app("#{gem_name}/lib/#{require_path}/version.rb").read).to match(/module Test\n module Gem/)
|
|
|
|
expect(bundled_app("#{gem_name}/lib/#{require_path}.rb").read).to match(/module Test\n module Gem/)
|
|
|
|
end
|
|
|
|
|
|
|
|
include_examples "generating a gem"
|
|
|
|
end
|
|
|
|
|
2018-11-02 19:07:56 -04:00
|
|
|
describe "uncommon gem names" do
|
|
|
|
it "can deal with two dashes" do
|
2019-11-11 03:57:45 -05:00
|
|
|
bundle! "gem a--a"
|
2018-11-02 19:07:56 -04:00
|
|
|
|
|
|
|
expect(bundled_app("a--a/a--a.gemspec")).to exist
|
|
|
|
end
|
|
|
|
|
|
|
|
it "fails gracefully with a ." do
|
|
|
|
bundle "gem foo.gemspec"
|
2019-06-01 05:49:40 -04:00
|
|
|
expect(err).to end_with("Invalid gem name foo.gemspec -- `Foo.gemspec` is an invalid constant name")
|
2018-11-02 19:07:56 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "fails gracefully with a ^" do
|
|
|
|
bundle "gem ^"
|
2019-06-01 05:49:40 -04:00
|
|
|
expect(err).to end_with("Invalid gem name ^ -- `^` is an invalid constant name")
|
2018-11-02 19:07:56 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "fails gracefully with a space" do
|
|
|
|
bundle "gem 'foo bar'"
|
2019-06-01 05:49:40 -04:00
|
|
|
expect(err).to end_with("Invalid gem name foo bar -- `Foo bar` is an invalid constant name")
|
2018-11-02 19:07:56 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "fails gracefully when multiple names are passed" do
|
|
|
|
bundle "gem foo bar baz"
|
2019-06-01 05:49:40 -04:00
|
|
|
expect(err).to eq(<<-E.strip)
|
2018-11-02 19:07:56 -04:00
|
|
|
ERROR: "bundle gem" was called with arguments ["foo", "bar", "baz"]
|
|
|
|
Usage: "bundle gem NAME [OPTIONS]"
|
|
|
|
E
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "#ensure_safe_gem_name" do
|
|
|
|
before do
|
|
|
|
bundle "gem #{subject}"
|
|
|
|
end
|
|
|
|
|
|
|
|
context "with an existing const name" do
|
|
|
|
subject { "gem" }
|
2019-04-14 02:01:35 -04:00
|
|
|
it { expect(err).to include("Invalid gem name #{subject}") }
|
2018-11-02 19:07:56 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context "with an existing hyphenated const name" do
|
|
|
|
subject { "gem-specification" }
|
2019-04-14 02:01:35 -04:00
|
|
|
it { expect(err).to include("Invalid gem name #{subject}") }
|
2018-11-02 19:07:56 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context "starting with an existing const name" do
|
|
|
|
subject { "gem-somenewconstantname" }
|
2019-04-14 02:01:35 -04:00
|
|
|
it { expect(err).not_to include("Invalid gem name #{subject}") }
|
2018-11-02 19:07:56 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context "ending with an existing const name" do
|
|
|
|
subject { "somenewconstantname-gem" }
|
2019-04-14 02:01:35 -04:00
|
|
|
it { expect(err).not_to include("Invalid gem name #{subject}") }
|
2018-11-02 19:07:56 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "on first run" do
|
|
|
|
it "asks about test framework" do
|
|
|
|
global_config "BUNDLE_GEM__MIT" => "false", "BUNDLE_GEM__COC" => "false"
|
|
|
|
|
|
|
|
bundle "gem foobar" do |input, _, _|
|
|
|
|
input.puts "rspec"
|
|
|
|
end
|
|
|
|
|
|
|
|
expect(bundled_app("foobar/spec/spec_helper.rb")).to exist
|
|
|
|
rakefile = strip_whitespace <<-RAKEFILE
|
|
|
|
require "bundler/gem_tasks"
|
|
|
|
require "rspec/core/rake_task"
|
|
|
|
|
|
|
|
RSpec::Core::RakeTask.new(:spec)
|
|
|
|
|
|
|
|
task :default => :spec
|
|
|
|
RAKEFILE
|
|
|
|
|
|
|
|
expect(bundled_app("foobar/Rakefile").read).to eq(rakefile)
|
2019-06-26 10:35:49 -04:00
|
|
|
expect(bundled_app("foobar/Gemfile").read).to include('gem "rspec"')
|
2018-11-02 19:07:56 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "asks about MIT license" do
|
|
|
|
global_config "BUNDLE_GEM__TEST" => "false", "BUNDLE_GEM__COC" => "false"
|
|
|
|
|
2019-04-14 02:01:35 -04:00
|
|
|
bundle "config list"
|
2018-11-02 19:07:56 -04:00
|
|
|
|
|
|
|
bundle "gem foobar" do |input, _, _|
|
|
|
|
input.puts "yes"
|
|
|
|
end
|
|
|
|
|
|
|
|
expect(bundled_app("foobar/LICENSE.txt")).to exist
|
|
|
|
end
|
|
|
|
|
|
|
|
it "asks about CoC" do
|
|
|
|
global_config "BUNDLE_GEM__MIT" => "false", "BUNDLE_GEM__TEST" => "false"
|
|
|
|
|
|
|
|
bundle "gem foobar" do |input, _, _|
|
|
|
|
input.puts "yes"
|
|
|
|
end
|
|
|
|
|
|
|
|
expect(bundled_app("foobar/CODE_OF_CONDUCT.md")).to exist
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "on conflicts with a previously created file" do
|
|
|
|
it "should fail gracefully" do
|
2019-11-11 03:57:45 -05:00
|
|
|
FileUtils.touch("conflict-foobar")
|
2018-11-02 19:07:56 -04:00
|
|
|
bundle "gem conflict-foobar"
|
2019-06-01 05:49:40 -04:00
|
|
|
expect(err).to include("Errno::ENOTDIR")
|
2018-11-02 19:07:56 -04:00
|
|
|
expect(exitstatus).to eql(32) if exitstatus
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "on conflicts with a previously created directory" do
|
|
|
|
it "should succeed" do
|
2019-11-11 03:57:45 -05:00
|
|
|
FileUtils.mkdir_p("conflict-foobar/Gemfile")
|
2018-11-02 19:07:56 -04:00
|
|
|
bundle! "gem conflict-foobar"
|
2019-06-01 05:49:40 -04:00
|
|
|
expect(out).to include("file_clash conflict-foobar/Gemfile").
|
2018-11-02 19:07:56 -04:00
|
|
|
and include "Initializing git repo in #{bundled_app("conflict-foobar")}"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|