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
|
|
|
|
|
2020-06-30 12:38:54 -04:00
|
|
|
def bundle_exec_rubocop
|
|
|
|
prepare_gemspec(bundled_app(gem_name, "#{gem_name}.gemspec"))
|
2021-04-14 23:47:04 -04:00
|
|
|
bundle "config set path #{rubocop_gems}", :dir => bundled_app(gem_name)
|
2020-10-15 00:20:25 -04:00
|
|
|
bundle "exec rubocop --debug --config .rubocop.yml", :dir => bundled_app(gem_name)
|
2020-06-30 12:38:54 -04:00
|
|
|
end
|
|
|
|
|
2021-04-14 23:47:04 -04:00
|
|
|
def bundle_exec_standardrb
|
|
|
|
prepare_gemspec(bundled_app(gem_name, "#{gem_name}.gemspec"))
|
|
|
|
bundle "config set path #{standard_gems}", :dir => bundled_app(gem_name)
|
|
|
|
bundle "exec standardrb --debug", :dir => bundled_app(gem_name)
|
|
|
|
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
|
|
|
|
2022-01-12 12:10:34 -05:00
|
|
|
let(:minitest_test_file_path) { "test/test_mygem.rb" }
|
|
|
|
|
2022-01-14 12:55:41 -05:00
|
|
|
let(:minitest_test_class_name) { "class TestMygem < Minitest::Test" }
|
|
|
|
|
2018-11-02 19:07:56 -04:00
|
|
|
before do
|
2021-02-01 10:17:16 -05:00
|
|
|
sys_exec("git config --global user.name 'Bundler User'")
|
|
|
|
sys_exec("git config --global user.email user@example.com")
|
|
|
|
sys_exec("git config --global github.user bundleuser")
|
2018-11-02 19:07:56 -04:00
|
|
|
end
|
|
|
|
|
2019-07-24 06:24:55 -04:00
|
|
|
describe "git repo initialization" do
|
2021-08-04 02:36:21 -04:00
|
|
|
it "generates a gem skeleton with a .git folder", :readline do
|
|
|
|
bundle "gem #{gem_name}"
|
|
|
|
gem_skeleton_assertions
|
|
|
|
expect(bundled_app("#{gem_name}/.git")).to exist
|
2019-07-24 06:24:55 -04:00
|
|
|
end
|
|
|
|
|
2021-08-04 02:36:21 -04:00
|
|
|
it "generates a gem skeleton with a .git folder when passing --git", :readline do
|
|
|
|
bundle "gem #{gem_name} --git"
|
|
|
|
gem_skeleton_assertions
|
|
|
|
expect(bundled_app("#{gem_name}/.git")).to exist
|
2019-07-24 06:24:55 -04:00
|
|
|
end
|
|
|
|
|
2021-08-04 02:36:21 -04:00
|
|
|
it "generates a gem skeleton without a .git folder when passing --no-git", :readline do
|
|
|
|
bundle "gem #{gem_name} --no-git"
|
|
|
|
gem_skeleton_assertions
|
|
|
|
expect(bundled_app("#{gem_name}/.git")).not_to exist
|
2019-07-24 06:24:55 -04:00
|
|
|
end
|
2021-08-04 02:40:56 -04:00
|
|
|
|
|
|
|
context "on a path with spaces" do
|
|
|
|
before do
|
|
|
|
Dir.mkdir(bundled_app("path with spaces"))
|
|
|
|
end
|
|
|
|
|
|
|
|
it "properly initializes git repo", :readline do
|
|
|
|
bundle "gem #{gem_name}", :dir => bundled_app("path with spaces")
|
|
|
|
expect(bundled_app("path with spaces/#{gem_name}/.git")).to exist
|
|
|
|
end
|
|
|
|
end
|
2019-07-24 06:24:55 -04:00
|
|
|
end
|
|
|
|
|
2018-11-02 19:07:56 -04:00
|
|
|
shared_examples_for "--mit flag" do
|
|
|
|
before do
|
2020-06-03 14:45:36 -04: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
|
2020-06-03 14:45:36 -04: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
|
|
|
|
it "generates a gem skeleton with MIT license" do
|
2021-02-01 10:17:16 -05:00
|
|
|
bundle "gem #{gem_name} --coc"
|
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
|
|
|
|
|
2021-02-01 10:17:16 -05:00
|
|
|
it "generates the README with a section for the Code of Conduct" do
|
|
|
|
bundle "gem #{gem_name} --coc"
|
|
|
|
expect(bundled_app("#{gem_name}/README.md").read).to include("## Code of Conduct")
|
|
|
|
expect(bundled_app("#{gem_name}/README.md").read).to match(%r{https://github\.com/bundleuser/#{gem_name}/blob/.*/CODE_OF_CONDUCT.md})
|
|
|
|
end
|
|
|
|
|
2021-04-14 23:47:04 -04:00
|
|
|
it "generates the README with a section for the Code of Conduct, respecting the configured git default branch", :git => ">= 2.28.0" do
|
2021-02-01 10:17:16 -05:00
|
|
|
sys_exec("git config --global init.defaultBranch main")
|
|
|
|
bundle "gem #{gem_name} --coc"
|
|
|
|
|
|
|
|
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/main/CODE_OF_CONDUCT.md")
|
2018-11-02 19:07:56 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples_for "--no-coc flag" do
|
|
|
|
before do
|
2020-06-03 14:45:36 -04: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
|
|
|
|
|
2021-02-01 10:17:16 -05:00
|
|
|
it "generates the README without a section for the Code of Conduct" do
|
|
|
|
expect(bundled_app("#{gem_name}/README.md").read).not_to include("## Code of Conduct")
|
|
|
|
expect(bundled_app("#{gem_name}/README.md").read).not_to match(%r{https://github\.com/bundleuser/#{gem_name}/blob/.*/CODE_OF_CONDUCT.md})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples_for "--changelog flag" do
|
|
|
|
before do
|
|
|
|
bundle "gem #{gem_name} --changelog"
|
|
|
|
end
|
|
|
|
it "generates a gem skeleton with a CHANGELOG", :readline do
|
|
|
|
gem_skeleton_assertions
|
|
|
|
expect(bundled_app("#{gem_name}/CHANGELOG.md")).to exist
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples_for "--no-changelog flag" do
|
|
|
|
before do
|
|
|
|
bundle "gem #{gem_name} --no-changelog"
|
|
|
|
end
|
|
|
|
it "generates a gem skeleton without a CHANGELOG", :readline do
|
|
|
|
gem_skeleton_assertions
|
|
|
|
expect(bundled_app("#{gem_name}/CHANGELOG.md")).to_not exist
|
2018-11-02 19:07:56 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-05-08 01:19:04 -04:00
|
|
|
shared_examples_for "--rubocop flag" do
|
2021-04-14 23:47:04 -04:00
|
|
|
context "is deprecated", :bundler => "< 3" do
|
|
|
|
before do
|
|
|
|
bundle "gem #{gem_name} --rubocop"
|
|
|
|
end
|
|
|
|
|
|
|
|
it "generates a gem skeleton with rubocop" do
|
|
|
|
gem_skeleton_assertions
|
|
|
|
expect(bundled_app("test-gem/Rakefile")).to read_as(
|
|
|
|
include("# frozen_string_literal: true").
|
|
|
|
and(include('require "rubocop/rake_task"').
|
|
|
|
and(include("RuboCop::RakeTask.new").
|
|
|
|
and(match(/default:.+:rubocop/))))
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "includes rubocop in generated Gemfile" do
|
|
|
|
allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile)
|
|
|
|
builder = Bundler::Dsl.new
|
|
|
|
builder.eval_gemfile(bundled_app("#{gem_name}/Gemfile"))
|
|
|
|
builder.dependencies
|
|
|
|
rubocop_dep = builder.dependencies.find {|d| d.name == "rubocop" }
|
|
|
|
expect(rubocop_dep).not_to be_nil
|
|
|
|
end
|
|
|
|
|
|
|
|
it "generates a default .rubocop.yml" do
|
|
|
|
expect(bundled_app("#{gem_name}/.rubocop.yml")).to exist
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples_for "--no-rubocop flag" do
|
|
|
|
context "is deprecated", :bundler => "< 3" do
|
|
|
|
define_negated_matcher :exclude, :include
|
|
|
|
|
|
|
|
before do
|
|
|
|
bundle "gem #{gem_name} --no-rubocop"
|
|
|
|
end
|
|
|
|
|
|
|
|
it "generates a gem skeleton without rubocop" do
|
|
|
|
gem_skeleton_assertions
|
|
|
|
expect(bundled_app("test-gem/Rakefile")).to read_as(exclude("rubocop"))
|
|
|
|
expect(bundled_app("test-gem/#{gem_name}.gemspec")).to read_as(exclude("rubocop"))
|
|
|
|
end
|
|
|
|
|
|
|
|
it "does not include rubocop in generated Gemfile" do
|
|
|
|
allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile)
|
|
|
|
builder = Bundler::Dsl.new
|
|
|
|
builder.eval_gemfile(bundled_app("#{gem_name}/Gemfile"))
|
|
|
|
builder.dependencies
|
|
|
|
rubocop_dep = builder.dependencies.find {|d| d.name == "rubocop" }
|
|
|
|
expect(rubocop_dep).to be_nil
|
|
|
|
end
|
|
|
|
|
|
|
|
it "doesn't generate a default .rubocop.yml" do
|
|
|
|
expect(bundled_app("#{gem_name}/.rubocop.yml")).to_not exist
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples_for "--linter=rubocop flag" do
|
2020-05-08 01:19:04 -04:00
|
|
|
before do
|
2021-04-14 23:47:04 -04:00
|
|
|
bundle "gem #{gem_name} --linter=rubocop"
|
2020-05-08 01:19:04 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "generates a gem skeleton with rubocop" do
|
|
|
|
gem_skeleton_assertions
|
|
|
|
expect(bundled_app("test-gem/Rakefile")).to read_as(
|
2020-06-20 16:37:14 -04:00
|
|
|
include("# frozen_string_literal: true").
|
2020-06-20 16:12:34 -04:00
|
|
|
and(include('require "rubocop/rake_task"').
|
2020-05-08 01:19:04 -04:00
|
|
|
and(include("RuboCop::RakeTask.new").
|
2020-06-20 16:12:34 -04:00
|
|
|
and(match(/default:.+:rubocop/))))
|
2020-05-08 01:19:04 -04:00
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "includes rubocop in generated Gemfile" do
|
|
|
|
allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile)
|
|
|
|
builder = Bundler::Dsl.new
|
|
|
|
builder.eval_gemfile(bundled_app("#{gem_name}/Gemfile"))
|
|
|
|
builder.dependencies
|
|
|
|
rubocop_dep = builder.dependencies.find {|d| d.name == "rubocop" }
|
|
|
|
expect(rubocop_dep).not_to be_nil
|
|
|
|
end
|
2020-06-16 09:37:21 -04:00
|
|
|
|
|
|
|
it "generates a default .rubocop.yml" do
|
|
|
|
expect(bundled_app("#{gem_name}/.rubocop.yml")).to exist
|
|
|
|
end
|
2020-05-08 01:19:04 -04:00
|
|
|
end
|
|
|
|
|
2021-04-14 23:47:04 -04:00
|
|
|
shared_examples_for "--linter=standard flag" do
|
|
|
|
before do
|
|
|
|
bundle "gem #{gem_name} --linter=standard"
|
|
|
|
end
|
|
|
|
|
|
|
|
it "generates a gem skeleton with standard" do
|
|
|
|
gem_skeleton_assertions
|
|
|
|
expect(bundled_app("test-gem/Rakefile")).to read_as(
|
|
|
|
include('require "standard/rake"').
|
|
|
|
and(match(/default:.+:standard/))
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "includes standard in generated Gemfile" do
|
|
|
|
allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile)
|
|
|
|
builder = Bundler::Dsl.new
|
|
|
|
builder.eval_gemfile(bundled_app("#{gem_name}/Gemfile"))
|
|
|
|
builder.dependencies
|
|
|
|
standard_dep = builder.dependencies.find {|d| d.name == "standard" }
|
|
|
|
expect(standard_dep).not_to be_nil
|
|
|
|
end
|
|
|
|
|
|
|
|
it "generates a default .standard.yml" do
|
|
|
|
expect(bundled_app("#{gem_name}/.standard.yml")).to exist
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples_for "--linter=none flag" do
|
2020-05-08 01:19:04 -04:00
|
|
|
define_negated_matcher :exclude, :include
|
|
|
|
|
|
|
|
before do
|
2021-04-14 23:47:04 -04:00
|
|
|
bundle "gem #{gem_name} --linter=none"
|
2020-05-08 01:19:04 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "generates a gem skeleton without rubocop" do
|
|
|
|
gem_skeleton_assertions
|
|
|
|
expect(bundled_app("test-gem/Rakefile")).to read_as(exclude("rubocop"))
|
|
|
|
expect(bundled_app("test-gem/#{gem_name}.gemspec")).to read_as(exclude("rubocop"))
|
|
|
|
end
|
|
|
|
|
|
|
|
it "does not include rubocop in generated Gemfile" do
|
|
|
|
allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile)
|
|
|
|
builder = Bundler::Dsl.new
|
|
|
|
builder.eval_gemfile(bundled_app("#{gem_name}/Gemfile"))
|
|
|
|
builder.dependencies
|
|
|
|
rubocop_dep = builder.dependencies.find {|d| d.name == "rubocop" }
|
|
|
|
expect(rubocop_dep).to be_nil
|
|
|
|
end
|
2020-06-16 09:37:21 -04:00
|
|
|
|
2021-04-14 23:47:04 -04:00
|
|
|
it "does not include standard in generated Gemfile" do
|
|
|
|
allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile)
|
|
|
|
builder = Bundler::Dsl.new
|
|
|
|
builder.eval_gemfile(bundled_app("#{gem_name}/Gemfile"))
|
|
|
|
builder.dependencies
|
|
|
|
standard_dep = builder.dependencies.find {|d| d.name == "standard" }
|
|
|
|
expect(standard_dep).to be_nil
|
|
|
|
end
|
|
|
|
|
2020-06-16 09:37:21 -04:00
|
|
|
it "doesn't generate a default .rubocop.yml" do
|
|
|
|
expect(bundled_app("#{gem_name}/.rubocop.yml")).to_not exist
|
|
|
|
end
|
2021-04-14 23:47:04 -04:00
|
|
|
|
|
|
|
it "doesn't generate a default .standard.yml" do
|
|
|
|
expect(bundled_app("#{gem_name}/.standard.yml")).to_not exist
|
|
|
|
end
|
2020-05-08 01:19:04 -04:00
|
|
|
end
|
|
|
|
|
2021-04-14 23:47:04 -04:00
|
|
|
it "has no rubocop offenses when using --linter=rubocop flag", :readline do
|
2020-06-30 12:38:54 -04:00
|
|
|
skip "ruby_core has an 'ast.rb' file that gets in the middle and breaks this spec" if ruby_core?
|
2021-04-14 23:47:04 -04:00
|
|
|
bundle "gem #{gem_name} --linter=rubocop"
|
2020-06-30 12:38:54 -04:00
|
|
|
bundle_exec_rubocop
|
2021-07-13 07:58:08 -04:00
|
|
|
expect(last_command).to be_success
|
2020-06-30 12:38:54 -04:00
|
|
|
end
|
|
|
|
|
2021-04-14 23:47:04 -04:00
|
|
|
it "has no rubocop offenses when using --ext and --linter=rubocop flag", :readline do
|
2020-06-30 12:38:54 -04:00
|
|
|
skip "ruby_core has an 'ast.rb' file that gets in the middle and breaks this spec" if ruby_core?
|
2021-04-14 23:47:04 -04:00
|
|
|
bundle "gem #{gem_name} --ext --linter=rubocop"
|
2020-06-30 12:38:54 -04:00
|
|
|
bundle_exec_rubocop
|
2021-07-13 07:58:08 -04:00
|
|
|
expect(last_command).to be_success
|
2020-06-30 12:38:54 -04:00
|
|
|
end
|
|
|
|
|
2021-04-14 23:47:04 -04:00
|
|
|
it "has no rubocop offenses when using --ext, --test=minitest, and --linter=rubocop flag", :readline do
|
2020-06-30 12:38:54 -04:00
|
|
|
skip "ruby_core has an 'ast.rb' file that gets in the middle and breaks this spec" if ruby_core?
|
2021-04-14 23:47:04 -04:00
|
|
|
bundle "gem #{gem_name} --ext --test=minitest --linter=rubocop"
|
2020-06-30 12:38:54 -04:00
|
|
|
bundle_exec_rubocop
|
2021-07-13 07:58:08 -04:00
|
|
|
expect(last_command).to be_success
|
2020-06-30 12:38:54 -04:00
|
|
|
end
|
|
|
|
|
2021-04-14 23:47:04 -04:00
|
|
|
it "has no rubocop offenses when using --ext, --test=rspec, and --linter=rubocop flag", :readline do
|
2020-06-30 12:38:54 -04:00
|
|
|
skip "ruby_core has an 'ast.rb' file that gets in the middle and breaks this spec" if ruby_core?
|
2021-04-14 23:47:04 -04:00
|
|
|
bundle "gem #{gem_name} --ext --test=rspec --linter=rubocop"
|
2020-06-30 12:38:54 -04:00
|
|
|
bundle_exec_rubocop
|
2021-07-13 07:58:08 -04:00
|
|
|
expect(last_command).to be_success
|
2020-06-30 12:38:54 -04:00
|
|
|
end
|
|
|
|
|
2021-04-14 23:47:04 -04:00
|
|
|
it "has no rubocop offenses when using --ext, --ext=test-unit, and --linter=rubocop flag", :readline do
|
2020-06-30 12:38:54 -04:00
|
|
|
skip "ruby_core has an 'ast.rb' file that gets in the middle and breaks this spec" if ruby_core?
|
2021-04-14 23:47:04 -04:00
|
|
|
bundle "gem #{gem_name} --ext --test=test-unit --linter=rubocop"
|
2020-06-30 12:38:54 -04:00
|
|
|
bundle_exec_rubocop
|
2021-07-13 07:58:08 -04:00
|
|
|
expect(last_command).to be_success
|
2020-06-30 12:38:54 -04:00
|
|
|
end
|
|
|
|
|
2021-04-14 23:47:04 -04:00
|
|
|
it "has no standard offenses when using --linter=standard flag", :readline do
|
|
|
|
skip "ruby_core has an 'ast.rb' file that gets in the middle and breaks this spec" if ruby_core?
|
|
|
|
bundle "gem #{gem_name} --linter=standard"
|
|
|
|
bundle_exec_standardrb
|
2021-07-13 07:58:08 -04:00
|
|
|
expect(last_command).to be_success
|
2021-04-14 23:47:04 -04:00
|
|
|
end
|
|
|
|
|
2020-05-28 03:21:04 -04:00
|
|
|
shared_examples_for "CI config is absent" do
|
|
|
|
it "does not create any CI files" do
|
|
|
|
expect(bundled_app("#{gem_name}/.github/workflows/main.yml")).to_not exist
|
|
|
|
expect(bundled_app("#{gem_name}/.travis.yml")).to_not exist
|
|
|
|
expect(bundled_app("#{gem_name}/.gitlab-ci.yml")).to_not exist
|
|
|
|
expect(bundled_app("#{gem_name}/.circleci/config.yml")).to_not exist
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-04-24 04:00:59 -04:00
|
|
|
shared_examples_for "test framework is absent" do
|
|
|
|
it "does not create any test framework files" do
|
|
|
|
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/test_helper.rb")).to_not exist
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-05-08 01:19:04 -04:00
|
|
|
context "README.md", :readline do
|
2018-11-02 19:07:56 -04:00
|
|
|
context "git config github.user present" do
|
|
|
|
before do
|
2020-06-03 14:45:36 -04: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
|
2021-02-01 10:17:16 -05:00
|
|
|
sys_exec("git config --global --unset github.user")
|
2020-06-03 14:45:36 -04:00
|
|
|
bundle "gem #{gem_name}"
|
2018-11-02 19:07:56 -04:00
|
|
|
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
|
|
|
|
|
2020-05-08 01:19:04 -04:00
|
|
|
it "creates a new git repository", :readline do
|
2020-06-03 14:45:36 -04:00
|
|
|
bundle "gem #{gem_name}"
|
2019-11-11 03:57:45 -05:00
|
|
|
expect(bundled_app("#{gem_name}/.git")).to exist
|
2018-11-02 19:07:56 -04:00
|
|
|
end
|
|
|
|
|
2020-05-08 01:19:04 -04:00
|
|
|
context "when git is not available", :readline do
|
2018-11-02 19:07:56 -04:00
|
|
|
# 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)}"
|
|
|
|
|
2020-06-03 14:46:35 -04:00
|
|
|
sys_exec "#{Gem.ruby} #{load_path_str} #{bindir.join("bundle")} gem #{gem_name}", :env => { "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
|
|
|
|
|
2020-05-16 06:47:24 -04:00
|
|
|
it "generates a valid gemspec", :readline, :ruby_repo do
|
2020-06-03 14:45:36 -04:00
|
|
|
bundle "gem newgem --bin"
|
2018-11-02 19:07:56 -04:00
|
|
|
|
2019-05-31 05:03:11 -04:00
|
|
|
prepare_gemspec(bundled_app("newgem", "newgem.gemspec"))
|
2018-11-02 19:07:56 -04:00
|
|
|
|
2020-05-08 01:19:04 -04:00
|
|
|
gems = ["rake-13.0.1"]
|
|
|
|
path = Bundler.feature_flag.default_install_uses_path? ? local_gem_path(:base => bundled_app("newgem")) : system_gem_path
|
|
|
|
system_gems gems, :path => path
|
2020-06-03 14:45:36 -04:00
|
|
|
bundle "exec rake build", :dir => bundled_app("newgem")
|
2018-11-02 19:07:56 -04:00
|
|
|
|
|
|
|
expect(last_command.stdboth).not_to include("ERROR")
|
|
|
|
end
|
|
|
|
|
2020-05-08 01:19:04 -04:00
|
|
|
context "gem naming with relative paths", :readline do
|
2018-11-02 19:07:56 -04:00
|
|
|
it "resolves ." do
|
|
|
|
create_temporary_dir("tmp")
|
|
|
|
|
2020-06-03 14:45:36 -04:00
|
|
|
bundle "gem .", :dir => bundled_app("tmp")
|
2018-11-02 19:07:56 -04:00
|
|
|
|
|
|
|
expect(bundled_app("tmp/lib/tmp.rb")).to exist
|
|
|
|
end
|
|
|
|
|
|
|
|
it "resolves .." do
|
|
|
|
create_temporary_dir("temp/empty_dir")
|
|
|
|
|
2020-06-03 14:45:36 -04:00
|
|
|
bundle "gem ..", :dir => bundled_app("temp/empty_dir")
|
2018-11-02 19:07:56 -04:00
|
|
|
|
|
|
|
expect(bundled_app("temp/lib/temp.rb")).to exist
|
|
|
|
end
|
|
|
|
|
|
|
|
it "resolves relative directory" do
|
|
|
|
create_temporary_dir("tmp/empty/tmp")
|
|
|
|
|
2020-06-03 14:45:36 -04:00
|
|
|
bundle "gem ../../empty", :dir => bundled_app("tmp/empty/tmp")
|
2018-11-02 19:07:56 -04:00
|
|
|
|
|
|
|
expect(bundled_app("tmp/empty/lib/empty.rb")).to exist
|
|
|
|
end
|
|
|
|
|
|
|
|
def create_temporary_dir(dir)
|
2020-05-08 01:19:04 -04:00
|
|
|
FileUtils.mkdir_p(bundled_app(dir))
|
2018-11-02 19:07:56 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-04-14 23:47:04 -04:00
|
|
|
shared_examples_for "--github-username option" do |github_username|
|
|
|
|
before do
|
|
|
|
bundle "gem #{gem_name} --github-username=#{github_username}"
|
|
|
|
end
|
|
|
|
|
|
|
|
it "generates a gem skeleton" do
|
|
|
|
gem_skeleton_assertions
|
|
|
|
end
|
|
|
|
|
|
|
|
it "contribute URL set to given github username" do
|
|
|
|
expect(bundled_app("#{gem_name}/README.md").read).not_to include("[USERNAME]")
|
|
|
|
expect(bundled_app("#{gem_name}/README.md").read).to include("github.com/#{github_username}")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples_for "github_username configuration" do
|
|
|
|
context "with github_username setting set to some value" do
|
|
|
|
before do
|
|
|
|
global_config "BUNDLE_GEM__GITHUB_USERNAME" => "different_username"
|
|
|
|
bundle "gem #{gem_name}"
|
|
|
|
end
|
|
|
|
|
|
|
|
it "generates a gem skeleton" do
|
|
|
|
gem_skeleton_assertions
|
|
|
|
end
|
|
|
|
|
|
|
|
it "contribute URL set to bundle config setting" do
|
|
|
|
expect(bundled_app("#{gem_name}/README.md").read).not_to include("[USERNAME]")
|
|
|
|
expect(bundled_app("#{gem_name}/README.md").read).to include("github.com/different_username")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "with github_username setting set to false" do
|
|
|
|
before do
|
|
|
|
global_config "BUNDLE_GEM__GITHUB_USERNAME" => "false"
|
|
|
|
bundle "gem #{gem_name}"
|
|
|
|
end
|
|
|
|
|
|
|
|
it "generates a gem skeleton" do
|
|
|
|
gem_skeleton_assertions
|
|
|
|
end
|
|
|
|
|
|
|
|
it "contribute URL set to [USERNAME]" do
|
|
|
|
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")
|
|
|
|
end
|
|
|
|
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
|
2020-06-03 14:45:36 -04:00
|
|
|
bundle "gem #{gem_name}"
|
2019-11-11 03:57:45 -05:00
|
|
|
|
|
|
|
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
|
2021-11-30 21:00:10 -05:00
|
|
|
expect(bundled_app("#{gem_name}/sig/#{require_path}.rbs")).to exist
|
2019-11-11 03:57:45 -05:00
|
|
|
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
|
2020-09-02 23:30:55 -04:00
|
|
|
expect(bundled_app("#{gem_name}/bin/setup").read).to start_with("#!")
|
|
|
|
expect(bundled_app("#{gem_name}/bin/console").read).to start_with("#!")
|
2018-11-02 19:07:56 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "starts with version 0.1.0" do
|
2020-06-03 14:45:36 -04: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
|
|
|
|
|
2021-11-30 21:00:10 -05:00
|
|
|
it "declare String type for VERSION constant" do
|
|
|
|
bundle "gem #{gem_name}"
|
|
|
|
|
|
|
|
expect(bundled_app("#{gem_name}/sig/#{require_path}.rbs").read).to match(/VERSION: String/)
|
|
|
|
end
|
|
|
|
|
2019-11-11 03:57:45 -05:00
|
|
|
context "git config user.{name,email} is set" do
|
|
|
|
before do
|
2020-06-03 14:45:36 -04:00
|
|
|
bundle "gem #{gem_name}"
|
2019-11-11 03:57:45 -05:00
|
|
|
end
|
|
|
|
|
2021-02-01 10:17:16 -05:00
|
|
|
it "sets gemspec author to git user.name if available" do
|
|
|
|
expect(generated_gemspec.authors.first).to eq("Bundler User")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "sets gemspec email to git user.email if available" do
|
|
|
|
expect(generated_gemspec.email.first).to eq("user@example.com")
|
|
|
|
end
|
2019-11-11 03:57:45 -05:00
|
|
|
end
|
2018-11-02 19:07:56 -04:00
|
|
|
|
|
|
|
context "git config user.{name,email} is not set" do
|
|
|
|
before do
|
2021-02-01 10:17:16 -05:00
|
|
|
sys_exec("git config --global --unset user.name")
|
|
|
|
sys_exec("git config --global --unset user.email")
|
2020-06-03 14:45:36 -04:00
|
|
|
bundle "gem #{gem_name}"
|
2018-11-02 19:07:56 -04:00
|
|
|
end
|
|
|
|
|
2021-02-01 10:17:16 -05:00
|
|
|
it "sets gemspec author to default message if git user.name is not set or empty" do
|
|
|
|
expect(generated_gemspec.authors.first).to eq("TODO: Write your name")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "sets gemspec email to default message if git user.email is not set or empty" do
|
|
|
|
expect(generated_gemspec.email.first).to eq("TODO: Write your email address")
|
|
|
|
end
|
2018-11-02 19:07:56 -04:00
|
|
|
end
|
|
|
|
|
2019-04-14 02:01:35 -04:00
|
|
|
it "sets gemspec metadata['allowed_push_host']" do
|
2020-06-03 14:45:36 -04:00
|
|
|
bundle "gem #{gem_name}"
|
2019-11-11 03:57:45 -05:00
|
|
|
|
2019-06-17 04:23:47 -04:00
|
|
|
expect(generated_gemspec.metadata["allowed_push_host"]).
|
2021-09-17 12:41:05 -04:00
|
|
|
to match(/example\.com/)
|
2018-11-02 19:07:56 -04:00
|
|
|
end
|
|
|
|
|
2016-03-26 06:47:43 -04:00
|
|
|
it "sets a minimum ruby version" do
|
2020-06-03 14:45:36 -04:00
|
|
|
bundle "gem #{gem_name}"
|
2019-11-11 03:57:45 -05:00
|
|
|
|
2021-09-20 10:18:14 -04:00
|
|
|
expect(generated_gemspec.required_ruby_version.to_s).to start_with(">=")
|
2016-03-26 06:47:43 -04:00
|
|
|
end
|
|
|
|
|
2018-11-02 19:07:56 -04:00
|
|
|
it "requires the version file" do
|
2020-06-03 14:45:36 -04:00
|
|
|
bundle "gem #{gem_name}"
|
2019-11-11 03:57:45 -05:00
|
|
|
|
2020-12-08 02:36:29 -05:00
|
|
|
expect(bundled_app("#{gem_name}/lib/#{require_path}.rb").read).to match(%r{require_relative "#{require_relative_path}/version"})
|
2018-11-02 19:07:56 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "creates a base error class" do
|
2020-06-03 14:45:36 -04:00
|
|
|
bundle "gem #{gem_name}"
|
2019-11-11 03:57:45 -05:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2020-12-20 04:48:15 -05:00
|
|
|
it "does not include the gemspec file in files" do
|
|
|
|
bundle "gem #{gem_name}"
|
|
|
|
|
|
|
|
bundler_gemspec = Bundler::GemHelper.new(gemspec_dir).gemspec
|
|
|
|
|
|
|
|
expect(bundler_gemspec.files).not_to include("#{gem_name}.gemspec")
|
|
|
|
end
|
|
|
|
|
2018-11-02 19:07:56 -04:00
|
|
|
it "runs rake without problems" do
|
2020-06-03 14:45:36 -04:00
|
|
|
bundle "gem #{gem_name}"
|
2019-11-11 03:57:45 -05:00
|
|
|
|
2020-05-08 01:19:04 -04:00
|
|
|
system_gems ["rake-13.0.1"]
|
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
|
|
|
|
|
2020-05-08 01:19:04 -04:00
|
|
|
sys_exec(rake, :dir => bundled_app(gem_name))
|
|
|
|
expect(out).to include("SUCCESS")
|
2018-11-02 19:07:56 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context "--exe parameter set" do
|
|
|
|
before do
|
2020-06-03 14:45:36 -04:00
|
|
|
bundle "gem #{gem_name} --exe"
|
2018-11-02 19:07:56 -04:00
|
|
|
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
|
2020-06-03 14:45:36 -04:00
|
|
|
bundle "gem #{gem_name} --bin"
|
2018-11-02 19:07:56 -04:00
|
|
|
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
|
2020-06-03 14:45:36 -04:00
|
|
|
bundle "gem #{gem_name}"
|
2018-11-02 19:07:56 -04:00
|
|
|
end
|
|
|
|
|
2020-04-24 04:00:59 -04:00
|
|
|
it_behaves_like "test framework is absent"
|
2018-11-02 19:07:56 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context "--test parameter set to rspec" do
|
|
|
|
before do
|
2020-06-03 14:45:36 -04:00
|
|
|
bundle "gem #{gem_name} --test=rspec"
|
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}/.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
|
2020-05-08 01:19:04 -04:00
|
|
|
allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile)
|
|
|
|
builder = Bundler::Dsl.new
|
|
|
|
builder.eval_gemfile(bundled_app("#{gem_name}/Gemfile"))
|
|
|
|
builder.dependencies
|
|
|
|
rspec_dep = builder.dependencies.find {|d| d.name == "rspec" }
|
|
|
|
expect(rspec_dep).to be_specific
|
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
|
2020-06-03 14:45:36 -04:00
|
|
|
bundle "config set gem.test rspec"
|
|
|
|
bundle "gem #{gem_name}"
|
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}/.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
|
2020-06-03 14:45:36 -04:00
|
|
|
bundle "config set gem.test rspec"
|
|
|
|
bundle "gem #{gem_name} --test=minitest"
|
2018-11-02 19:07:56 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "builds spec skeleton" do
|
2022-01-12 12:10:34 -05:00
|
|
|
expect(bundled_app("#{gem_name}/#{minitest_test_file_path}")).to exist
|
2019-11-11 03:57:45 -05:00
|
|
|
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
|
2020-06-03 14:45:36 -04:00
|
|
|
bundle "gem #{gem_name} --test=minitest"
|
2018-11-02 19:07:56 -04:00
|
|
|
end
|
|
|
|
|
2019-04-14 02:01:35 -04:00
|
|
|
it "depends on a specific version of minitest" do
|
2020-05-08 01:19:04 -04:00
|
|
|
allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile)
|
|
|
|
builder = Bundler::Dsl.new
|
|
|
|
builder.eval_gemfile(bundled_app("#{gem_name}/Gemfile"))
|
|
|
|
builder.dependencies
|
|
|
|
minitest_dep = builder.dependencies.find {|d| d.name == "minitest" }
|
|
|
|
expect(minitest_dep).to be_specific
|
2018-11-02 19:07:56 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "builds spec skeleton" do
|
2022-01-12 12:10:34 -05:00
|
|
|
expect(bundled_app("#{gem_name}/#{minitest_test_file_path}")).to exist
|
2019-11-11 03:57:45 -05:00
|
|
|
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
|
|
|
|
|
2020-05-08 01:19:04 -04:00
|
|
|
it "requires 'test_helper'" do
|
2022-01-12 12:10:34 -05:00
|
|
|
expect(bundled_app("#{gem_name}/#{minitest_test_file_path}").read).to include(%(require "test_helper"))
|
2018-11-02 19:07:56 -04:00
|
|
|
end
|
|
|
|
|
2022-01-14 12:55:41 -05:00
|
|
|
it "defines valid test class name" do
|
|
|
|
expect(bundled_app("#{gem_name}/#{minitest_test_file_path}").read).to include(minitest_test_class_name)
|
|
|
|
end
|
|
|
|
|
2018-11-02 19:07:56 -04:00
|
|
|
it "creates a default test which fails" do
|
2022-01-12 12:10:34 -05:00
|
|
|
expect(bundled_app("#{gem_name}/#{minitest_test_file_path}").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
|
2020-06-03 14:45:36 -04:00
|
|
|
bundle "config set gem.test minitest"
|
|
|
|
bundle "gem #{gem_name}"
|
2020-05-08 01:19:04 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "creates a default rake task to run the test suite" do
|
|
|
|
rakefile = strip_whitespace <<-RAKEFILE
|
2020-06-19 08:54:11 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2020-05-08 01:19:04 -04:00
|
|
|
require "bundler/gem_tasks"
|
|
|
|
require "rake/testtask"
|
|
|
|
|
|
|
|
Rake::TestTask.new(:test) do |t|
|
|
|
|
t.libs << "test"
|
|
|
|
t.libs << "lib"
|
2021-01-03 20:11:34 -05:00
|
|
|
t.test_files = FileList["test/**/test_*.rb"]
|
2020-05-08 01:19:04 -04:00
|
|
|
end
|
|
|
|
|
2020-06-20 16:12:34 -04:00
|
|
|
task default: :test
|
2020-05-08 01:19:04 -04:00
|
|
|
RAKEFILE
|
|
|
|
|
|
|
|
expect(bundled_app("#{gem_name}/Rakefile").read).to eq(rakefile)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "--test parameter set to test-unit" do
|
|
|
|
before do
|
2020-06-03 14:45:36 -04:00
|
|
|
bundle "gem #{gem_name} --test=test-unit"
|
2020-05-08 01:19:04 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "depends on a specific version of test-unit" do
|
|
|
|
allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile)
|
|
|
|
builder = Bundler::Dsl.new
|
|
|
|
builder.eval_gemfile(bundled_app("#{gem_name}/Gemfile"))
|
|
|
|
builder.dependencies
|
|
|
|
test_unit_dep = builder.dependencies.find {|d| d.name == "test-unit" }
|
|
|
|
expect(test_unit_dep).to be_specific
|
|
|
|
end
|
|
|
|
|
|
|
|
it "builds spec skeleton" do
|
|
|
|
expect(bundled_app("#{gem_name}/test/#{require_path}_test.rb")).to exist
|
|
|
|
expect(bundled_app("#{gem_name}/test/test_helper.rb")).to exist
|
|
|
|
end
|
|
|
|
|
|
|
|
it "requires the main file" do
|
|
|
|
expect(bundled_app("#{gem_name}/test/test_helper.rb").read).to include(%(require "#{require_path}"))
|
|
|
|
end
|
|
|
|
|
|
|
|
it "requires 'test_helper'" do
|
|
|
|
expect(bundled_app("#{gem_name}/test/#{require_path}_test.rb").read).to include(%(require "test_helper"))
|
|
|
|
end
|
|
|
|
|
|
|
|
it "creates a default test which fails" do
|
|
|
|
expect(bundled_app("#{gem_name}/test/#{require_path}_test.rb").read).to include("assert_equal(\"expected\", \"actual\")")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-05-28 03:37:05 -04:00
|
|
|
context "gem.test setting set to test-unit" do
|
|
|
|
before do
|
2020-06-03 14:45:36 -04:00
|
|
|
bundle "config set gem.test test-unit"
|
|
|
|
bundle "gem #{gem_name}"
|
2020-05-28 03:37:05 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "creates a default rake task to run the test suite" do
|
|
|
|
rakefile = strip_whitespace <<-RAKEFILE
|
2020-06-19 08:54:11 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2020-05-28 03:37:05 -04:00
|
|
|
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
|
|
|
|
|
2020-06-20 16:12:34 -04:00
|
|
|
task default: :test
|
2020-05-28 03:37:05 -04:00
|
|
|
RAKEFILE
|
|
|
|
|
|
|
|
expect(bundled_app("#{gem_name}/Rakefile").read).to eq(rakefile)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "gem.test set to rspec and --test with no arguments", :hint_text do
|
|
|
|
before do
|
2020-06-03 14:45:36 -04:00
|
|
|
bundle "config set gem.test rspec"
|
|
|
|
bundle "gem #{gem_name} --test"
|
2020-05-28 03:37:05 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "builds spec skeleton" do
|
|
|
|
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
|
|
|
|
end
|
|
|
|
|
2020-06-02 16:09:47 -04:00
|
|
|
it "hints that --test is already configured" do
|
|
|
|
expect(out).to match("rspec is already configured, ignoring --test flag.")
|
2020-05-28 03:37:05 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "gem.test setting set to false and --test with no arguments", :hint_text do
|
|
|
|
before do
|
2020-06-03 14:45:36 -04:00
|
|
|
bundle "config set gem.test false"
|
|
|
|
bundle "gem #{gem_name} --test"
|
2020-05-28 03:37:05 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "asks to generate test files" do
|
|
|
|
expect(out).to match("Do you want to generate tests with your gem?")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "hints that the choice will only be applied to the current gem" do
|
|
|
|
expect(out).to match("Your choice will only be applied to this gem.")
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like "test framework is absent"
|
|
|
|
end
|
|
|
|
|
|
|
|
context "gem.test setting not set and --test with no arguments", :hint_text do
|
|
|
|
before do
|
2020-06-03 14:45:36 -04:00
|
|
|
bundle "gem #{gem_name} --test"
|
2020-05-28 03:37:05 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "asks to generate test files" do
|
|
|
|
expect(out).to match("Do you want to generate tests with your gem?")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "hints that the choice will be applied to future bundle gem calls" do
|
|
|
|
hint = "Future `bundle gem` calls will use your choice. " \
|
|
|
|
"This setting can be changed anytime with `bundle config gem.test`."
|
|
|
|
expect(out).to match(hint)
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like "test framework is absent"
|
|
|
|
end
|
|
|
|
|
2020-05-29 10:37:45 -04:00
|
|
|
context "--ci with no argument" do
|
2020-06-11 08:54:04 -04:00
|
|
|
it "does not generate any CI config" do
|
2020-06-03 14:45:36 -04:00
|
|
|
bundle "gem #{gem_name}"
|
2020-06-11 08:54:04 -04:00
|
|
|
|
|
|
|
expect(bundled_app("#{gem_name}/.github/workflows/main.yml")).to_not exist
|
|
|
|
expect(bundled_app("#{gem_name}/.travis.yml")).to_not exist
|
|
|
|
expect(bundled_app("#{gem_name}/.gitlab-ci.yml")).to_not exist
|
|
|
|
expect(bundled_app("#{gem_name}/.circleci/config.yml")).to_not exist
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "--ci set to github" do
|
2020-05-28 05:48:15 -04:00
|
|
|
it "generates a GitHub Actions config file" do
|
2020-06-03 14:45:36 -04:00
|
|
|
bundle "gem #{gem_name} --ci=github"
|
2020-06-11 08:54:04 -04:00
|
|
|
|
|
|
|
expect(bundled_app("#{gem_name}/.github/workflows/main.yml")).to exist
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "--ci set to gitlab" do
|
2020-05-28 05:48:15 -04:00
|
|
|
it "generates a GitLab CI config file" do
|
2020-06-03 14:45:36 -04:00
|
|
|
bundle "gem #{gem_name} --ci=gitlab"
|
2020-06-11 08:54:04 -04:00
|
|
|
|
|
|
|
expect(bundled_app("#{gem_name}/.gitlab-ci.yml")).to exist
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "--ci set to circle" do
|
2020-05-28 05:48:15 -04:00
|
|
|
it "generates a CircleCI config file" do
|
2020-06-03 14:45:36 -04:00
|
|
|
bundle "gem #{gem_name} --ci=circle"
|
2020-06-11 08:54:04 -04:00
|
|
|
|
|
|
|
expect(bundled_app("#{gem_name}/.circleci/config.yml")).to exist
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "--ci set to travis" do
|
2020-05-28 05:48:15 -04:00
|
|
|
it "generates a Travis CI config file" do
|
2020-06-03 14:45:36 -04:00
|
|
|
bundle "gem #{gem_name} --ci=travis"
|
2020-06-11 08:54:04 -04:00
|
|
|
|
|
|
|
expect(bundled_app("#{gem_name}/.travis.yml")).to exist
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "gem.ci setting set to none" do
|
2020-05-28 05:48:15 -04:00
|
|
|
it "doesn't generate any CI config" do
|
2020-06-11 08:54:04 -04:00
|
|
|
expect(bundled_app("#{gem_name}/.github/workflows/main.yml")).to_not exist
|
|
|
|
expect(bundled_app("#{gem_name}/.travis.yml")).to_not exist
|
|
|
|
expect(bundled_app("#{gem_name}/.gitlab-ci.yml")).to_not exist
|
|
|
|
expect(bundled_app("#{gem_name}/.circleci/config.yml")).to_not exist
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "gem.ci setting set to github" do
|
2020-05-28 05:48:15 -04:00
|
|
|
it "generates a GitHub Actions config file" do
|
2020-06-03 14:45:36 -04:00
|
|
|
bundle "config set gem.ci github"
|
|
|
|
bundle "gem #{gem_name}"
|
2020-06-11 08:54:04 -04:00
|
|
|
|
|
|
|
expect(bundled_app("#{gem_name}/.github/workflows/main.yml")).to exist
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "gem.ci setting set to travis" do
|
2020-05-28 05:48:15 -04:00
|
|
|
it "generates a Travis CI config file" do
|
2020-06-03 14:45:36 -04:00
|
|
|
bundle "config set gem.ci travis"
|
|
|
|
bundle "gem #{gem_name}"
|
2020-06-11 08:54:04 -04:00
|
|
|
|
|
|
|
expect(bundled_app("#{gem_name}/.travis.yml")).to exist
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "gem.ci setting set to gitlab" do
|
2020-05-28 05:48:15 -04:00
|
|
|
it "generates a GitLab CI config file" do
|
2020-06-03 14:45:36 -04:00
|
|
|
bundle "config set gem.ci gitlab"
|
|
|
|
bundle "gem #{gem_name}"
|
2020-06-11 08:54:04 -04:00
|
|
|
|
|
|
|
expect(bundled_app("#{gem_name}/.gitlab-ci.yml")).to exist
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-05-28 05:48:15 -04:00
|
|
|
context "gem.ci setting set to circle" do
|
2020-06-11 08:54:04 -04:00
|
|
|
it "generates a CircleCI config file" do
|
2020-06-03 14:45:36 -04:00
|
|
|
bundle "config set gem.ci circle"
|
|
|
|
bundle "gem #{gem_name}"
|
2020-06-11 08:54:04 -04:00
|
|
|
|
|
|
|
expect(bundled_app("#{gem_name}/.circleci/config.yml")).to exist
|
|
|
|
end
|
|
|
|
end
|
2020-05-30 05:06:57 -04:00
|
|
|
|
|
|
|
context "gem.ci set to github and --ci with no arguments", :hint_text do
|
|
|
|
before do
|
2020-06-03 14:45:36 -04:00
|
|
|
bundle "config set gem.ci github"
|
|
|
|
bundle "gem #{gem_name} --ci"
|
2020-05-30 05:06:57 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "generates a GitHub Actions config file" do
|
|
|
|
expect(bundled_app("#{gem_name}/.github/workflows/main.yml")).to exist
|
|
|
|
end
|
|
|
|
|
2020-06-01 20:59:53 -04:00
|
|
|
it "hints that --ci is already configured" do
|
|
|
|
expect(out).to match("github is already configured, ignoring --ci flag.")
|
2020-05-30 05:06:57 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "gem.ci setting set to false and --ci with no arguments", :hint_text do
|
|
|
|
before do
|
2020-06-03 14:45:36 -04:00
|
|
|
bundle "config set gem.ci false"
|
|
|
|
bundle "gem #{gem_name} --ci"
|
2020-05-30 05:06:57 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "asks to setup CI" do
|
2020-05-31 02:58:16 -04:00
|
|
|
expect(out).to match("Do you want to set up continuous integration for your gem?")
|
2020-05-30 05:06:57 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "hints that the choice will only be applied to the current gem" do
|
|
|
|
expect(out).to match("Your choice will only be applied to this gem.")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "gem.ci setting not set and --ci with no arguments", :hint_text do
|
|
|
|
before do
|
2020-06-03 14:45:36 -04:00
|
|
|
bundle "gem #{gem_name} --ci"
|
2020-05-30 05:06:57 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "asks to setup CI" do
|
2020-05-31 02:58:16 -04:00
|
|
|
expect(out).to match("Do you want to set up continuous integration for your gem?")
|
2020-05-30 05:06:57 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "hints that the choice will be applied to future bundle gem calls" do
|
|
|
|
hint = "Future `bundle gem` calls will use your choice. " \
|
|
|
|
"This setting can be changed anytime with `bundle config gem.ci`."
|
|
|
|
expect(out).to match(hint)
|
|
|
|
end
|
|
|
|
end
|
2018-11-02 19:07:56 -04:00
|
|
|
|
2021-04-14 23:47:04 -04:00
|
|
|
context "--linter with no argument" do
|
|
|
|
it "does not generate any linter config" do
|
|
|
|
bundle "gem #{gem_name}"
|
|
|
|
|
|
|
|
expect(bundled_app("#{gem_name}/.rubocop.yml")).to_not exist
|
|
|
|
expect(bundled_app("#{gem_name}/.standard.yml")).to_not exist
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "--linter set to rubocop" do
|
|
|
|
it "generates a RuboCop config" do
|
|
|
|
bundle "gem #{gem_name} --linter=rubocop"
|
|
|
|
|
|
|
|
expect(bundled_app("#{gem_name}/.rubocop.yml")).to exist
|
|
|
|
expect(bundled_app("#{gem_name}/.standard.yml")).to_not exist
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "--linter set to standard" do
|
|
|
|
it "generates a Standard config" do
|
|
|
|
bundle "gem #{gem_name} --linter=standard"
|
|
|
|
|
|
|
|
expect(bundled_app("#{gem_name}/.standard.yml")).to exist
|
|
|
|
expect(bundled_app("#{gem_name}/.rubocop.yml")).to_not exist
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "gem.linter setting set to none" do
|
|
|
|
it "doesn't generate any linter config" do
|
|
|
|
bundle "gem #{gem_name}"
|
|
|
|
|
|
|
|
expect(bundled_app("#{gem_name}/.rubocop.yml")).to_not exist
|
|
|
|
expect(bundled_app("#{gem_name}/.standard.yml")).to_not exist
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "gem.linter setting set to rubocop" do
|
|
|
|
it "generates a RuboCop config file" do
|
|
|
|
bundle "config set gem.linter rubocop"
|
|
|
|
bundle "gem #{gem_name}"
|
|
|
|
|
|
|
|
expect(bundled_app("#{gem_name}/.rubocop.yml")).to exist
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "gem.linter setting set to standard" do
|
|
|
|
it "generates a Standard config file" do
|
|
|
|
bundle "config set gem.linter standard"
|
|
|
|
bundle "gem #{gem_name}"
|
|
|
|
|
|
|
|
expect(bundled_app("#{gem_name}/.standard.yml")).to exist
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "gem.rubocop setting set to true", :bundler => "< 3" do
|
|
|
|
before do
|
|
|
|
bundle "config set gem.rubocop true"
|
|
|
|
bundle "gem #{gem_name}"
|
|
|
|
end
|
|
|
|
|
|
|
|
it "generates rubocop config" do
|
|
|
|
expect(bundled_app("#{gem_name}/.rubocop.yml")).to exist
|
|
|
|
end
|
|
|
|
|
|
|
|
it "unsets gem.rubocop" do
|
|
|
|
bundle "config gem.rubocop"
|
|
|
|
expect(out).to include("You have not configured a value for `gem.rubocop`")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "sets gem.linter=rubocop instead" do
|
|
|
|
bundle "config gem.linter"
|
|
|
|
expect(out).to match(/Set for the current user .*: "rubocop"/)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "gem.linter set to rubocop and --linter with no arguments", :hint_text do
|
|
|
|
before do
|
|
|
|
bundle "config set gem.linter rubocop"
|
|
|
|
bundle "gem #{gem_name} --linter"
|
|
|
|
end
|
|
|
|
|
|
|
|
it "generates a RuboCop config file" do
|
|
|
|
expect(bundled_app("#{gem_name}/.rubocop.yml")).to exist
|
|
|
|
end
|
|
|
|
|
|
|
|
it "hints that --linter is already configured" do
|
|
|
|
expect(out).to match("rubocop is already configured, ignoring --linter flag.")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "gem.linter setting set to false and --linter with no arguments", :hint_text do
|
|
|
|
before do
|
|
|
|
bundle "config set gem.linter false"
|
|
|
|
bundle "gem #{gem_name} --linter"
|
|
|
|
end
|
|
|
|
|
|
|
|
it "asks to setup a linter" do
|
|
|
|
expect(out).to match("Do you want to add a code linter and formatter to your gem?")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "hints that the choice will only be applied to the current gem" do
|
|
|
|
expect(out).to match("Your choice will only be applied to this gem.")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "gem.linter setting not set and --linter with no arguments", :hint_text do
|
|
|
|
before do
|
|
|
|
bundle "gem #{gem_name} --linter"
|
|
|
|
end
|
|
|
|
|
|
|
|
it "asks to setup a linter" do
|
|
|
|
expect(out).to match("Do you want to add a code linter and formatter to your gem?")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "hints that the choice will be applied to future bundle gem calls" do
|
|
|
|
hint = "Future `bundle gem` calls will use your choice. " \
|
|
|
|
"This setting can be changed anytime with `bundle config gem.linter`."
|
|
|
|
expect(out).to match(hint)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-11-02 19:07:56 -04:00
|
|
|
context "--edit option" do
|
|
|
|
it "opens the generated gemspec in the user's text editor" do
|
2020-06-03 14:45:36 -04:00
|
|
|
output = bundle "gem #{gem_name} --edit=echo"
|
2020-05-08 01:19:04 -04:00
|
|
|
gemspec_path = File.join(bundled_app, gem_name, "#{gem_name}.gemspec")
|
2018-11-02 19:07:56 -04:00
|
|
|
expect(output).to include("echo \"#{gemspec_path}\"")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-05-08 01:19:04 -04:00
|
|
|
context "testing --mit and --coc options against bundle config settings", :readline do
|
2018-11-02 19:07:56 -04:00
|
|
|
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
|
2020-05-08 01:19:04 -04:00
|
|
|
global_config "BUNDLE_GEM__MIT" => "true"
|
2018-11-02 19:07:56 -04:00
|
|
|
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
|
2020-05-08 01:19:04 -04:00
|
|
|
before do
|
|
|
|
global_config "BUNDLE_GEM__MIT" => "false"
|
|
|
|
end
|
2018-11-02 19:07:56 -04:00
|
|
|
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
|
2020-05-08 01:19:04 -04:00
|
|
|
global_config "BUNDLE_GEM__COC" => "true"
|
2018-11-02 19:07:56 -04:00
|
|
|
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
|
2020-05-08 01:19:04 -04:00
|
|
|
before do
|
|
|
|
global_config "BUNDLE_GEM__COC" => "false"
|
|
|
|
end
|
2018-11-02 19:07:56 -04:00
|
|
|
it_behaves_like "--coc flag"
|
|
|
|
it_behaves_like "--no-coc flag"
|
|
|
|
end
|
2020-05-08 01:19:04 -04:00
|
|
|
|
|
|
|
context "with rubocop option in bundle config settings set to true" do
|
|
|
|
before do
|
|
|
|
global_config "BUNDLE_GEM__RUBOCOP" => "true"
|
|
|
|
end
|
2021-04-14 23:47:04 -04:00
|
|
|
it_behaves_like "--linter=rubocop flag"
|
|
|
|
it_behaves_like "--linter=standard flag"
|
|
|
|
it_behaves_like "--linter=none flag"
|
2020-05-08 01:19:04 -04:00
|
|
|
it_behaves_like "--rubocop flag"
|
|
|
|
it_behaves_like "--no-rubocop flag"
|
|
|
|
end
|
|
|
|
|
|
|
|
context "with rubocop option in bundle config settings set to false" do
|
|
|
|
before do
|
|
|
|
global_config "BUNDLE_GEM__RUBOCOP" => "false"
|
|
|
|
end
|
2021-04-14 23:47:04 -04:00
|
|
|
it_behaves_like "--linter=rubocop flag"
|
|
|
|
it_behaves_like "--linter=standard flag"
|
|
|
|
it_behaves_like "--linter=none flag"
|
2020-05-08 01:19:04 -04:00
|
|
|
it_behaves_like "--rubocop flag"
|
|
|
|
it_behaves_like "--no-rubocop flag"
|
|
|
|
end
|
2021-02-01 10:17:16 -05:00
|
|
|
|
2021-04-14 23:47:04 -04:00
|
|
|
context "with linter option in bundle config settings set to rubocop" do
|
|
|
|
before do
|
|
|
|
global_config "BUNDLE_GEM__LINTER" => "rubocop"
|
|
|
|
end
|
|
|
|
it_behaves_like "--linter=rubocop flag"
|
|
|
|
it_behaves_like "--linter=standard flag"
|
|
|
|
it_behaves_like "--linter=none flag"
|
|
|
|
end
|
|
|
|
|
|
|
|
context "with linter option in bundle config settings set to standard" do
|
|
|
|
before do
|
|
|
|
global_config "BUNDLE_GEM__LINTER" => "standard"
|
|
|
|
end
|
|
|
|
it_behaves_like "--linter=rubocop flag"
|
|
|
|
it_behaves_like "--linter=standard flag"
|
|
|
|
it_behaves_like "--linter=none flag"
|
|
|
|
end
|
|
|
|
|
|
|
|
context "with linter option in bundle config settings set to false" do
|
|
|
|
before do
|
|
|
|
global_config "BUNDLE_GEM__LINTER" => "false"
|
|
|
|
end
|
|
|
|
it_behaves_like "--linter=rubocop flag"
|
|
|
|
it_behaves_like "--linter=standard flag"
|
|
|
|
it_behaves_like "--linter=none flag"
|
|
|
|
end
|
|
|
|
|
2021-02-01 10:17:16 -05:00
|
|
|
context "with changelog option in bundle config settings set to true" do
|
|
|
|
before do
|
|
|
|
global_config "BUNDLE_GEM__CHANGELOG" => "true"
|
|
|
|
end
|
|
|
|
it_behaves_like "--changelog flag"
|
|
|
|
it_behaves_like "--no-changelog flag"
|
|
|
|
end
|
|
|
|
|
|
|
|
context "with changelog option in bundle config settings set to false" do
|
|
|
|
before do
|
|
|
|
global_config "BUNDLE_GEM__CHANGELOG" => "false"
|
|
|
|
end
|
|
|
|
it_behaves_like "--changelog flag"
|
|
|
|
it_behaves_like "--no-changelog flag"
|
|
|
|
end
|
2018-11-02 19:07:56 -04:00
|
|
|
end
|
|
|
|
|
2021-04-14 23:47:04 -04:00
|
|
|
context "testing --github-username option against git and bundle config settings", :readline do
|
|
|
|
context "without git config set" do
|
|
|
|
before do
|
|
|
|
sys_exec("git config --global --unset github.user")
|
|
|
|
end
|
|
|
|
context "with github-username option in bundle config settings set to some value" do
|
|
|
|
before do
|
|
|
|
global_config "BUNDLE_GEM__GITHUB_USERNAME" => "different_username"
|
|
|
|
end
|
|
|
|
it_behaves_like "--github-username option", "gh_user"
|
|
|
|
end
|
|
|
|
|
|
|
|
context "with github-username option in bundle config settings set to false" do
|
|
|
|
before do
|
|
|
|
global_config "BUNDLE_GEM__GITHUB_USERNAME" => "false"
|
|
|
|
end
|
|
|
|
it_behaves_like "--github-username option", "gh_user"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "with git config set" do
|
|
|
|
context "with github-username option in bundle config settings set to some value" do
|
|
|
|
before do
|
|
|
|
global_config "BUNDLE_GEM__GITHUB_USERNAME" => "different_username"
|
|
|
|
end
|
|
|
|
it_behaves_like "--github-username option", "gh_user"
|
|
|
|
end
|
|
|
|
|
|
|
|
context "with github-username option in bundle config settings set to false" do
|
|
|
|
before do
|
|
|
|
global_config "BUNDLE_GEM__GITHUB_USERNAME" => "false"
|
|
|
|
end
|
|
|
|
it_behaves_like "--github-username option", "gh_user"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "testing github_username bundle config against git config settings", :readline do
|
|
|
|
context "without git config set" do
|
|
|
|
before do
|
|
|
|
sys_exec("git config --global --unset github.user")
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like "github_username configuration"
|
|
|
|
end
|
|
|
|
|
|
|
|
context "with git config set" do
|
|
|
|
it_behaves_like "github_username configuration"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-05-08 01:19:04 -04:00
|
|
|
context "gem naming with underscore", :readline do
|
2019-11-11 03:57:45 -05:00
|
|
|
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
|
|
|
|
2020-12-08 02:36:29 -05:00
|
|
|
let(:require_relative_path) { "test_gem" }
|
|
|
|
|
2022-01-12 12:10:34 -05:00
|
|
|
let(:minitest_test_file_path) { "test/test_test_gem.rb" }
|
|
|
|
|
2022-01-14 12:55:41 -05:00
|
|
|
let(:minitest_test_class_name) { "class TestTestGem < Minitest::Test" }
|
|
|
|
|
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
|
|
|
it "does not nest constants" do
|
2020-06-03 14:45:36 -04:00
|
|
|
bundle ["gem", gem_name, flags].compact.join(" ")
|
2019-11-11 03:57:45 -05:00
|
|
|
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
|
|
|
|
2020-05-08 01:19:04 -04:00
|
|
|
before do
|
2020-06-03 14:45:36 -04:00
|
|
|
bundle ["gem", gem_name, flags].compact.join(" ")
|
2020-05-08 01:19:04 -04:00
|
|
|
end
|
|
|
|
|
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
|
2020-06-19 08:54:11 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-11-02 19:07:56 -04:00
|
|
|
require "bundler/gem_tasks"
|
|
|
|
require "rake/extensiontask"
|
|
|
|
|
2020-06-19 08:54:11 -04:00
|
|
|
task build: :compile
|
2018-11-02 19:07:56 -04:00
|
|
|
|
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
|
|
|
|
|
2020-06-30 05:12:59 -04:00
|
|
|
task default: %i[clobber compile]
|
2018-11-02 19:07:56 -04:00
|
|
|
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
|
|
|
|
|
2020-05-08 01:19:04 -04:00
|
|
|
context "gem naming with dashed", :readline do
|
2019-11-11 03:57:45 -05:00
|
|
|
let(:gem_name) { "test-gem" }
|
|
|
|
|
|
|
|
let(:require_path) { "test/gem" }
|
|
|
|
|
2020-12-08 02:36:29 -05:00
|
|
|
let(:require_relative_path) { "gem" }
|
|
|
|
|
2022-01-12 12:10:34 -05:00
|
|
|
let(:minitest_test_file_path) { "test/test/test_gem.rb" }
|
|
|
|
|
2022-01-19 03:52:27 -05:00
|
|
|
let(:minitest_test_class_name) { "class Test::TestGem < Minitest::Test" }
|
2022-01-14 12:55:41 -05:00
|
|
|
|
2019-11-11 03:57:45 -05:00
|
|
|
it "nests constants so they work" do
|
2020-06-03 14:45:36 -04:00
|
|
|
bundle "gem #{gem_name}"
|
2019-11-11 03:57:45 -05:00
|
|
|
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
|
2020-05-08 01:19:04 -04:00
|
|
|
it "can deal with two dashes", :readline do
|
2020-06-03 14:45:36 -04: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
|
2020-06-03 12:43:17 -04:00
|
|
|
bundle "gem foo.gemspec", :raise_on_error => false
|
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
|
2020-06-03 12:43:17 -04:00
|
|
|
bundle "gem ^", :raise_on_error => false
|
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
|
2020-06-03 12:43:17 -04:00
|
|
|
bundle "gem 'foo bar'", :raise_on_error => false
|
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
|
2020-06-03 12:43:17 -04:00
|
|
|
bundle "gem foo bar baz", :raise_on_error => false
|
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
|
|
|
|
|
2020-05-08 01:19:04 -04:00
|
|
|
describe "#ensure_safe_gem_name", :readline do
|
2018-11-02 19:07:56 -04:00
|
|
|
before do
|
2020-06-03 12:43:17 -04:00
|
|
|
bundle "gem #{subject}", :raise_on_error => false
|
2018-11-02 19:07:56 -04:00
|
|
|
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
|
|
|
|
|
2020-05-08 01:19:04 -04:00
|
|
|
context "on first run", :readline do
|
2018-11-02 19:07:56 -04:00
|
|
|
it "asks about test framework" do
|
|
|
|
global_config "BUNDLE_GEM__MIT" => "false", "BUNDLE_GEM__COC" => "false"
|
|
|
|
|
2020-06-03 14:45:36 -04:00
|
|
|
bundle "gem foobar" do |input, _, _|
|
2018-11-02 19:07:56 -04:00
|
|
|
input.puts "rspec"
|
|
|
|
end
|
|
|
|
|
|
|
|
expect(bundled_app("foobar/spec/spec_helper.rb")).to exist
|
|
|
|
rakefile = strip_whitespace <<-RAKEFILE
|
2020-06-19 08:54:11 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-11-02 19:07:56 -04:00
|
|
|
require "bundler/gem_tasks"
|
|
|
|
require "rspec/core/rake_task"
|
|
|
|
|
|
|
|
RSpec::Core::RakeTask.new(:spec)
|
|
|
|
|
2020-06-20 16:12:34 -04:00
|
|
|
task default: :spec
|
2018-11-02 19:07:56 -04:00
|
|
|
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
|
|
|
|
|
2020-06-11 08:54:04 -04:00
|
|
|
it "asks about CI service" do
|
2021-04-14 23:47:04 -04:00
|
|
|
global_config "BUNDLE_GEM__TEST" => "false", "BUNDLE_GEM__MIT" => "false", "BUNDLE_GEM__COC" => "false", "BUNDLE_GEM__LINTER" => "false"
|
2020-06-11 08:54:04 -04:00
|
|
|
|
2020-06-03 14:45:36 -04:00
|
|
|
bundle "gem foobar" do |input, _, _|
|
2020-06-11 08:54:04 -04:00
|
|
|
input.puts "github"
|
|
|
|
end
|
|
|
|
|
|
|
|
expect(bundled_app("foobar/.github/workflows/main.yml")).to exist
|
|
|
|
end
|
|
|
|
|
2018-11-02 19:07:56 -04:00
|
|
|
it "asks about MIT license" do
|
2021-04-14 23:47:04 -04:00
|
|
|
global_config "BUNDLE_GEM__TEST" => "false", "BUNDLE_GEM__COC" => "false", "BUNDLE_GEM__CI" => "false", "BUNDLE_GEM__LINTER" => "false"
|
2018-11-02 19:07:56 -04:00
|
|
|
|
2020-06-03 14:45:36 -04:00
|
|
|
bundle "config list"
|
2018-11-02 19:07:56 -04:00
|
|
|
|
2020-06-03 14:45:36 -04:00
|
|
|
bundle "gem foobar" do |input, _, _|
|
2018-11-02 19:07:56 -04:00
|
|
|
input.puts "yes"
|
|
|
|
end
|
|
|
|
|
|
|
|
expect(bundled_app("foobar/LICENSE.txt")).to exist
|
|
|
|
end
|
|
|
|
|
|
|
|
it "asks about CoC" do
|
2021-04-14 23:47:04 -04:00
|
|
|
global_config "BUNDLE_GEM__MIT" => "false", "BUNDLE_GEM__TEST" => "false", "BUNDLE_GEM__CI" => "false", "BUNDLE_GEM__LINTER" => "false"
|
2018-11-02 19:07:56 -04:00
|
|
|
|
2020-06-03 14:45:36 -04:00
|
|
|
bundle "gem foobar" do |input, _, _|
|
2018-11-02 19:07:56 -04:00
|
|
|
input.puts "yes"
|
|
|
|
end
|
|
|
|
|
|
|
|
expect(bundled_app("foobar/CODE_OF_CONDUCT.md")).to exist
|
|
|
|
end
|
2021-02-01 10:17:16 -05:00
|
|
|
|
|
|
|
it "asks about CHANGELOG" do
|
2021-04-14 23:47:04 -04:00
|
|
|
global_config "BUNDLE_GEM__MIT" => "false", "BUNDLE_GEM__TEST" => "false", "BUNDLE_GEM__CI" => "false", "BUNDLE_GEM__LINTER" => "false",
|
2021-02-01 10:17:16 -05:00
|
|
|
"BUNDLE_GEM__COC" => "false"
|
|
|
|
|
|
|
|
bundle "gem foobar" do |input, _, _|
|
|
|
|
input.puts "yes"
|
|
|
|
end
|
|
|
|
|
|
|
|
expect(bundled_app("foobar/CHANGELOG.md")).to exist
|
|
|
|
end
|
2018-11-02 19:07:56 -04:00
|
|
|
end
|
|
|
|
|
2020-05-08 01:19:04 -04:00
|
|
|
context "on conflicts with a previously created file", :readline do
|
2018-11-02 19:07:56 -04:00
|
|
|
it "should fail gracefully" do
|
2020-05-08 01:19:04 -04:00
|
|
|
FileUtils.touch(bundled_app("conflict-foobar"))
|
2020-06-03 12:43:17 -04:00
|
|
|
bundle "gem conflict-foobar", :raise_on_error => false
|
2021-02-01 10:17:16 -05:00
|
|
|
expect(err).to eq("Couldn't create a new gem named `conflict-foobar` because there's an existing file named `conflict-foobar`.")
|
2020-06-24 13:53:16 -04:00
|
|
|
expect(exitstatus).to eql(32)
|
2018-11-02 19:07:56 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-05-08 01:19:04 -04:00
|
|
|
context "on conflicts with a previously created directory", :readline do
|
2018-11-02 19:07:56 -04:00
|
|
|
it "should succeed" do
|
2020-05-08 01:19:04 -04:00
|
|
|
FileUtils.mkdir_p(bundled_app("conflict-foobar/Gemfile"))
|
2020-06-03 14:45:36 -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
|