bundler 1.3.0.pre → 1.3.0.pre.2

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of bundler might be problematic. Click here for more details.

@@ -201,7 +201,7 @@ module Bundler
201
201
  # fetch from modern index: specs.4.8.gz
202
202
  def fetch_all_remote_specs
203
203
  @has_api = false
204
- Gem.sources = ["#{@remote_uri}"]
204
+ Bundler.rubygems.sources = ["#{@remote_uri}"]
205
205
 
206
206
  begin
207
207
  Bundler.rubygems.fetch_all_remote_specs
@@ -35,6 +35,11 @@ module Bundler
35
35
  end
36
36
 
37
37
  def sources=(val)
38
+ # Gem.configuration creates a new Gem::ConfigFile, which by default will read ~/.gemrc
39
+ # If that file exists, its settings (including sources) will overwrite the values we
40
+ # are about to set here. In order to avoid that, we force memoizing the config file now.
41
+ configuration
42
+
38
43
  Gem.sources = val
39
44
  end
40
45
 
@@ -68,6 +68,9 @@ module Bundler
68
68
  Kernel.require file
69
69
  end
70
70
  rescue LoadError => e
71
+ REGEXPS.find { |r| r =~ e.message }
72
+ raise if dep.autorequire || $1 != required_file
73
+
71
74
  if dep.autorequire.nil? && dep.name.include?('-')
72
75
  begin
73
76
  namespaced_file = dep.name.gsub('-', '/')
@@ -78,9 +81,6 @@ module Bundler
78
81
  raise if dep.autorequire || (regex_name && regex_name.gsub('-', '/') != namespaced_file)
79
82
  raise e if regex_name.nil?
80
83
  end
81
- else
82
- REGEXPS.find { |r| r =~ e.message }
83
- raise if dep.autorequire || $1 != required_file
84
84
  end
85
85
  end
86
86
  end
@@ -104,6 +104,12 @@ module Bundler
104
104
  next if spec.name == 'bundler'
105
105
  spec.source.cache(spec) if spec.source.respond_to?(:cache)
106
106
  end
107
+
108
+ Dir[cache_path.join("*/.git")].each do |git_dir|
109
+ FileUtils.rm_rf(git_dir)
110
+ FileUtils.touch(File.expand_path("../.bundlecache", git_dir))
111
+ end
112
+
107
113
  prune_cache unless Bundler.settings[:no_prune]
108
114
  end
109
115
 
@@ -246,7 +252,7 @@ module Bundler
246
252
  end
247
253
 
248
254
  if cached.any?
249
- Bundler.ui.info "Removing outdated .git/path repos from vendor/cache"
255
+ Bundler.ui.info "Removing outdated git and path gems from vendor/cache"
250
256
 
251
257
  cached.each do |path|
252
258
  path = File.dirname(path)
@@ -166,8 +166,11 @@ module Bundler
166
166
  FileUtils.rm_rf(app_cache_path)
167
167
  git_proxy.checkout if requires_checkout?
168
168
  git_proxy.copy_to(app_cache_path, @submodules)
169
- FileUtils.rm_rf(app_cache_path.join(".git"))
170
- FileUtils.touch(app_cache_path.join(".bundlecache"))
169
+ # Evaluate gemspecs and cache the result. Gemspecs
170
+ # in git might require git or other dependencies.
171
+ # The gemspecs we cache should already be evaluated.
172
+ spec_path = app_cache_path.join(File.basename(spec.loaded_from))
173
+ File.open(spec_path, 'wb') {|file| file.print spec.to_ruby }
171
174
  end
172
175
 
173
176
  def load_spec_files
@@ -264,4 +267,4 @@ module Bundler
264
267
  end
265
268
 
266
269
  end
267
- end
270
+ end
@@ -44,7 +44,9 @@ module Bundler
44
44
  else
45
45
  Bundler.ui.info "Fetching #{uri}"
46
46
  FileUtils.mkdir_p(path.dirname)
47
- git %|clone #{uri_escaped} "#{path}" --bare --no-hardlinks|
47
+ clone_command = %|clone #{uri_escaped} "#{path}" --bare --no-hardlinks|
48
+ clone_command = "#{clone_command} --quiet" if Bundler.ui.quiet?
49
+ git clone_command
48
50
  end
49
51
  end
50
52
 
