summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBundlerbot <bot@bundler.io>2019-10-07 15:35:56 +0000
committerDavid Rodríguez <deivid.rodriguez@riseup.net>2019-11-07 16:41:39 +0100
commit1234f2509879db68919aedd9e4f10608d0cf932a (patch)
tree0ae83a2a7309390af385d778841416e53eba61a7
parenta8e7d8a96b9307423429ab6299467bbcbf35fad5 (diff)
downloadbundler-1234f2509879db68919aedd9e4f10608d0cf932a.tar.gz
Merge #7373
7373: Refactor new gem specs r=deivid-rodriguez a=deivid-rodriguez ### What was the end-user problem that led to this PR? The problem was that I rebased #6455 and I had trouble getting the specs to pass. ### What was your diagnosis of the problem? My diagnosis was that the new gemspecs could use a refactor. ### What is your fix for the problem, implemented in this PR? My fix is to refactor these specs so that they are easier to read and modify. Co-authored-by: David Rodríguez <deivid.rodriguez@riseup.net> (cherry picked from commit 6ceec5596d5bfadad6da9990a66514da760d7eda)
-rw-r--r--spec/commands/newgem_spec.rb470
-rw-r--r--spec/spec_helper.rb1
2 files changed, 151 insertions, 320 deletions
diff --git a/spec/commands/newgem_spec.rb b/spec/commands/newgem_spec.rb
index 32c1868cd2..18a30ca9db 100644
--- a/spec/commands/newgem_spec.rb
+++ b/spec/commands/newgem_spec.rb
@@ -1,22 +1,20 @@
# frozen_string_literal: true
RSpec.describe "bundle gem" do
- def execute_bundle_gem(gem_name, flag = "")
- bundle! "gem #{gem_name} #{flag}"
- # reset gemspec cache for each test because of commit 3d4163a
- Bundler.clear_gemspec_cache
- end
-
- def gem_skeleton_assertions(gem_name)
+ def gem_skeleton_assertions
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
- expect(bundled_app("#{gem_name}/lib/test/gem.rb")).to exist
- expect(bundled_app("#{gem_name}/lib/test/gem/version.rb")).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
end
- let(:generated_gemspec) { Bundler::GemHelper.new(bundled_app(gem_name).to_s).gemspec }
+ let(:generated_gemspec) { Bundler.load_gemspec_uncached(bundled_app(gem_name).join("#{gem_name}.gemspec")) }
+
+ let(:gem_name) { "mygem" }
+
+ let(:require_path) { "mygem" }
before do
global_config "BUNDLE_GEM__MIT" => "false", "BUNDLE_GEM__TEST" => "false", "BUNDLE_GEM__COC" => "false"
@@ -61,15 +59,14 @@ RSpec.describe "bundle gem" do
end
describe "git repo initialization" do
- let(:gem_name) { "test-gem" }
-
shared_examples_for "a gem with an initial git repo" do
before do
- execute_bundle_gem(gem_name, flags)
+ bundle! "gem #{gem_name} #{flags}"
end
+
it "generates a gem skeleton with a .git folder" do
- gem_skeleton_assertions(gem_name)
- expect(bundled_app("test-gem/.git")).to exist
+ gem_skeleton_assertions
+ expect(bundled_app("#{gem_name}/.git")).to exist
end
end
@@ -87,108 +84,101 @@ RSpec.describe "bundle gem" do
context "when passing --no-git" do
before do
- execute_bundle_gem(gem_name, "--no-git")
+ bundle! "gem #{gem_name} --no-git"
end
it "generates a gem skeleton without a .git folder" do
- gem_skeleton_assertions(gem_name)
- expect(bundled_app("test-gem/.git")).not_to exist
+ gem_skeleton_assertions
+ expect(bundled_app("#{gem_name}/.git")).not_to exist
end
end
end
shared_examples_for "--mit flag" do
before do
- execute_bundle_gem(gem_name, "--mit")
+ bundle! "gem #{gem_name} --mit"
end
it "generates a gem skeleton with MIT license" do
- gem_skeleton_assertions(gem_name)
- expect(bundled_app("test-gem/LICENSE.txt")).to exist
- skel = Bundler::GemHelper.new(bundled_app(gem_name).to_s)
- expect(skel.gemspec.license).to eq("MIT")
+ gem_skeleton_assertions
+ expect(bundled_app("#{gem_name}/LICENSE.txt")).to exist
+ expect(generated_gemspec.license).to eq("MIT")
end
end
shared_examples_for "--no-mit flag" do
before do
- execute_bundle_gem(gem_name, "--no-mit")
+ bundle! "gem #{gem_name} --no-mit"
end
it "generates a gem skeleton without MIT license" do
- gem_skeleton_assertions(gem_name)
- expect(bundled_app("test-gem/LICENSE.txt")).to_not exist
+ gem_skeleton_assertions
+ expect(bundled_app("#{gem_name}/LICENSE.txt")).to_not exist
end
end
shared_examples_for "--coc flag" do
before do
- execute_bundle_gem(gem_name, "--coc")
+ bundle! "gem #{gem_name} --coc"
end
it "generates a gem skeleton with MIT license" do
- gem_skeleton_assertions(gem_name)
- expect(bundled_app("test-gem/CODE_OF_CONDUCT.md")).to exist
+ gem_skeleton_assertions
+ expect(bundled_app("#{gem_name}/CODE_OF_CONDUCT.md")).to exist
end
describe "README additions" do
it "generates the README with a section for the Code of Conduct" do
- expect(bundled_app("test-gem/README.md").read).to include("## Code of Conduct")
- expect(bundled_app("test-gem/README.md").read).to include("https://github.com/bundleuser/#{gem_name}/blob/master/CODE_OF_CONDUCT.md")
+ 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")
end
end
end
shared_examples_for "--no-coc flag" do
before do
- execute_bundle_gem(gem_name, "--no-coc")
+ bundle! "gem #{gem_name} --no-coc"
end
it "generates a gem skeleton without Code of Conduct" do
- gem_skeleton_assertions(gem_name)
- expect(bundled_app("test-gem/CODE_OF_CONDUCT.md")).to_not exist
+ gem_skeleton_assertions
+ expect(bundled_app("#{gem_name}/CODE_OF_CONDUCT.md")).to_not exist
end
describe "README additions" do
it "generates the README without a section for the Code of Conduct" do
- expect(bundled_app("test-gem/README.md").read).not_to include("## Code of Conduct")
- expect(bundled_app("test-gem/README.md").read).not_to include("https://github.com/bundleuser/#{gem_name}/blob/master/CODE_OF_CONDUCT.md")
+ 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")
end
end
end
context "README.md" do
- let(:gem_name) { "test_gem" }
-
context "git config github.user present" do
before do
- execute_bundle_gem(gem_name)
+ bundle! "gem #{gem_name}"
end
it "contribute URL set to git username" do
- expect(bundled_app("test_gem/README.md").read).not_to include("[USERNAME]")
- expect(bundled_app("test_gem/README.md").read).to include("github.com/bundleuser")
+ 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")
end
end
context "git config github.user is absent" do
before do
sys_exec("git config --unset github.user")
- in_app_root
bundle "gem #{gem_name}"
end
it "contribute URL set to [USERNAME]" do
- expect(bundled_app("test_gem/README.md").read).to include("[USERNAME]")
- expect(bundled_app("test_gem/README.md").read).not_to include("github.com/bundleuser")
+ 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
it "creates a new git repository" do
- in_app_root
- bundle "gem test_gem"
- expect(bundled_app("test_gem/.git")).to exist
+ bundle "gem #{gem_name}"
+ expect(bundled_app("#{gem_name}/.git")).to exist
end
context "when git is not available" do
- let(:gem_name) { "test_gem" }
-
# This spec cannot have `git` available in the test env
before do
load_paths = [lib, spec]
@@ -211,7 +201,6 @@ RSpec.describe "bundle gem" do
end
it "generates a valid gemspec" do
- in_app_root
bundle! "gem newgem --bin"
prepare_gemspec(bundled_app("newgem", "newgem.gemspec"))
@@ -226,10 +215,6 @@ RSpec.describe "bundle gem" do
end
context "gem naming with relative paths" do
- before do
- in_app_root
- end
-
it "resolves ." do
create_temporary_dir("tmp")
@@ -260,43 +245,41 @@ RSpec.describe "bundle gem" do
end
end
- context "gem naming with underscore" do
- let(:gem_name) { "test_gem" }
-
- before do
- execute_bundle_gem(gem_name)
- end
-
+ shared_examples_for "generating a gem" do
it "generates a gem skeleton" do
- expect(bundled_app("test_gem/test_gem.gemspec")).to exist
- expect(bundled_app("test_gem/Gemfile")).to exist
- expect(bundled_app("test_gem/Rakefile")).to exist
- expect(bundled_app("test_gem/lib/test_gem.rb")).to exist
- expect(bundled_app("test_gem/lib/test_gem/version.rb")).to exist
- expect(bundled_app("test_gem/.gitignore")).to exist
+ 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
- expect(bundled_app("test_gem/bin/setup")).to exist
- expect(bundled_app("test_gem/bin/console")).to exist
- expect(bundled_app("test_gem/bin/setup")).to be_executable
- expect(bundled_app("test_gem/bin/console")).to be_executable
+ 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
end
it "starts with version 0.1.0" do
- expect(bundled_app("test_gem/lib/test_gem/version.rb").read).to match(/VERSION = "0.1.0"/)
- end
+ bundle! "gem #{gem_name}"
- it "does not nest constants" do
- expect(bundled_app("test_gem/lib/test_gem/version.rb").read).to match(/module TestGem/)
- expect(bundled_app("test_gem/lib/test_gem.rb").read).to match(/module TestGem/)
+ expect(bundled_app("#{gem_name}/lib/#{require_path}/version.rb").read).to match(/VERSION = "0.1.0"/)
end
- it_should_behave_like "git config is present"
+ 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
context "git config user.{name,email} is not set" do
before do
`git config --unset user.name`
`git config --unset user.email`
- in_app_root
bundle "gem #{gem_name}"
end
@@ -304,25 +287,35 @@ RSpec.describe "bundle gem" do
end
it "sets gemspec metadata['allowed_push_host']" do
+ bundle! "gem #{gem_name}"
+
expect(generated_gemspec.metadata["allowed_push_host"]).
to match(/mygemserver\.com/)
end
it "sets a minimum ruby version" do
+ bundle! "gem #{gem_name}"
+
bundler_gemspec = Bundler::GemHelper.new(gemspec_dir).gemspec
expect(bundler_gemspec.required_ruby_version).to eq(generated_gemspec.required_ruby_version)
end
it "requires the version file" do
- expect(bundled_app("test_gem/lib/test_gem.rb").read).to match(%r{require "test_gem/version"})
+ bundle! "gem #{gem_name}"
+
+ expect(bundled_app("#{gem_name}/lib/#{require_path}.rb").read).to match(%r{require "#{require_path}/version"})
end
it "creates a base error class" do
- expect(bundled_app("test_gem/lib/test_gem.rb").read).to match(/class Error < StandardError; end$/)
+ bundle! "gem #{gem_name}"
+
+ expect(bundled_app("#{gem_name}/lib/#{require_path}.rb").read).to match(/class Error < StandardError; end$/)
end
it "runs rake without problems" do
+ bundle! "gem #{gem_name}"
+
system_gems ["rake-12.3.2"]
rakefile = strip_whitespace <<-RAKEFILE
@@ -330,7 +323,7 @@ RSpec.describe "bundle gem" do
puts 'SUCCESS'
end
RAKEFILE
- File.open(bundled_app("test_gem/Rakefile"), "w") do |file|
+ File.open(bundled_app("#{gem_name}/Rakefile"), "w") do |file|
file.puts rakefile
end
@@ -342,117 +335,110 @@ RSpec.describe "bundle gem" do
context "--exe parameter set" do
before do
- in_app_root
bundle "gem #{gem_name} --exe"
end
it "builds exe skeleton" do
- expect(bundled_app("test_gem/exe/test_gem")).to exist
+ expect(bundled_app("#{gem_name}/exe/#{gem_name}")).to exist
end
- it "requires 'test-gem'" do
- expect(bundled_app("test_gem/exe/test_gem").read).to match(/require "test_gem"/)
+ it "requires the main file" do
+ expect(bundled_app("#{gem_name}/exe/#{gem_name}").read).to match(/require "#{require_path}"/)
end
end
context "--bin parameter set" do
before do
- in_app_root
bundle "gem #{gem_name} --bin"
end
it "builds exe skeleton" do
- expect(bundled_app("test_gem/exe/test_gem")).to exist
+ expect(bundled_app("#{gem_name}/exe/#{gem_name}")).to exist
end
- it "requires 'test-gem'" do
- expect(bundled_app("test_gem/exe/test_gem").read).to match(/require "test_gem"/)
+ it "requires the main file" do
+ expect(bundled_app("#{gem_name}/exe/#{gem_name}").read).to match(/require "#{require_path}"/)
end
end
context "no --test parameter" do
before do
- in_app_root
bundle "gem #{gem_name}"
end
it "doesn't create any spec/test file" do
- expect(bundled_app("test_gem/.rspec")).to_not exist
- expect(bundled_app("test_gem/spec/test_gem_spec.rb")).to_not exist
- expect(bundled_app("test_gem/spec/spec_helper.rb")).to_not exist
- expect(bundled_app("test_gem/test/test_test_gem.rb")).to_not exist
- expect(bundled_app("test_gem/test/minitest_helper.rb")).to_not exist
+ 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
end
end
context "--test parameter set to rspec" do
before do
- in_app_root
bundle "gem #{gem_name} --test=rspec"
end
it "builds spec skeleton" do
- expect(bundled_app("test_gem/.rspec")).to exist
- expect(bundled_app("test_gem/spec/test_gem_spec.rb")).to exist
- expect(bundled_app("test_gem/spec/spec_helper.rb")).to exist
+ 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
it "depends on a specific version of rspec in generated Gemfile" do
- Dir.chdir(bundled_app("test_gem")) do
+ Dir.chdir(bundled_app(gem_name)) do
builder = Bundler::Dsl.new
- builder.eval_gemfile(bundled_app("test_gem/Gemfile"))
+ 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
end
end
- it "requires 'test-gem'" do
- expect(bundled_app("test_gem/spec/spec_helper.rb").read).to include(%(require "test_gem"))
+ it "requires the main file" do
+ expect(bundled_app("#{gem_name}/spec/spec_helper.rb").read).to include(%(require "#{require_path}"))
end
it "creates a default test which fails" do
- expect(bundled_app("test_gem/spec/test_gem_spec.rb").read).to include("expect(false).to eq(true)")
+ expect(bundled_app("#{gem_name}/spec/#{require_path}_spec.rb").read).to include("expect(false).to eq(true)")
end
end
context "gem.test setting set to rspec" do
before do
- in_app_root
bundle "config set gem.test rspec"
bundle "gem #{gem_name}"
end
it "builds spec skeleton" do
- expect(bundled_app("test_gem/.rspec")).to exist
- expect(bundled_app("test_gem/spec/test_gem_spec.rb")).to exist
- expect(bundled_app("test_gem/spec/spec_helper.rb")).to exist
+ 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
end
context "gem.test setting set to rspec and --test is set to minitest" do
before do
- in_app_root
bundle "config set gem.test rspec"
bundle "gem #{gem_name} --test=minitest"
end
it "builds spec skeleton" do
- expect(bundled_app("test_gem/test/test_gem_test.rb")).to exist
- expect(bundled_app("test_gem/test/test_helper.rb")).to exist
+ expect(bundled_app("#{gem_name}/test/#{require_path}_test.rb")).to exist
+ expect(bundled_app("#{gem_name}/test/test_helper.rb")).to exist
end
end
context "--test parameter set to minitest" do
before do
- in_app_root
bundle "gem #{gem_name} --test=minitest"
end
it "depends on a specific version of minitest" do
- Dir.chdir(bundled_app("test_gem")) do
+ Dir.chdir(bundled_app(gem_name)) do
builder = Bundler::Dsl.new
- builder.eval_gemfile(bundled_app("test_gem/Gemfile"))
+ 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
@@ -460,26 +446,25 @@ RSpec.describe "bundle gem" do
end
it "builds spec skeleton" do
- expect(bundled_app("test_gem/test/test_gem_test.rb")).to exist
- expect(bundled_app("test_gem/test/test_helper.rb")).to exist
+ 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 'test-gem'" do
- expect(bundled_app("test_gem/test/test_helper.rb").read).to include(%(require "test_gem"))
+ it "requires the main file" do
+ expect(bundled_app("#{gem_name}/test/test_helper.rb").read).to include(%(require "#{require_path}"))
end
it "requires 'minitest_helper'" do
- expect(bundled_app("test_gem/test/test_gem_test.rb").read).to include(%(require "test_helper"))
+ 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("test_gem/test/test_gem_test.rb").read).to include("assert false")
+ expect(bundled_app("#{gem_name}/test/#{require_path}_test.rb").read).to include("assert false")
end
end
context "gem.test setting set to minitest" do
before do
- in_app_root
bundle "config set gem.test minitest"
bundle "gem #{gem_name}"
end
@@ -498,29 +483,27 @@ RSpec.describe "bundle gem" do
task :default => :test
RAKEFILE
- expect(bundled_app("test_gem/Rakefile").read).to eq(rakefile)
+ expect(bundled_app("#{gem_name}/Rakefile").read).to eq(rakefile)
end
end
context "--test with no arguments" do
before do
- in_app_root
bundle "gem #{gem_name} --test"
end
it "defaults to rspec" do
- expect(bundled_app("test_gem/spec/spec_helper.rb")).to exist
- expect(bundled_app("test_gem/test/minitest_helper.rb")).to_not exist
+ expect(bundled_app("#{gem_name}/spec/spec_helper.rb")).to exist
+ expect(bundled_app("#{gem_name}/test/minitest_helper.rb")).to_not exist
end
it "creates a .travis.yml file to test the library against the current Ruby version on Travis CI" do
- expect(bundled_app("test_gem/.travis.yml").read).to match(/- #{RUBY_VERSION}/)
+ expect(bundled_app("#{gem_name}/.travis.yml").read).to match(/- #{RUBY_VERSION}/)
end
end
context "--edit option" do
it "opens the generated gemspec in the user's text editor" do
- in_app_root
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}\"")
@@ -531,6 +514,8 @@ RSpec.describe "bundle gem" do
context "testing --mit and --coc options against bundle config settings" do
let(:gem_name) { "test-gem" }
+ let(:require_path) { "test/gem" }
+
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"
@@ -558,196 +543,35 @@ RSpec.describe "bundle gem" do
end
end
- context "gem naming with dashed" do
- let(:gem_name) { "test-gem" }
-
- before do
- execute_bundle_gem(gem_name)
- end
-
- it "generates a gem skeleton" do
- expect(bundled_app("test-gem/test-gem.gemspec")).to exist
- expect(bundled_app("test-gem/Gemfile")).to exist
- expect(bundled_app("test-gem/Rakefile")).to exist
- expect(bundled_app("test-gem/lib/test/gem.rb")).to exist
- expect(bundled_app("test-gem/lib/test/gem/version.rb")).to exist
- end
-
- it "starts with version 0.1.0" do
- expect(bundled_app("test-gem/lib/test/gem/version.rb").read).to match(/VERSION = "0.1.0"/)
- end
-
- it "nests constants so they work" do
- expect(bundled_app("test-gem/lib/test/gem/version.rb").read).to match(/module Test\n module Gem/)
- expect(bundled_app("test-gem/lib/test/gem.rb").read).to match(/module Test\n module Gem/)
- end
-
- it_should_behave_like "git config is present"
-
- context "git config user.{name,email} is not set" do
- before do
- `git config --unset user.name`
- `git config --unset user.email`
- in_app_root
- bundle "gem #{gem_name}"
- end
-
- it_should_behave_like "git config is absent"
- end
-
- it "requires the version file" do
- expect(bundled_app("test-gem/lib/test/gem.rb").read).to match(%r{require "test/gem/version"})
- end
-
- it "runs rake without problems" do
- system_gems ["rake-12.3.2"]
-
- rakefile = strip_whitespace <<-RAKEFILE
- task :default do
- puts 'SUCCESS'
- end
- RAKEFILE
- File.open(bundled_app("test-gem/Rakefile"), "w") do |file|
- file.puts rakefile
- end
-
- Dir.chdir(bundled_app(gem_name)) do
- sys_exec(rake)
- expect(out).to include("SUCCESS")
- end
- end
-
- context "--bin parameter set" do
- before do
- in_app_root
- bundle "gem #{gem_name} --bin"
- end
-
- it "builds bin skeleton" do
- expect(bundled_app("test-gem/exe/test-gem")).to exist
- end
-
- it "requires 'test/gem'" do
- expect(bundled_app("test-gem/exe/test-gem").read).to match(%r{require "test/gem"})
- end
- end
-
- context "no --test parameter" do
- before do
- in_app_root
- bundle "gem #{gem_name}"
- end
-
- it "doesn't create any spec/test file" do
- expect(bundled_app("test-gem/.rspec")).to_not exist
- expect(bundled_app("test-gem/spec/test/gem_spec.rb")).to_not exist
- expect(bundled_app("test-gem/spec/spec_helper.rb")).to_not exist
- expect(bundled_app("test-gem/test/test_test/gem.rb")).to_not exist
- expect(bundled_app("test-gem/test/minitest_helper.rb")).to_not exist
- end
- end
-
- context "--test parameter set to rspec" do
- before do
- in_app_root
- bundle "gem #{gem_name} --test=rspec"
- end
-
- it "builds spec skeleton" do
- expect(bundled_app("test-gem/.rspec")).to exist
- expect(bundled_app("test-gem/spec/test/gem_spec.rb")).to exist
- expect(bundled_app("test-gem/spec/spec_helper.rb")).to exist
- end
-
- it "requires 'test/gem'" do
- expect(bundled_app("test-gem/spec/spec_helper.rb").read).to include(%(require "test/gem"))
- end
-
- it "creates a default test which fails" do
- expect(bundled_app("test-gem/spec/test/gem_spec.rb").read).to include("expect(false).to eq(true)")
- end
-
- it "creates a default rake task to run the specs" do
- rakefile = strip_whitespace <<-RAKEFILE
- require "bundler/gem_tasks"
- require "rspec/core/rake_task"
+ context "gem naming with underscore" do
+ let(:gem_name) { "test_gem" }
- RSpec::Core::RakeTask.new(:spec)
+ let(:require_path) { "test_gem" }
- task :default => :spec
- RAKEFILE
+ let(:flags) { nil }
- expect(bundled_app("test-gem/Rakefile").read).to eq(rakefile)
- end
+ before do
+ bundle! ["gem", gem_name, flags].compact.join(" ")
end
- context "--test parameter set to minitest" do
- before do
- in_app_root
- bundle "gem #{gem_name} --test=minitest"
- end
-
- it "builds spec skeleton" do
- expect(bundled_app("test-gem/test/test/gem_test.rb")).to exist
- expect(bundled_app("test-gem/test/test_helper.rb")).to exist
- end
-
- it "requires 'test/gem'" do
- expect(bundled_app("test-gem/test/test_helper.rb").read).to match(%r{require "test/gem"})
- end
-
- it "requires 'test_helper'" do
- expect(bundled_app("test-gem/test/test/gem_test.rb").read).to match(/require "test_helper"/)
- end
-
- it "creates a default test which fails" do
- expect(bundled_app("test-gem/test/test/gem_test.rb").read).to match(/assert false/)
- 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
-
- expect(bundled_app("test-gem/Rakefile").read).to eq(rakefile)
- end
+ 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/)
end
- context "--test with no arguments" do
- before do
- in_app_root
- bundle "gem #{gem_name} --test"
- end
-
- it "defaults to rspec" do
- expect(bundled_app("test-gem/spec/spec_helper.rb")).to exist
- expect(bundled_app("test-gem/test/minitest_helper.rb")).to_not exist
- end
- end
+ include_examples "generating a gem"
context "--ext parameter set" do
- before do
- in_app_root
- bundle "gem test_gem --ext"
- end
+ let(:flags) { "--ext" }
it "builds ext skeleton" do
- expect(bundled_app("test_gem/ext/test_gem/extconf.rb")).to exist
- expect(bundled_app("test_gem/ext/test_gem/test_gem.h")).to exist
- expect(bundled_app("test_gem/ext/test_gem/test_gem.c")).to exist
+ 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
end
it "includes rake-compiler" do
- expect(bundled_app("test_gem/Gemfile").read).to include('gem "rake-compiler"')
+ expect(bundled_app("#{gem_name}/Gemfile").read).to include('gem "rake-compiler"')
end
it "depends on compile task for build" do
@@ -757,21 +581,38 @@ RSpec.describe "bundle gem" do
task :build => :compile
- Rake::ExtensionTask.new("test_gem") do |ext|
- ext.lib_dir = "lib/test_gem"
+ Rake::ExtensionTask.new("#{gem_name}") do |ext|
+ ext.lib_dir = "lib/#{gem_name}"
end
task :default => [:clobber, :compile, :spec]
RAKEFILE
- expect(bundled_app("test_gem/Rakefile").read).to eq(rakefile)
+ expect(bundled_app("#{gem_name}/Rakefile").read).to eq(rakefile)
end
end
end
+ 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
+
describe "uncommon gem names" do
it "can deal with two dashes" do
- execute_bundle_gem("a--a")
+ bundle! "gem a--a"
expect(bundled_app("a--a/a--a.gemspec")).to exist
end
@@ -804,9 +645,6 @@ Usage: "bundle gem NAME [OPTIONS]"
before do
bundle "gem #{subject}"
end
- after do
- Bundler.clear_gemspec_cache
- end
context "with an existing const name" do
subject { "gem" }
@@ -830,10 +668,6 @@ Usage: "bundle gem NAME [OPTIONS]"
end
context "on first run" do
- before do
- in_app_root
- end
-
it "asks about test framework" do
global_config "BUNDLE_GEM__MIT" => "false", "BUNDLE_GEM__COC" => "false"
@@ -880,9 +714,7 @@ Usage: "bundle gem NAME [OPTIONS]"
context "on conflicts with a previously created file" do
it "should fail gracefully" do
- in_app_root do
- FileUtils.touch("conflict-foobar")
- end
+ FileUtils.touch("conflict-foobar")
bundle "gem conflict-foobar"
expect(err).to include("Errno::ENOTDIR")
expect(exitstatus).to eql(32) if exitstatus
@@ -891,9 +723,7 @@ Usage: "bundle gem NAME [OPTIONS]"
context "on conflicts with a previously created directory" do
it "should succeed" do
- in_app_root do
- FileUtils.mkdir_p("conflict-foobar/Gemfile")
- end
+ FileUtils.mkdir_p("conflict-foobar/Gemfile")
bundle! "gem conflict-foobar"
expect(out).to include("file_clash conflict-foobar/Gemfile").
and include "Initializing git repo in #{bundled_app("conflict-foobar")}"
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index f43dd7e44e..34982c8ca8 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -79,6 +79,7 @@ RSpec.configure do |config|
end
config.before :suite do
+ require_relative "support/rubygems_ext"
Spec::Rubygems.setup
ENV["RUBYOPT"] = "#{ENV["RUBYOPT"]} -r#{Spec::Path.spec_dir}/support/hax.rb"
ENV["BUNDLE_SPEC_RUN"] = "true"