From f4307761cf8b25f5ab300331bb7ab03025c4db86 Mon Sep 17 00:00:00 2001 From: Andre Arko Date: Sat, 17 Sep 2011 17:42:03 -0700 Subject: move gem_helper_spec to conventional location --- bundler.gemspec | 3 +- spec/bundler/gem_helper_spec.rb | 136 ++++++++++++++++++++++++++++++++++++++++ spec/other/gem_helper_spec.rb | 136 ---------------------------------------- 3 files changed, 138 insertions(+), 137 deletions(-) create mode 100644 spec/bundler/gem_helper_spec.rb delete mode 100644 spec/other/gem_helper_spec.rb diff --git a/bundler.gemspec b/bundler.gemspec index cb7f795c29..86eab2cdfc 100644 --- a/bundler.gemspec +++ b/bundler.gemspec @@ -22,7 +22,8 @@ Gem::Specification.new do |s| # Man files are required because they are ignored by git man_files = Dir.glob("lib/bundler/man/**/*") - s.files = `git ls-files`.split("\n") + man_files + git_files = `git ls-files`.split("\n") rescue '' + s.files = git_files + man_files s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") s.executables = %w(bundle) s.require_paths = ["lib"] diff --git a/spec/bundler/gem_helper_spec.rb b/spec/bundler/gem_helper_spec.rb new file mode 100644 index 0000000000..bb21b60ced --- /dev/null +++ b/spec/bundler/gem_helper_spec.rb @@ -0,0 +1,136 @@ +require "spec_helper" +require 'bundler/gem_helper' + +describe "Bundler::GemHelper tasks" do + context "determining gemspec" do + it "interpolates the name when there is only one gemspec" do + bundle 'gem test' + app = bundled_app("test") + helper = Bundler::GemHelper.new(app.to_s) + helper.gemspec.name.should == 'test' + end + + it "interpolates the name for a hidden gemspec" do + bundle 'gem test' + app = bundled_app("test") + FileUtils.mv app.join('test.gemspec'), app.join('.gemspec') + helper = Bundler::GemHelper.new(app.to_s) + helper.gemspec.name.should == 'test' + end + + it "should fail when there is no gemspec" do + bundle 'gem test' + app = bundled_app("test") + FileUtils.rm(File.join(app.to_s, 'test.gemspec')) + proc { Bundler::GemHelper.new(app.to_s) }.should raise_error(/Unable to determine name/) + end + + it "should fail when there are two gemspecs and the name isn't specified" do + bundle 'gem test' + app = bundled_app("test") + File.open(File.join(app.to_s, 'test2.gemspec'), 'w') {|f| f << ''} + proc { Bundler::GemHelper.new(app.to_s) }.should raise_error(/Unable to determine name/) + end + end + + context "gem management" do + def mock_confirm_message(message) + Bundler.ui.should_receive(:confirm).with(message) + end + + def mock_build_message + mock_confirm_message "test 0.0.1 built to pkg/test-0.0.1.gem" + end + + before(:each) do + bundle 'gem test' + @app = bundled_app("test") + @gemspec = File.read("#{@app.to_s}/test.gemspec") + File.open("#{@app.to_s}/test.gemspec", 'w'){|f| f << @gemspec.gsub('TODO: ', '') } + @helper = Bundler::GemHelper.new(@app.to_s) + end + + it "uses a shell UI for output" do + Bundler.ui.should be_a(Bundler::UI::Shell) + end + + describe 'build' do + it "builds" do + mock_build_message + @helper.build_gem + bundled_app('test/pkg/test-0.0.1.gem').should exist + end + + it "raises an appropriate error when the build fails" do + # break the gemspec by adding back the TODOs... + File.open("#{@app.to_s}/test.gemspec", 'w'){|f| f << @gemspec } + proc { @helper.build_gem }.should raise_error(/TODO/) + end + end + + describe 'install' do + it "installs" do + mock_build_message + mock_confirm_message "test (0.0.1) installed" + @helper.install_gem + bundled_app('test/pkg/test-0.0.1.gem').should exist + %x{gem list}.should include("test (0.0.1)") + end + + it "raises an appropriate error when the install fails" do + @helper.should_receive(:build_gem) do + # write an invalid gem file, so we can simulate install failure... + FileUtils.mkdir_p(File.join(@app.to_s, 'pkg')) + path = "#{@app.to_s}/pkg/test-0.0.1.gem" + File.open(path, 'w'){|f| f << "not actually a gem"} + path + end + proc { @helper.install_gem }.should raise_error + end + end + + describe 'release' do + it "shouldn't push if there are uncommitted files" do + proc { @helper.release_gem }.should raise_error(/files that need to be committed/) + end + + it 'raises an appropriate error if there is no git remote' do + Bundler.ui.stub(:confirm => nil, :error => nil) # silence messages + + Dir.chdir(gem_repo1) { + `git init --bare` + } + Dir.chdir(@app) { + `git init` + `git config user.email "you@example.com"` + `git config user.name "name"` + `git commit -a -m "initial commit"` + } + + proc { @helper.release_gem }.should raise_error + end + + it "releases" do + mock_build_message + mock_confirm_message(/Tagged v0.0.1/) + mock_confirm_message("Pushed git commits and tags") + + @helper.should_receive(:rubygem_push).with(bundled_app('test/pkg/test-0.0.1.gem').to_s) + + Dir.chdir(gem_repo1) { + `git init --bare` + } + Dir.chdir(@app) { + `git init` + `git config user.email "you@example.com"` + `git config user.name "name"` + `git remote add origin file://#{gem_repo1}` + `git commit -a -m "initial commit"` + sys_exec("git push origin master", true) + `git commit -a -m "another commit"` + } + @helper.release_gem + end + end + end +end diff --git a/spec/other/gem_helper_spec.rb b/spec/other/gem_helper_spec.rb deleted file mode 100644 index bb21b60ced..0000000000 --- a/spec/other/gem_helper_spec.rb +++ /dev/null @@ -1,136 +0,0 @@ -require "spec_helper" -require 'bundler/gem_helper' - -describe "Bundler::GemHelper tasks" do - context "determining gemspec" do - it "interpolates the name when there is only one gemspec" do - bundle 'gem test' - app = bundled_app("test") - helper = Bundler::GemHelper.new(app.to_s) - helper.gemspec.name.should == 'test' - end - - it "interpolates the name for a hidden gemspec" do - bundle 'gem test' - app = bundled_app("test") - FileUtils.mv app.join('test.gemspec'), app.join('.gemspec') - helper = Bundler::GemHelper.new(app.to_s) - helper.gemspec.name.should == 'test' - end - - it "should fail when there is no gemspec" do - bundle 'gem test' - app = bundled_app("test") - FileUtils.rm(File.join(app.to_s, 'test.gemspec')) - proc { Bundler::GemHelper.new(app.to_s) }.should raise_error(/Unable to determine name/) - end - - it "should fail when there are two gemspecs and the name isn't specified" do - bundle 'gem test' - app = bundled_app("test") - File.open(File.join(app.to_s, 'test2.gemspec'), 'w') {|f| f << ''} - proc { Bundler::GemHelper.new(app.to_s) }.should raise_error(/Unable to determine name/) - end - end - - context "gem management" do - def mock_confirm_message(message) - Bundler.ui.should_receive(:confirm).with(message) - end - - def mock_build_message - mock_confirm_message "test 0.0.1 built to pkg/test-0.0.1.gem" - end - - before(:each) do - bundle 'gem test' - @app = bundled_app("test") - @gemspec = File.read("#{@app.to_s}/test.gemspec") - File.open("#{@app.to_s}/test.gemspec", 'w'){|f| f << @gemspec.gsub('TODO: ', '') } - @helper = Bundler::GemHelper.new(@app.to_s) - end - - it "uses a shell UI for output" do - Bundler.ui.should be_a(Bundler::UI::Shell) - end - - describe 'build' do - it "builds" do - mock_build_message - @helper.build_gem - bundled_app('test/pkg/test-0.0.1.gem').should exist - end - - it "raises an appropriate error when the build fails" do - # break the gemspec by adding back the TODOs... - File.open("#{@app.to_s}/test.gemspec", 'w'){|f| f << @gemspec } - proc { @helper.build_gem }.should raise_error(/TODO/) - end - end - - describe 'install' do - it "installs" do - mock_build_message - mock_confirm_message "test (0.0.1) installed" - @helper.install_gem - bundled_app('test/pkg/test-0.0.1.gem').should exist - %x{gem list}.should include("test (0.0.1)") - end - - it "raises an appropriate error when the install fails" do - @helper.should_receive(:build_gem) do - # write an invalid gem file, so we can simulate install failure... - FileUtils.mkdir_p(File.join(@app.to_s, 'pkg')) - path = "#{@app.to_s}/pkg/test-0.0.1.gem" - File.open(path, 'w'){|f| f << "not actually a gem"} - path - end - proc { @helper.install_gem }.should raise_error - end - end - - describe 'release' do - it "shouldn't push if there are uncommitted files" do - proc { @helper.release_gem }.should raise_error(/files that need to be committed/) - end - - it 'raises an appropriate error if there is no git remote' do - Bundler.ui.stub(:confirm => nil, :error => nil) # silence messages - - Dir.chdir(gem_repo1) { - `git init --bare` - } - Dir.chdir(@app) { - `git init` - `git config user.email "you@example.com"` - `git config user.name "name"` - `git commit -a -m "initial commit"` - } - - proc { @helper.release_gem }.should raise_error - end - - it "releases" do - mock_build_message - mock_confirm_message(/Tagged v0.0.1/) - mock_confirm_message("Pushed git commits and tags") - - @helper.should_receive(:rubygem_push).with(bundled_app('test/pkg/test-0.0.1.gem').to_s) - - Dir.chdir(gem_repo1) { - `git init --bare` - } - Dir.chdir(@app) { - `git init` - `git config user.email "you@example.com"` - `git config user.name "name"` - `git remote add origin file://#{gem_repo1}` - `git commit -a -m "initial commit"` - sys_exec("git push origin master", true) - `git commit -a -m "another commit"` - } - @helper.release_gem - end - end - end -end -- cgit v1.2.1