@@ -139,4 +141,4 @@ module Bundler
139
141
 
140
142
  end
141
143
  end
142
- end
144
+ end
@@ -137,6 +137,8 @@ module Bundler
137
137
  end
138
138
  end
139
139
  end
140
+ elsif File.exists?(expanded_path)
141
+ raise PathError, "The path `#{expanded_path}` is not a directory."
140
142
  else
141
143
  raise PathError, "The path `#{expanded_path}` does not exist."
142
144
  end
@@ -1,3 +1,3 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require '<%= config[:name] %>'
3
+ require '<%= config[:namespaced_path] %>'
@@ -1,4 +1,4 @@
1
- require "<%=config[:name]%>/version"
1
+ require "<%=config[:namespaced_path]%>/version"
2
2
 
3
3
  <%- config[:constant_array].each_with_index do |c,i| -%>
4
4
  <%= ' '*i %>module <%= c %>
@@ -1,7 +1,7 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  lib = File.expand_path('../lib', __FILE__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require '<%=config[:name]%>/version'
4
+ require '<%=config[:namespaced_path]%>/version'
5
5
 
6
6
  Gem::Specification.new do |gem|
7
7
  gem.name = <%=config[:name].inspect%>
@@ -1,2 +1,2 @@
1
1
  $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
- require '<%= config[:name] %>'
2
+ require '<%= config[:namespaced_path] %>'
@@ -1,4 +1,4 @@
1
1
  $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
- require '<%= config[:name] %>'
2
+ require '<%= config[:namespaced_path] %>'
3
3
 
4
4
  require 'minitest/autorun'
@@ -57,6 +57,10 @@ module Bundler
57
57
  @quiet = true
58
58
  end
59
59
 
60
+ def quiet?
61
+ @quiet
62
+ end
63
+
60
64
  def debug?
61
65
  # needs to be false instead of nil to be newline param to other methods
62
66
  !!@debug && !@quiet
@@ -2,5 +2,5 @@ module Bundler
2
2
  # We're doing this because we might write tests that deal
3
3
  # with other versions of bundler and we are unsure how to
4
4
  # handle this better.
5
- VERSION = "1.3.0.pre" unless defined?(::Bundler::VERSION)
5
+ VERSION = "1.3.0.pre.2" unless defined?(::Bundler::VERSION)
6
6
  end
@@ -3,17 +3,47 @@ require 'bundler'
3
3
 
4
4
  describe Bundler do
5
5
  describe "#load_gemspec_uncached" do
6
- it "should catch Psych syntax errors" do
7
- gemspec = <<-GEMSPEC
8
- {:!00 ao=gu\g1= 7~f
9
- GEMSPEC
10
- File.open(tmp("test.gemspec"), 'wb') do |file|
11
- file.puts gemspec
6
+
7
+ before do
8
+ @gemspec = tmp("test.gemspec")
9
+ @gemspec.open('wb') do |f|
10
+ f.write strip_whitespace(<<-GEMSPEC)
11
+ ---
12
+ {:!00 ao=gu\g1= 7~f
13
+ GEMSPEC
12
14
  end
15
+ end
13
16
 
14
- expect(proc {
15
- Bundler.load_gemspec_uncached(tmp("test.gemspec"))
16
- }).to raise_error(Bundler::GemspecError)
17
+ describe "on Ruby 1.8", :ruby => "1.8" do
18
+ it "should catch YAML syntax errors" do
19
+ expect { Bundler.load_gemspec_uncached(@gemspec) }.
20
+ to raise_error(Bundler::GemspecError)
21
+ end
17
22
  end
23
+
24
+ context "on Ruby 1.9", :ruby => "1.9" do
25
+ context "with Syck as YAML::Engine" do
26
+ it "raises a GemspecError after YAML load throws ArgumentError" do
27
+ orig_yamler, YAML::ENGINE.yamler = YAML::ENGINE.yamler, 'syck'
28
+
29
+ expect { Bundler.load_gemspec_uncached(@gemspec) }.
30
+ to raise_error(Bundler::GemspecError)
31
+
32
+ YAML::ENGINE.yamler = orig_yamler
33
+ end
34
+ end
35
+
36
+ context "with Psych as YAML::Engine" do
37
+ it "raises a GemspecError after YAML load throws Psych::SyntaxError" do
38
+ orig_yamler, YAML::ENGINE.yamler = YAML::ENGINE.yamler, 'psych'
39
+
40
+ expect { Bundler.load_gemspec_uncached(@gemspec) }.
41
+ to raise_error(Bundler::GemspecError)
42
+
43
+ YAML::ENGINE.yamler = orig_yamler
44
+ end
45
+ end
46
+ end
47
+
18
48
  end
19
49
  end
@@ -7,19 +7,31 @@ describe Bundler::Dsl do
7
7
  end
8
8
 
9
9
  describe '#_normalize_options' do
10
- it "should convert :github to :git" do
10
+ it "converts :github to :git" do
11
11
  subject.gem("sparks", :github => "indirect/sparks")
12
12
  github_uri = "git://github.com/indirect/sparks.git"
13
13
  expect(subject.dependencies.first.source.uri).to eq(github_uri)
14
14
  end
15
15
 
16
- it "should convert 'rails' to 'rails/rails'" do
16
+ it "converts numeric :gist to :git" do
17
+ subject.gem("not-really-a-gem", :gist => 2859988)
18
+ github_uri = "git://gist.github.com/2859988.git"
19
+ expect(subject.dependencies.first.source.uri).to eq(github_uri)
20
+ end
21
+
22
+ it "converts :gist to :git" do
23
+ subject.gem("not-really-a-gem", :gist => "2859988")
24
+ github_uri = "git://gist.github.com/2859988.git"
25
+ expect(subject.dependencies.first.source.uri).to eq(github_uri)
26
+ end
27
+
28
+ it "converts 'rails' to 'rails/rails'" do
17
29
  subject.gem("rails", :github => "rails")
18
30
  github_uri = "git://github.com/rails/rails.git"
19
31
  expect(subject.dependencies.first.source.uri).to eq(github_uri)
20
32
  end
21
33
 
22
- it "should interpret slashless 'github:' value as account name" do
34
+ it "interprets slashless 'github:' value as account name" do
23
35
  subject.gem("bundler", :github => "carlhuda")
24
36
  github_uri = "git://github.com/carlhuda/bundler.git"
25
37
  expect(subject.dependencies.first.source.uri).to eq(github_uri)
@@ -28,7 +40,7 @@ describe Bundler::Dsl do
28
40
  end
29
41
 
30
42
  describe '#method_missing' do
31
- it 'should raise an error for unknown DSL methods' do
43
+ it 'raises an error for unknown DSL methods' do
32
44
  Bundler.should_receive(:read_file).with("Gemfile").and_return("unknown")
33
45
  error_msg = "Undefined local variable or method `unknown'" \
34
46
  " for Gemfile\\s+from Gemfile:1"
@@ -46,7 +58,7 @@ describe Bundler::Dsl do
46
58
  end
47
59
 
48
60
  describe "syntax errors" do
49
- it "should raise a Bundler::GemfileError" do
61
+ it "raise a Bundler::GemfileError" do
50
62
  gemfile "gem 'foo', :path => /unquoted/string/syntax/error"
51
63
  expect { Bundler::Dsl.evaluate(bundled_app("Gemfile"), nil, true) }.
52
64
  to raise_error(Bundler::GemfileError)
@@ -35,7 +35,7 @@ describe "Bundler::GemHelper tasks" do
35
35
 
36
36
  it "handles namespaces and converting to CamelCase" do
37
37
  bundle 'gem test-foo_bar'
38
- lib = bundled_app('test-foo_bar').join('lib/test-foo_bar.rb').read
38
+ lib = bundled_app('test-foo_bar').join('lib/test/foo_bar.rb').read
39
39
  expect(lib).to include("module Test")
40
40
  expect(lib).to include("module FooBar")
41
41
  end
@@ -165,5 +165,24 @@ end
165
165
 
166
166
  expect(out).not_to include("Your Gemfile contains path and git dependencies.")
167
167
  end
168
+
169
+ it "evaluates gemspecs and writes them out" do
170
+ git = build_git "foo"
171
+
172
+ # Insert a gemspec method that shells out
173
+ spec_lines = lib_path("foo-1.0/foo.gemspec").read.split("\n")
174
+ spec_lines.insert(-2, "s.description = `echo bob`")
175
+ update_git("foo"){ |s| s.write "foo.gemspec", spec_lines.join("\n") }
176
+
177
+ install_gemfile <<-G
178
+ gem "foo", :git => '#{lib_path("foo-1.0")}'
179
+ G
180
+ bundle "#{cmd} --all"
181
+
182
+ ref = git.ref_for("master", 11)
183
+ gemspec = bundled_app("vendor/cache/foo-1.0-#{ref}/foo.gemspec").read
184
+ expect(gemspec).to_not match("`echo bob`")
185
+ end
186
+
168
187
  end
169
188
  end
@@ -216,10 +216,10 @@ describe "gemcutter's dependency API" do
216
216
 
217
217
  bundle :install, :artifice => "endpoint_extra"
218
218
 
219
- output = <<OUTPUT
220
- Fetching gem metadata from http://localgemserver.test/..
221
- Fetching gem metadata from http://localgemserver.test/extra/.
222
- OUTPUT
219
+ output = <<-OUTPUT.gsub(/^ +/,'')
220
+ Fetching gem metadata from http://localgemserver.test/..
221
+ Fetching gem metadata from http://localgemserver.test/extra/.
222
+ OUTPUT
223
223
  expect(out).to include(output)
224
224
  end
225
225
 
@@ -433,4 +433,26 @@ OUTPUT
433
433
  end
434
434
  end
435
435
 
436
+ context ".gemrc with sources is present" do
437
+ before do
438
+ File.open(home('.gemrc'), 'w') do |file|
439
+ file.puts({:sources => ["http://rubygems.org"]}.to_yaml)
440
+ end
441
+ end
442
+
443
+ after do
444
+ home('.gemrc').rmtree
445
+ end
446
+
447
+ it "uses other sources declared in the Gemfile" do
448
+ gemfile <<-G
449
+ source "#{source_uri}"
450
+ gem 'rack'
451
+ G
452
+
453
+ bundle "install", :exitstatus => true, :artifice => "endpoint_marshal_fail"
454
+
455
+ expect(exitstatus).to eq(0)
456
+ end
457
+ end
436
458
  end
@@ -95,6 +95,12 @@ describe ".bundle/config" do
95
95
  run "puts Bundler.settings[:foo]"
96
96
  expect(out).to eq("global")
97
97
  end
98
+
99
+ it "expands the path at time of setting" do
100
+ bundle "config --global local.foo .."
101
+ run "puts Bundler.settings['local.foo']"
102
+ expect(out).to eq(File.expand_path(Dir.pwd + "/.."))
103
+ end
98
104
  end
99
105
 
100
106
  describe "local" do
@@ -134,5 +140,11 @@ describe ".bundle/config" do
134
140
  run "puts Bundler.settings[:foo]"
135
141
  expect(out).to eq("local")
136
142
  end
143
+
144
+ it "expands the path at time of setting" do
145
+ bundle "config --local local.foo .."
146
+ run "puts Bundler.settings['local.foo']"
147
+ expect(out).to eq(File.expand_path(Dir.pwd + "/.."))
148
+ end
137
149
  end
138
150
  end
@@ -1,168 +1,329 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe "bundle gem" do
4
- before :each do
4
+ before do
5
5
  @git_name = `git config --global user.name`.chomp
6
6
  `git config --global user.name "Bundler User"`
7
7
  @git_email = `git config --global user.email`.chomp
8
8
  `git config --global user.email user@example.com`
9
- bundle 'gem test-gem'
10
- # reset gemspec cache for each test because of commit 3d4163a
11
- Bundler.clear_gemspec_cache
12
9
  end
13
10
 
14
- after :each do
11
+ after do
15
12
  `git config --global user.name "#{@git_name}"`
16
13
  `git config --global user.email #{@git_email}`
17
14
  end
18
15
 
19
- let(:generated_gem) { Bundler::GemHelper.new(bundled_app("test-gem").to_s) }
16
+ shared_examples_for "git config is present" do
17
+ context "git config user.{name,email} present" do
18
+ it "sets gemspec author to git user.name if available" do
19
+ expect(generated_gem.gemspec.authors.first).to eq("Bundler User")
20
+ end
20
21
 
21
- it "generates a gem skeleton" do
22
- expect(bundled_app("test-gem/test-gem.gemspec")).to exist
23
- expect(bundled_app("test-gem/LICENSE.txt")).to exist
24
- expect(bundled_app("test-gem/Gemfile")).to exist
25
- expect(bundled_app("test-gem/Rakefile")).to exist
26
- expect(bundled_app("test-gem/lib/test-gem.rb")).to exist
27
- expect(bundled_app("test-gem/lib/test-gem/version.rb")).to exist
22
+ it "sets gemspec email to git user.email if available" do
23
+ expect(generated_gem.gemspec.email.first).to eq("user@example.com")
24
+ end
25
+ end
28
26
  end
29
27
 
30
- it "starts with version 0.0.1" do
31
- expect(bundled_app("test-gem/lib/test-gem/version.rb").read).to match(/VERSION = "0.0.1"/)
32
- end
28
+ shared_examples_for "git config is absent" do |hoge|
29
+ it "sets gemspec author to default message if git user.name is not set or empty" do
30
+ expect(generated_gem.gemspec.authors.first).to eq("TODO: Write your name")
31
+ end
33
32
 
34
- it "nests constants so they work" do
35
- expect(bundled_app("test-gem/lib/test-gem/version.rb").read).to match(/module Test\n module Gem/)
36
- expect(bundled_app("test-gem/lib/test-gem.rb").read).to match(/module Test\n module Gem/)
33
+ it "sets gemspec email to default message if git user.email is not set or empty" do
34
+ expect(generated_gem.gemspec.email.first).to eq("TODO: Write your email address")
35
+ end
37
36
  end
38
37
 
39
- context "git config user.{name,email} present" do
40
- it "sets gemspec author to git user.name if available" do
41
- expect(generated_gem.gemspec.authors.first).to eq("Bundler User")
38
+ context "gem naming with underscore" do
39
+ let(:gem_name) { 'test_gem' }
40
+
41
+ before do
42
+ bundle "gem #{gem_name}"
43
+ # reset gemspec cache for each test because of commit 3d4163a
44
+ Bundler.clear_gemspec_cache
42
45
  end
43
46
 
44
- it "sets gemspec email to git user.email if available" do
45
- expect(generated_gem.gemspec.email.first).to eq("user@example.com")
47
+ let(:generated_gem) { Bundler::GemHelper.new(bundled_app(gem_name).to_s) }
48
+
49
+ it "generates a gem skeleton" do
50
+ expect(bundled_app("test_gem/test_gem.gemspec")).to exist
51
+ expect(bundled_app("test_gem/LICENSE.txt")).to exist
52
+ expect(bundled_app("test_gem/Gemfile")).to exist
53
+ expect(bundled_app("test_gem/Rakefile")).to exist
54
+ expect(bundled_app("test_gem/lib/test_gem.rb")).to exist
55
+ expect(bundled_app("test_gem/lib/test_gem/version.rb")).to exist
46
56
  end
47
- end
48
57
 
49
- context "git config user.{name,email} is not set" do
50
- before :each do
51
- `git config --global --unset user.name`
52
- `git config --global --unset user.email`
53
- reset!
54
- in_app_root
55
- bundle 'gem test-gem'
58
+ it "starts with version 0.0.1" do
59
+ expect(bundled_app("test_gem/lib/test_gem/version.rb").read).to match(/VERSION = "0.0.1"/)
56
60
  end
57
61
 
58
- it "sets gemspec author to default message if git user.name is not set or empty" do
59
- expect(generated_gem.gemspec.authors.first).to eq("TODO: Write your name")
62
+ it "does not nest constants" do
63
+ expect(bundled_app("test_gem/lib/test_gem/version.rb").read).to match(/module TestGem/)
64
+ expect(bundled_app("test_gem/lib/test_gem.rb").read).to match(/module TestGem/)
60
65
  end
61
66
 
62
- it "sets gemspec email to default message if git user.email is not set or empty" do
63
- expect(generated_gem.gemspec.email.first).to eq("TODO: Write your email address")
67
+ it_should_behave_like "git config is present"
68
+
69
+ context "git config user.{name,email} is not set" do
70
+ before do
71
+ `git config --global --unset user.name`
72
+ `git config --global --unset user.email`
73
+ reset!
74
+ in_app_root
75
+ bundle "gem #{gem_name}"
76
+ end
77
+
78
+ it_should_behave_like "git config is absent"
64
79
  end
65
- end
66
80
 
67
- it "sets gemspec license to MIT by default" do
68
- expect(generated_gem.gemspec.license).to eq("MIT")
69
- end
81
+ it "sets gemspec license to MIT by default" do
82
+ expect(generated_gem.gemspec.license).to eq("MIT")
83
+ end
70
84
 
71
- it "requires the version file" do
72
- expect(bundled_app("test-gem/lib/test-gem.rb").read).to match(/require "test-gem\/version"/)
73
- end
85
+ it "requires the version file" do
86
+ expect(bundled_app("test_gem/lib/test_gem.rb").read).to match(/require "test_gem\/version"/)
87
+ end
74
88
 
75
- it "runs rake without problems" do
76
- system_gems ["rake-10.0.2"]
89
+ it "runs rake without problems" do
90
+ system_gems ["rake-10.0.2"]
77
91
 
78
- rakefile = <<-RAKEFILE
79
- task :default do
80
- puts 'SUCCESS'
81
- end
92
+ rakefile = <<-RAKEFILE
93
+ task :default do
94
+ puts 'SUCCESS'
95
+ end
82
96
  RAKEFILE
83
- File.open(bundled_app("test-gem/Rakefile"), 'w') do |file|
84
- file.puts rakefile
97
+ File.open(bundled_app("test_gem/Rakefile"), 'w') do |file|
98
+ file.puts rakefile
99
+ end
100
+
101
+ Dir.chdir(bundled_app(gem_name)) do
102
+ sys_exec("rake")
103
+ expect(out).to include("SUCCESS")
104
+ end
85
105
  end
86
106
 
87
- Dir.chdir(bundled_app("test-gem")) do
88
- sys_exec("rake")
89
- expect(out).to include("SUCCESS")
107
+ context "--bin parameter set" do
108
+ before do
109
+ reset!
110
+ in_app_root
111
+ bundle "gem #{gem_name} --bin"
112
+ end
113
+
114
+ it "builds bin skeleton" do
115
+ expect(bundled_app("test_gem/bin/test_gem")).to exist
116
+ end
117
+
118
+ it "requires 'test-gem'" do
119
+ expect(bundled_app("test_gem/bin/test_gem").read).to match(/require 'test_gem'/)
120
+ end
90
121
  end
91
- end
92
122
 
93
- context "--bin parameter set" do
94
- before :each do
95
- reset!
96
- in_app_root
97
- bundle 'gem test-gem --bin'
123
+ context "--test parameter set to rspec" do
124
+ before do
125
+ reset!
126
+ in_app_root
127
+ bundle "gem #{gem_name} --test=rspec"
128
+ end
129
+
130
+ it "builds spec skeleton" do
131
+ expect(bundled_app("test_gem/.rspec")).to exist
132
+ expect(bundled_app("test_gem/spec/test_gem_spec.rb")).to exist
133
+ expect(bundled_app("test_gem/spec/spec_helper.rb")).to exist
134
+ end
135
+
136
+ it "requires 'test-gem'" do
137
+ expect(bundled_app("test_gem/spec/spec_helper.rb").read).to match(/require 'test_gem'/)
138
+ end
139
+
140
+ it "creates a default test which fails" do
141
+ expect(bundled_app("test_gem/spec/test_gem_spec.rb").read).to match(/false.should be_true/)
142
+ end
98
143
  end
99
144
 
100
- it "builds bin skeleton" do
101
- expect(bundled_app("test-gem/bin/test-gem")).to exist
145
+ context "--test parameter set to minitest" do
146
+ before do
147
+ reset!
148
+ in_app_root
149
+ bundle "gem #{gem_name} --test=minitest"
150
+ end
151
+
152
+ it "builds spec skeleton" do
153
+ expect(bundled_app("test_gem/test/test_test_gem.rb")).to exist
154
+ expect(bundled_app("test_gem/test/minitest_helper.rb")).to exist
155
+ end
156
+
157
+ it "requires 'test-gem'" do
158
+ expect(bundled_app("test_gem/test/minitest_helper.rb").read).to match(/require 'test_gem'/)
159
+ end
160
+
161
+ it "requires 'minitest_helper'" do
162
+ expect(bundled_app("test_gem/test/test_test_gem.rb").read).to match(/require '.\/minitest_helper'/)
163
+ end
164
+
165
+ it "creates a default test which fails" do
166
+ expect(bundled_app("test_gem/test/test_test_gem.rb").read).to match(/assert false/)
167
+ end
102
168
  end
103
169
 
104
- it "requires 'test-gem'" do
105
- expect(bundled_app("test-gem/bin/test-gem").read).to match(/require 'test-gem'/)
170
+ context "--test with no arguments" do
171
+ before do
172
+ reset!
173
+ in_app_root
174
+ bundle "gem #{gem_name} --test"
175
+ end
176
+
177
+ it "defaults to rspec" do
178
+ expect(bundled_app("test_gem/spec/spec_helper.rb")).to exist
179
+ expect(bundled_app("test_gem/test/minitest_helper.rb")).to_not exist
180
+ end
106
181
  end
107
182
  end
108
183
 
109
- context "--test parameter set to rspec" do
110
- before :each do
111
- reset!
112
- in_app_root
113
- bundle "gem test-gem --test=rspec"
184
+ context "gem naming with dashed" do
185
+ let(:gem_name) { 'test-gem' }
186
+
187
+ before do
188
+ bundle "gem #{gem_name}"
189
+ # reset gemspec cache for each test because of commit 3d4163a
190
+ Bundler.clear_gemspec_cache
114
191
  end
115
192
 
116
- it "builds spec skeleton" do
117
- expect(bundled_app("test-gem/.rspec")).to exist
118
- expect(bundled_app("test-gem/spec/test-gem_spec.rb")).to exist
119
- expect(bundled_app("test-gem/spec/spec_helper.rb")).to exist
193
+ let(:generated_gem) { Bundler::GemHelper.new(bundled_app(gem_name).to_s) }
194
+
195
+ it "generates a gem skeleton" do
196
+ expect(bundled_app("test-gem/test-gem.gemspec")).to exist
197
+ expect(bundled_app("test-gem/LICENSE.txt")).to exist
198
+ expect(bundled_app("test-gem/Gemfile")).to exist
199
+ expect(bundled_app("test-gem/Rakefile")).to exist
200
+ expect(bundled_app("test-gem/lib/test/gem.rb")).to exist
201
+ expect(bundled_app("test-gem/lib/test/gem/version.rb")).to exist
120
202
  end
121
203
 
122
- it "requires 'test-gem'" do
123
- expect(bundled_app("test-gem/spec/spec_helper.rb").read).to match(/require 'test-gem'/)
204
+ it "starts with version 0.0.1" do
205
+ expect(bundled_app("test-gem/lib/test/gem/version.rb").read).to match(/VERSION = "0.0.1"/)
124
206
  end
125
207
 
126
- it "creates a default test which fails" do
127
- expect(bundled_app("test-gem/spec/test-gem_spec.rb").read).to match(/false.should be_true/)
208
+ it "nests constants so they work" do
209
+ expect(bundled_app("test-gem/lib/test/gem/version.rb").read).to match(/module Test\n module Gem/)
210
+ expect(bundled_app("test-gem/lib/test/gem.rb").read).to match(/module Test\n module Gem/)
128
211
  end
129
- end
130
212
 
131
- context "--test parameter set to minitest" do
132
- before :each do
133
- reset!
134
- in_app_root
135
- bundle "gem test-gem --test=minitest"
213
+ it_should_behave_like "git config is present"
214
+
215
+ context "git config user.{name,email} is not set" do
216
+ before do
217
+ `git config --global --unset user.name`
218
+ `git config --global --unset user.email`
219
+ reset!
220
+ in_app_root
221
+ bundle "gem #{gem_name}"
222
+ end
223
+
224
+ it_should_behave_like "git config is absent"
136
225
  end
137
226
 
138
- it "builds spec skeleton" do
139
- expect(bundled_app("test-gem/test/test_test-gem.rb")).to exist
140
- expect(bundled_app("test-gem/test/minitest_helper.rb")).to exist
227
+ it "sets gemspec license to MIT by default" do
228
+ expect(generated_gem.gemspec.license).to eq("MIT")
141
229
  end
142
230
 
143
- it "requires 'test-gem'" do
144
- expect(bundled_app("test-gem/test/minitest_helper.rb").read).to match(/require 'test-gem'/)
231
+ it "requires the version file" do
232
+ expect(bundled_app("test-gem/lib/test/gem.rb").read).to match(/require "test\/gem\/version"/)
145
233
  end
146
234
 
147
- it "requires 'minitest_helper'" do
148
- expect(bundled_app("test-gem/test/test_test-gem.rb").read).to match(/require '.\/minitest_helper'/)
235
+ it "runs rake without problems" do
236
+ system_gems ["rake-10.0.2"]
237
+
238
+ rakefile = <<-RAKEFILE
239
+ task :default do
240
+ puts 'SUCCESS'
241
+ end
242
+ RAKEFILE
243
+ File.open(bundled_app("test-gem/Rakefile"), 'w') do |file|
244
+ file.puts rakefile
245
+ end
246
+
247
+ Dir.chdir(bundled_app(gem_name)) do
248
+ sys_exec("rake")
249
+ expect(out).to include("SUCCESS")
250
+ end
251
+ end
252
+
253
+ context "--bin parameter set" do
254
+ before do
255
+ reset!
256
+ in_app_root
257
+ bundle "gem #{gem_name} --bin"
258
+ end
259
+
260
+ it "builds bin skeleton" do
261
+ expect(bundled_app("test-gem/bin/test-gem")).to exist
262
+ end
263
+
264
+ it "requires 'test/gem'" do
265
+ expect(bundled_app("test-gem/bin/test-gem").read).to match(/require 'test\/gem'/)
266
+ end
149
267
  end
150
268
 
151
- it "creates a default test which fails" do
152
- expect(bundled_app("test-gem/test/test_test-gem.rb").read).to match(/assert false/)
269
+ context "--test parameter set to rspec" do
270
+ before do
271
+ reset!
272
+ in_app_root
273
+ bundle "gem #{gem_name} --test=rspec"
274
+ end
275
+
276
+ it "builds spec skeleton" do
277
+ expect(bundled_app("test-gem/.rspec")).to exist
278
+ expect(bundled_app("test-gem/spec/test/gem_spec.rb")).to exist
279
+ expect(bundled_app("test-gem/spec/spec_helper.rb")).to exist
280
+ end
281
+
282
+ it "requires 'test/gem'" do
283
+ expect(bundled_app("test-gem/spec/spec_helper.rb").read).to match(/require 'test\/gem'/)
284
+ end
285
+
286
+ it "creates a default test which fails" do
287
+ expect(bundled_app("test-gem/spec/test/gem_spec.rb").read).to match(/false.should be_true/)
288
+ end
153
289
  end
154
- end
155
290
 
156
- context "--test with no arguments" do
157
- before :each do
158
- reset!
159
- in_app_root
160
- bundle "gem test-gem --test"
291
+ context "--test parameter set to minitest" do
292
+ before do
293
+ reset!
294
+ in_app_root
295
+ bundle "gem #{gem_name} --test=minitest"
296
+ end
297
+
298
+ it "builds spec skeleton" do
299
+ expect(bundled_app("test-gem/test/test_test/gem.rb")).to exist
300
+ expect(bundled_app("test-gem/test/minitest_helper.rb")).to exist
301
+ end
302
+
303
+ it "requires 'test/gem'" do
304
+ expect(bundled_app("test-gem/test/minitest_helper.rb").read).to match(/require 'test\/gem'/)
305
+ end
306
+
307
+ it "requires 'minitest_helper'" do
308
+ expect(bundled_app("test-gem/test/test_test/gem.rb").read).to match(/require '.\/minitest_helper'/)
309
+ end
310
+
311
+ it "creates a default test which fails" do
312
+ expect(bundled_app("test-gem/test/test_test/gem.rb").read).to match(/assert false/)
313
+ end
161
314
  end
162
315
 
163
- it "defaults to rspec" do
164
- expect(bundled_app("test-gem/spec/spec_helper.rb")).to exist
165
- expect(bundled_app("test-gem/test/minitest_helper.rb")).to_not exist
316
+ context "--test with no arguments" do
317
+ before do
318
+ reset!
319
+ in_app_root
320
+ bundle "gem #{gem_name} --test"
321
+ end
322
+
323
+ it "defaults to rspec" do
324
+ expect(bundled_app("test-gem/spec/spec_helper.rb")).to exist
325
+ expect(bundled_app("test-gem/test/minitest_helper.rb")).to_not exist
326
+ end
166
327
  end
167
328
  end
168
329
  end