Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Remove spec fixtures

  • Loading branch information...
commit 708d0c2e05d397730efbb0cbd4439c86c0b44379 1 parent 079767c
Carl Lerche authored Carlhuda committed
View
6 Rakefile
@@ -47,6 +47,12 @@ else
end
end
+desc "mount a ramdisk at ./tmp for faster specs"
+task :ramdisk do
+ sh 'diskutil erasevolume HFS+ "tmpbundler" `hdiutil attach -nomount ram://116543`'
+ File.symlink "/Volumes/tmpbundler", File.expand_path('../tmp', __FILE__)
+end
+
desc "install the gem locally"
task :install => [:package] do
sh %{gem install pkg/#{spec.name}-#{spec.version}}
View
190 spec/bundler/cli_spec.rb
@@ -1,12 +1,13 @@
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
describe "Bundler::CLI" do
+
describe "it compiles gems that take options" do
before(:each) do
build_manifest <<-Gemfile
clear_sources
source "file://#{gem_repo1}"
- gem "very-simple-binary"
+ gem "very_simple_binary"
Gemfile
end
@@ -19,9 +20,9 @@
end
it "passes if a yaml is specified that contains the necessary options" do
- File.open(bundled_app.join("build.yml"), "w+") do |file|
+ File.open("#{bundled_app}/build.yml", "w+") do |file|
file.puts <<-build_options.gsub(/^ /, '')
- very-simple-binary:
+ very_simple_binary:
simple: wot
build_options
end
@@ -32,26 +33,22 @@
@output.should_not =~ /Failed to build gem native extension/
- ruby_code = <<-RUBY.split("\n").join("; ")
- require %{very_simple_binary}
- include VerySimpleBinaryForTests
- puts working
+ out = run_in_context <<-RUBY
+ require 'very_simple_binary'
+ puts VerySimpleBinaryInC
RUBY
- @output = run_in_context "exec %{#{Gem.ruby} -e '#{ruby_code}'}"
-
- @output.should == "true"
+ out.should == "VerySimpleBinaryInC"
end
end
describe "it working" do
- before(:each) do
+ before :each do
build_manifest <<-Gemfile
clear_sources
source "file://#{gem_repo1}"
gem "rake"
- gem "extlib"
- gem "very-simple"
+ gem "activesupport"
gem "rack", :only => :web
Gemfile
@@ -61,38 +58,32 @@
end
it "caches and installs rake" do
- gems = %w(rake-0.8.7 extlib-0.9.12 rack-0.9.1 very-simple-1.0)
+ gems = %w(rake-0.8.7 activesupport-2.3.2 rack-1.0.0)
bundled_app("vendor", "gems").should have_cached_gems(*gems)
bundled_app("vendor", "gems").should have_installed_gems(*gems)
end
it "creates a default environment file with the appropriate load paths" do
- bundled_app('vendor', 'gems', 'environment.rb').should have_load_paths(bundled_app("vendor", "gems"),
- "extlib-0.9.12" => %w(lib),
- "rake-0.8.7" => %w(bin lib),
- "very-simple-1.0" => %w(bin lib),
- "rack-0.9.1" => %w(bin lib)
- )
- end
+ out = run_in_context <<-RUBY
+ require "rake"
+ require "activesupport"
+ require "rack"
+ puts "\#{RAKE} - \#{ACTIVESUPPORT} - \#{RACK}"
+ RUBY
- it "creates an executable for rake in ./bin" do
- out = run_in_context "puts $:"
- out.should include(bundled_app("vendor", "gems", "gems", "rake-0.8.7", "lib").to_s)
- out.should include(bundled_app("vendor", "gems", "gems", "rake-0.8.7", "bin").to_s)
- out.should include(bundled_app("vendor", "gems", "gems", "extlib-0.9.12", "lib").to_s)
- out.should include(bundled_app("vendor", "gems", "gems", "very-simple-1.0", "lib").to_s)
- out.should include(bundled_app("vendor", "gems", "gems", "rack-0.9.1").to_s)
+ out.should == "0.8.7 - 2.3.2 - 1.0.0"
end
- it "creates valid executables" do
- out = `#{bundled_app("bin", "rake")} -e 'require "extlib" ; puts Extlib'`.strip
- out.should == "Extlib"
+ it "creates valid executables in ./bin" do
+ app_root do
+ `bin/rake`.should == "0.8.7\n"
+ end
end
it "runs exec correctly" do
- Dir.chdir(bundled_app) do
- out = gem_command :exec, %[ruby -e 'require "extlib" ; puts Extlib']
- out.should == "Extlib"
+ app_root do
+ out = gem_command :exec, %[ruby -e 'require "rake" ; puts RAKE']
+ out.should == "0.8.7"
end
end
@@ -104,28 +95,26 @@
end
it "maintains the correct environment when shelling out" do
- out = run_in_context "exec %{#{Gem.ruby} -e 'require %{very-simple} ; puts VerySimpleForTests'}"
- out.should == "VerySimpleForTests"
+ out = run_in_context "exec %{#{Gem.ruby} -e 'require %{rake} ; puts RAKE'}"
+ out.should == "0.8.7"
end
it "logs the correct information messages" do
[ "Updating source: file:#{gem_repo1}",
"Calculating dependencies...",
"Downloading rake-0.8.7.gem",
- "Downloading extlib-0.9.12.gem",
- "Downloading rack-0.9.1.gem",
- "Downloading very-simple-1.0.gem",
+ "Downloading activesupport-2.3.2.gem",
+ "Downloading rack-1.0.0.gem",
"Installing rake (0.8.7)",
- "Installing extlib (0.9.12)",
- "Installing rack (0.9.1)",
- "Installing very-simple (1.0)",
+ "Installing activesupport (2.3.2)",
+ "Installing rack (1.0.0)",
"Done." ].each do |message|
@output.should =~ /^#{Regexp.escape(message)}$/
end
end
it "already has gems in the loaded_specs" do
- out = run_in_context "puts Gem.loaded_specs.key?('extlib')"
+ out = run_in_context "puts Gem.loaded_specs.key?('activesupport')"
out.should == "true"
end
@@ -136,13 +125,13 @@
# TODO: Remove this when rubygems is fixed
it "adds the gem to Gem.source_index" do
- out = run_in_context "puts Gem.source_index.find_name('very-simple').first.version"
- out.should == "1.0"
+ out = run_in_context "puts Gem.source_index.find_name('activesupport').first.version"
+ out.should == "2.3.2"
end
end
describe "error cases" do
- before(:each) do
+ before :each do
bundled_app.mkdir_p
Dir.chdir(bundled_app)
end
@@ -167,11 +156,11 @@
build_manifest <<-Gemfile
clear_sources
source "file://#{gem_repo1}"
- gem "treetop"
+ gem "missing_dep"
Gemfile
out = gem_command :bundle
- out.should include("Could not find gem 'polyglot (>= 0.2.5, runtime)' (required by 'treetop (>= 0, runtime)') in any of the sources")
+ out.should include("Could not find gem 'not_here (>= 0, runtime)' (required by 'missing_dep (>= 0, runtime)') in any of the sources")
end
end
@@ -233,7 +222,6 @@
clear_sources
source "file://#{gem_repo1}"
gem "rake"
- gem "extlib"
gem "rack", :only => :web
disable_rubygems
@@ -270,16 +258,15 @@
install_manifest <<-Gemfile
clear_sources
source "file://#{gem_repo1}"
- source "file://#{gem_repo2}"
gem "rack"
Gemfile
FileUtils.mv bundled_app, tmp_path("bundled_app2")
Dir.chdir(tmp_path('bundled_app2')) do
- out = gem_command :exec, "ruby -e 'Bundler.require_env :default ; puts Rack'"
- out.should == "Rack"
- `bin/rackup --version`.strip.should == "Rack 1.0"
+ out = gem_command :exec, "ruby -e 'Bundler.require_env :default ; puts RACK'"
+ out.should == "1.0.0"
+ `bin/rackup`.strip.should == "1.0.0"
end
end
end
@@ -289,7 +276,6 @@
m = build_manifest <<-Gemfile
clear_sources
source "file://#{gem_repo1}"
- source "file://#{gem_repo2}"
gem "rack", "0.9.1"
Gemfile
m.install
@@ -297,7 +283,6 @@
build_manifest <<-Gemfile
clear_sources
source "file://#{gem_repo1}"
- source "file://#{gem_repo2}"
gem "rack"
Gemfile
@@ -325,7 +310,7 @@
it "only uses the localy cached gems when bundling with --cache" do
build_manifest <<-Gemfile
clear_sources
- source "file://#{gem_repo2}"
+ source "file://#{gem_repo1}"
gem "rack"
Gemfile
@@ -341,7 +326,7 @@
build_manifest <<-Gemfile
clear_sources
- source "file://#{gem_repo2}"
+ source "file://#{gem_repo1}"
gem "rack"
Gemfile
@@ -359,49 +344,25 @@
build_manifest <<-Gemfile
clear_sources
source "file://#{gem_repo1}"
- gem "extlib"
- gem "very-simple", :only => :server
+ gem "activesupport"
+ gem "rake", :only => :server
gem "rack", :only => :test
Gemfile
-
- %w(doc environment.rb gems specifications).each do |f|
- FileUtils.rm_rf(tmp_gem_path.join(f))
- end
end
it "install gems for environments specified in --only line" do
- Dir.chdir(bundled_app) do
- gem_command :bundle, "--only test"
- bundled_app('vendor', 'gems', 'environment.rb').should have_load_paths(bundled_app("vendor", "gems"),
- "extlib-0.9.12" => %w(lib),
- "rack-0.9.1" => %w(bin lib)
- )
- end
- end
- end
-
- describe "bundling all but certain environments" do
- before(:each) do
- build_manifest <<-Gemfile
- clear_sources
- source "file://#{gem_repo1}"
- gem "extlib"
- gem "very-simple", :except => :test
- gem "rack", :except => :server
- Gemfile
-
- %w(doc environment.rb gems specifications).each do |f|
- FileUtils.rm_rf(tmp_gem_path.join(f))
- end
- end
-
- it "install gems for environments specified in --only line" do
- Dir.chdir(bundled_app) do
- gem_command :bundle, "--only test"
- bundled_app('vendor', 'gems', 'environment.rb').should have_load_paths(bundled_app("vendor", "gems"),
- "extlib-0.9.12" => %w(lib),
- "rack-0.9.1" => %w(bin lib)
- )
+ system_gems do
+ app_root do
+ gem_command :bundle, "--only test"
+ out = run_in_context "require 'activesupport' ; require 'rack' ; puts ACTIVESUPPORT"
+ out.should == "2.3.2"
+
+ out = run_in_context <<-RUBY
+ begin ;require 'rake'
+ rescue LoadError ; puts 'awesome' ; end
+ RUBY
+ out.should == 'awesome'
+ end
end
end
end
@@ -420,7 +381,7 @@
Gemfile
Dir.chdir(bundled_app) do
- out = gem_command :bundle, "--cache #{gem_repo1('gems', 'rack-0.9.1.gem')}"
+ out = gem_command :bundle, "--cache #{gem_repo1}/gems/rack-0.9.1.gem"
gem_command :bundle, "--cached"
out.should include("Caching: rack-0.9.1.gem")
tmp_gem_path.should include_cached_gems("rack-0.9.1")
@@ -432,33 +393,35 @@
build_manifest <<-Gemfile
clear_sources
gem "rack"
- gem "abstract"
+ gem "activesupport"
Gemfile
Dir.chdir(bundled_app) do
- out = gem_command :bundle, "--cache #{gem_repo1('gems')}"
+ out = gem_command :bundle, "--cache #{gem_repo1}/gems"
gem_command :bundle, "--cached"
- %w(abstract-1.0.0 actionmailer-2.3.2 activerecord-2.3.2 addressable-2.0.2 builder-2.1.2).each do |gemfile|
+ %w(actionmailer-2.3.2 activerecord-2.3.2 rake-0.8.7 rack-0.9.1 rack-1.0.0).each do |gemfile|
out.should include("Caching: #{gemfile}.gem")
end
- tmp_gem_path.should include_cached_gems("rack-0.9.1", "abstract-1.0.0")
- tmp_gem_path.should have_installed_gems("rack-0.9.1", "abstract-1.0.0")
+ tmp_gem_path.should include_cached_gems("rack-1.0.0", "activesupport-2.3.2")
+ tmp_gem_path.should have_installed_gems("rack-1.0.0", "activesupport-2.3.2")
end
end
it "adds a gem from the local repository" do
- build_manifest <<-Gemfile
- clear_sources
- gem "rspec"
- disable_system_gems
- Gemfile
-
- Dir.chdir(bundled_app) do
- out = gem_command :bundle, "--cache rspec"
- gem_command :bundle, "--cached"
- out = run_in_context "require 'spec' ; puts Spec"
- out.should == "Spec"
+ system_gems "rake-0.8.7" do
+ build_manifest <<-Gemfile
+ clear_sources
+ gem "rake"
+ disable_system_gems
+ Gemfile
+
+ Dir.chdir(bundled_app) do
+ out = gem_command :bundle, "--cache rake"
+ gem_command :bundle, "--cached"
+ out = run_in_context "require 'rake' ; puts RAKE"
+ out.should == "0.8.7"
+ end
end
end
@@ -503,13 +466,12 @@
m = build_manifest <<-Gemfile
clear_sources
source "file://#{gem_repo1}"
- source "file://#{gem_repo2}"
gem "rack", "0.9.1"
gem "rails"
Gemfile
m.install
- Dir.chdir(bundled_app) do
+ app_root do
@output = gem_command :bundle, "--list-outdated"
end
View
45 spec/bundler/dependency_spec.rb
@@ -1,45 +0,0 @@
-require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
-
-describe "Bundler::Dependency" do
-
- it "is initialized with name" do
- b = Bundler::Dependency.new("rails")
- b.name.should == "rails"
- b.version.should == ">= 0"
- end
-
- it "can take an optional version" do
- b = Bundler::Dependency.new("rails", :version => "3.0")
- b.version.should == "3.0"
- end
-
- it "can take a 'version' option" do
- b = Bundler::Dependency.new("rails", "version" => "3.0")
- b.version.should == "3.0"
- end
-
- it "disallows the :rubygems environment" do
- lambda { Bundler::Dependency.new("ruby-debug", :only => "rubygems") }.
- should raise_error(Bundler::InvalidEnvironmentName)
- lambda { Bundler::Dependency.new("ruby-debug", :except => "rubygems") }.
- should raise_error(Bundler::InvalidEnvironmentName)
- end
-
- it "tests whether a dependency is for a specific environment (with :only)" do
- b = Bundler::Dependency.new("ruby-debug", :only => "development")
- b.should be_in("development")
- b.should be_in(:development)
-
- b.should_not be_in("production")
- b.should_not be_in(:production)
- end
-
- it "tests whether a dependency is for a specific environment (with :except)" do
- b = Bundler::Dependency.new("ruby-debug", :except => "development")
- b.should_not be_in("development")
- b.should_not be_in(:development)
-
- b.should be_in("production")
- b.should be_in(:production)
- end
-end
View
74 spec/bundler/directory_spec.rb
@@ -6,7 +6,8 @@
2.times do |i|
describe "stubbing out a gem with a directory -- #{i}" do
before(:each) do
- path = fixture_dir.join("very-simple")
+ build_lib "very-simple"
+ path = tmp_path("libs/very-simple-1.0")
path = path.relative_path_from(bundled_app) if i == 1
install_manifest <<-Gemfile
@@ -23,8 +24,8 @@
end
it "has very-simple in the load path" do
- out = run_in_context "require 'very-simple' ; puts VerySimpleForTests"
- out.should == "VerySimpleForTests"
+ out = run_in_context "require 'very-simple' ; puts VERYSIMPLE"
+ out.should == "1.0"
end
it "does not remove the directory during cleanup" do
@@ -33,7 +34,7 @@
source "file://#{gem_repo1}"
Gemfile
- fixture_dir.join("very-simple").should be_directory
+ tmp_path("libs/very-simple-1.0").should be_directory
end
it "can bundle --cached" do
@@ -43,8 +44,8 @@
Dir.chdir(bundled_app) do
out = gem_command :bundle, "--cached"
- out = run_in_context "require 'very-simple' ; puts VerySimpleForTests"
- out.should == "VerySimpleForTests"
+ out = run_in_context "require 'very-simple' ; puts VERYSIMPLE"
+ out.should == "1.0"
end
end
end
@@ -52,10 +53,11 @@
describe "bad directory stubbing" do
it "raises an exception unless the version is specified" do
+ build_lib "very-simple"
lambda do
install_manifest <<-Gemfile
clear_sources
- gem "very-simple", :path => "#{fixture_dir.join("very-simple")}"
+ gem "very-simple", :path => "#{tmp_path}/libs/very-simple-1.0"
Gemfile
end.should raise_error(Bundler::DirectorySourceError, /Please explicitly specify a version/)
end
@@ -73,15 +75,15 @@
end
it "checks the root directory for a *.gemspec file" do
- path = lib_builder("very-simple", "1.0", :path => tmp_path("very-simple")) do |s|
- s.add_dependency "rack", ">= 0.9.1"
+ build_lib("very-simple", "1.0", :path => tmp_path("very-simple"), :gemspec => true) do |s|
+ s.add_dependency "rack", "= 0.9.1"
s.write "lib/very-simple.rb", "class VerySimpleForTests ; end"
end
install_manifest <<-Gemfile
clear_sources
source "file://#{gem_repo1}"
- gem "very-simple", "1.0", :path => "#{path}"
+ gem "very-simple", "1.0", :path => "#{tmp_path("very-simple")}"
Gemfile
tmp_gem_path.should_not include_cached_gem("very-simple-1.0")
@@ -90,15 +92,15 @@
end
it "recursively finds all gemspec files in a directory" do
- lib_builder("first", "1.0")
- lib_builder("second", "1.0") do |s|
+ build_lib("first", "1.0", :gemspec => true)
+ build_lib("second", "1.0", :gemspec => true) do |s|
s.add_dependency "first", ">= 0"
s.write "lib/second.rb", "require 'first' ; SECOND = '1.0'"
end
install_manifest <<-Gemfile
clear_sources
- gem "second", :path => "#{tmp_path('dirs')}"
+ gem "second", :path => "#{tmp_path('libs')}"
Gemfile
out = run_in_context <<-RUBY
@@ -110,27 +112,15 @@
out.should == "1.0\n1.0"
end
- it "complains when the gemspec was not found in the directory specified" do
- pending "Not sure if this is correct behavior"
- lib_builder "first", "1.0"
-
- lambda {
- install_manifest <<-Gemfile
- clear_sources
- gem "first", "1.0", :path => "#{tmp_path('dirs')}"
- Gemfile
- }.should raise_error(Bundler::DirectorySourceError, /The location you specified for first is/)
- end
-
it "copies bin files to the bin dir" do
- path = lib_builder('very-simple', '1.0', :path => tmp_path("very-simple")) do |s|
+ build_lib('very-simple', '1.0', :gemspec => true) do |s|
s.executables << 'very_simple'
s.write "bin/very_simple", "#!#{Gem.ruby}\nputs 'OMG'"
end
install_manifest <<-Gemfile
clear_sources
- gem "very-simple", :path => "#{tmp_path('very-simple')}"
+ gem "very-simple", :path => "#{tmp_path('libs/very-simple-1.0')}"
Gemfile
tmp_bindir('very_simple').should exist
@@ -138,17 +128,17 @@
end
it "always pulls the dependency from the directory even if there is a newer gem available" do
- path = lib_builder('abstract', '0.5')
+ build_lib('rack', '0.5', :gemspec => true)
install_manifest <<-Gemfile
clear_sources
source "file://#{gem_repo1}"
- gem "abstract", :path => "#{path}"
+ gem "rack", :path => "#{tmp_path('libs')}"
Gemfile
out = run_in_context <<-RUBY
Bundler.require_env
- puts ABSTRACT
+ puts RACK
RUBY
out.should == '0.5'
@@ -159,8 +149,8 @@
ext = bundled_app("externals")
ext.mkdir_p
- lib_builder "omg", "1.0", :gemspec => false, :path => "#{ext}/omg"
- lib_builder "hi2u", "1.0", :gemspec => false, :path => "#{ext}/hi2u"
+ build_lib "omg", "1.0", :path => "#{ext}/omg"
+ build_lib "hi2u", "1.0", :path => "#{ext}/hi2u"
install_manifest <<-Gemfile
clear_sources
@@ -175,10 +165,10 @@
end
it "can list vendored gems without :path" do
- lib_builder "omg", "1.0", :gemspec => false
+ build_lib "omg", "1.0"
install_manifest <<-Gemfile
clear_sources
- directory "#{tmp_path}/dirs/omg" do
+ directory "#{tmp_path}/libs/omg-1.0" do
gem "omg", "1.0"
end
Gemfile
@@ -187,12 +177,12 @@
end
it "raises an error when two gems are defined for the same path" do
- lib_builder "omg", "1.0", :gemspec => false
+ build_lib "omg", "1.0"
lambda {
install_manifest <<-Gemfile
clear_sources
- directory "#{tmp_path('dirs')}" do
+ directory "#{tmp_path}/libs/omg-1.0" do
gem "omg", "1.0", :path => "omg"
gem "lol", "1.0", :path => "omg"
end
@@ -201,12 +191,12 @@
end
it "lets you set a directory source without a block" do
- lib_builder "omg", "1.0"
- lib_builder "lol", "1.0"
+ build_lib "omg", "1.0", :gemspec => true
+ build_lib "lol", "1.0", :gemspec => true
install_manifest <<-Gemfile
clear_sources
- directory "#{tmp_path}/dirs"
+ directory "#{tmp_path}/libs"
gem "omg"
gem "lol"
Gemfile
@@ -216,11 +206,11 @@
end
it "takes a glob" do
- lib_builder "omg", "1.0", :path => "#{tmp_path}/dirs/omg-1.0"
- lib_builder "omg", "2.0", :path => "#{tmp_path}/dirs/omg-2.0"
+ build_lib "omg", "1.0", :gemspec => true
+ build_lib "omg", "2.0", :gemspec => true
install_manifest <<-Gemfile
clear_sources
- directory "#{tmp_path}/dirs", :glob => "**/*-1*/*.gemspec" do
+ directory "#{tmp_path}/libs", :glob => "**/*-1*/*.gemspec" do
gem "omg"
end
Gemfile
View
60 spec/bundler/dsl_spec.rb
@@ -6,7 +6,6 @@
install_manifest <<-Gemfile
clear_sources
source "file://#{gem_repo1}"
- source "file://#{gem_repo2}"
gem "activerecord"
@@ -16,13 +15,13 @@
end
Gemfile
- "default".should have_const("ActiveRecord")
- "default".should_not have_const("Spec")
- "default".should_not have_const("VerySimpleForTests")
+ "default".should have_const("ACTIVERECORD")
+ "default".should_not have_const("SPEC")
+ "default".should_not have_const("VERYSIMPLE")
- "test".should have_const("ActiveRecord")
- "test".should have_const("Spec")
- "test".should have_const("VerySimpleForTests")
+ "test".should have_const("ACTIVERECORD")
+ "test".should have_const("SPEC")
+ "test".should have_const("VERYSIMPLE")
end
it "supports only blocks with multiple args" do
@@ -34,16 +33,15 @@
end
Gemfile
- "default".should_not have_const("Rack")
- "test".should have_const("Rack")
- "production".should have_const("Rack")
+ "default".should_not have_const("RACK")
+ "test".should have_const("RACK")
+ "production".should have_const("RACK")
end
it "supports nesting only blocks" do
install_manifest <<-Gemfile
clear_sources
source "file://#{gem_repo1}"
- source "file://#{gem_repo2}"
only [:test, :staging] do
gem "very-simple"
@@ -53,17 +51,16 @@
end
Gemfile
- "test".should have_const("VerySimpleForTests")
- "test".should have_const("Spec")
- "staging".should have_const("VerySimpleForTests")
- "staging".should_not have_const("Spec")
+ "test".should have_const("VERYSIMPLE")
+ "test".should have_const("SPEC")
+ "staging".should have_const("VERYSIMPLE")
+ "staging".should_not have_const("SPEC")
end
it "supports except blocks" do
install_manifest <<-Gemfile
clear_sources
source "file://#{gem_repo1}"
- source "file://#{gem_repo2}"
gem "activerecord"
@@ -73,13 +70,13 @@
end
Gemfile
- "default".should have_const("ActiveRecord")
- "default".should have_const("Spec")
- "default".should have_const("VerySimpleForTests")
+ "default".should have_const("ACTIVERECORD")
+ "default".should have_const("SPEC")
+ "default".should have_const("VERYSIMPLE")
- "test".should have_const("ActiveRecord")
- "test".should_not have_const("Spec")
- "test".should_not have_const("VerySimpleForTests")
+ "test".should have_const("ACTIVERECORD")
+ "test".should_not have_const("SPEC")
+ "test".should_not have_const("VERYSIMPLE")
end
it "supports except blocks with multiple args" do
@@ -91,16 +88,15 @@
end
Gemfile
- "default".should have_const("Rack")
- "test".should_not have_const("Rack")
- "production".should_not have_const("Rack")
+ "default".should have_const("RACK")
+ "test".should_not have_const("RACK")
+ "production".should_not have_const("RACK")
end
it "supports nesting except blocks" do
install_manifest <<-Gemfile
clear_sources
source "file://#{gem_repo1}"
- source "file://#{gem_repo2}"
except [:test] do
gem "very-simple"
@@ -110,11 +106,11 @@
end
Gemfile
- "default".should have_const("Spec")
- "default".should have_const("VerySimpleForTests")
- "test".should_not have_const("VerySimpleForTests")
- "test".should_not have_const("Spec")
- "omg".should have_const("VerySimpleForTests")
- "omg".should_not have_const("Spec")
+ "default".should have_const("SPEC")
+ "default".should have_const("VERYSIMPLE")
+ "test".should_not have_const("VERYSIMPLE")
+ "test".should_not have_const("SPEC")
+ "omg".should have_const("VERYSIMPLE")
+ "omg".should_not have_const("SPEC")
end
end
View
25 spec/bundler/fetcher_spec.rb
@@ -1,10 +1,6 @@
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
describe "Fetcher" do
- before(:each) do
- @source = Bundler::GemSource.new(:uri => "file://#{gem_repo1}")
- @other = Bundler::GemSource.new(:uri => "file://#{gem_repo2}")
- end
it "raises if the source does not exist" do
m = build_manifest <<-Gemfile
@@ -40,7 +36,6 @@
m = build_manifest <<-Gemfile
clear_sources
source "file://#{gem_repo1}"
- source "file://#{gem_repo2}"
gem "do_sqlite3"
Gemfile
@@ -60,38 +55,36 @@
m = build_manifest <<-Gemfile
clear_sources
source "file://#{gem_repo1}"
- source "file://#{gem_repo2}"
gem "very-simple"
Gemfile
m.install
@log_output.should have_log_message("Updating source: file:#{gem_repo1}")
- @log_output.should have_log_message("Updating source: file:#{gem_repo2}")
end
it "works with repositories that don't provide Marshal.4.8.Z" do
- gem_repo1.cp_r(tmp_path.join('bogus_repo'))
- Dir["#{tmp_path.join('bogus_repo')}/Marshal.*"].each { |f| File.unlink(f) }
+ FileUtils.cp_r gem_repo1, gem_repo2
+ Dir["#{gem_repo2}/Marshal.*"].each { |f| File.unlink(f) }
install_manifest <<-Gemfile
clear_sources
- source "file://#{tmp_path.join('bogus_repo')}"
+ source "file://#{gem_repo2}"
gem "rack"
Gemfile
- tmp_gem_path.should have_cached_gems("rack-0.9.1")
+ tmp_gem_path.should have_cached_gems("rack-1.0.0")
end
it "works with repositories that don't provide prerelease_specs.4.8.gz" do
- gem_repo1.cp_r(tmp_path.join('bogus_repo'))
- Dir["#{tmp_path.join('bogus_repo')}/prerelease*"].each { |f| File.unlink(f) }
+ FileUtils.cp_r gem_repo1, gem_repo2
+ Dir["#{gem_repo2}/prerelease*"].each { |f| File.unlink(f) }
install_manifest <<-Gemfile
clear_sources
- source "file://#{tmp_path.join('bogus_repo')}"
+ source "file://#{gem_repo2}"
gem "rack"
Gemfile
- @log_output.should have_log_message("Source 'file:#{tmp_path.join('bogus_repo')}' does not support prerelease gems")
- tmp_gem_path.should have_cached_gems("rack-0.9.1")
+ @log_output.should have_log_message("Source 'file:#{gem_repo2}' does not support prerelease gems")
+ tmp_gem_path.should have_cached_gems("rack-1.0.0")
end
end
View
60 spec/bundler/finder_spec.rb
@@ -1,60 +0,0 @@
-require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
-
-describe "Finder" do
- # TODO: Refactor all of these specs
- before(:each) do
- index = build_index do
- add_spec "activemerchant", "1.4.1" do
- runtime "activesupport", ">= 1.4.1"
- end
- add_spec "activesupport", "3.0.0"
- add_spec "activesupport", "2.3.2"
- add_spec "action_pack", "2.3.2" do
- runtime "activesupport", "= 2.3.2"
- end
- end
-
- def index.specs
- specs = Hash.new{|h,k| h[k] = {}}
- @gems.values.each do |spec|
- specs[spec.name][spec.version] = spec
- end
- specs
- end
-
- @faster = Bundler::Finder.new(index)
- end
-
- it "find the gem given correct search" do
- [
- build_dep("activemerchant", "= 1.4.1"),
- build_dep("activemerchant", ">= 1.4.1"),
- build_dep("activemerchant", "<= 1.4.1"),
- build_dep("activemerchant", ">= 1.4.0"),
- build_dep("activemerchant", ">= 1.4"),
- build_dep("activemerchant", ">= 1.3.0"),
- build_dep("activemerchant", ">= 1.3"),
- build_dep("activemerchant", ">= 1"),
- build_dep("activemerchant", ">= 1.4.1"),
- build_dep("activemerchant", "> 0"),
- build_dep("activemerchant", "<= 1.4.1"),
- build_dep("activemerchant", "<= 2"),
- ].each { |dep| @faster.search(dep).should only_have_spec("activemerchant-1.4.1") }
- end
-
- it "does not find the gem given an incorrect search" do
- [
- build_dep("activemerchant", "= 1.4.0"),
- build_dep("activemerchant", "= 1.4"),
- build_dep("activemerchant", "= 1"),
- build_dep("activemerchant", ">= 1.4.2"),
- build_dep("activemerchant", "> 1.4.1"),
- build_dep("activemerchant", "<= 1.4.0"),
- build_dep("activemerchant", "< 1.4.1"),
- ].each { |dep| @faster.search(dep).should be_empty }
- end
-
- it "returns all gem specs that match the search" do
- @faster.search(build_dep("activesupport", "> 0")).should only_have_specs("activesupport-2.3.2", "activesupport-3.0.0")
- end
-end
View
32 spec/bundler/git_spec.rb
@@ -2,9 +2,13 @@
describe "Getting gems from git" do
+ before :each do
+ build_lib "very-simple", :path => "#{tmp_path}/very-simple"
+ end
+
describe "a simple gem in git" do
before(:each) do
- @path = build_git_repo "very-simple", :with => fixture_dir.join("very-simple")
+ @path = build_git_repo "very-simple", :with => tmp_path.join("very-simple")
install_manifest <<-Gemfile
clear_sources
source "file://#{gem_repo1}"
@@ -19,8 +23,8 @@
end
it "has very-simple in the load path" do
- out = run_in_context "require 'very-simple' ; puts VerySimpleForTests"
- out.should == "VerySimpleForTests"
+ out = run_in_context "require 'very-simple' ; puts VERYSIMPLE"
+ out.should == "1.0"
end
it "removes the directory during cleanup" do
@@ -46,8 +50,8 @@
Dir.chdir(bundled_app) do
out = gem_command :bundle, "--cached"
- out = run_in_context "require 'very-simple' ; puts VerySimpleForTests"
- out.should == "VerySimpleForTests"
+ out = run_in_context "require 'very-simple' ; puts VERYSIMPLE"
+ out.should == "1.0"
end
end
end
@@ -68,13 +72,13 @@
Gemfile
tmp_gem_path.should_not include_cached_gem("very-simple-1.0")
- tmp_gem_path.should include_cached_gem("rack-0.9.1")
- tmp_gem_path.should include_installed_gem("rack-0.9.1")
+ tmp_gem_path.should include_cached_gem("rack-1.0.0")
+ tmp_gem_path.should include_installed_gem("rack-1.0.0")
end
it "recursively finds all gemspec files in a git repository" do
- lib_builder("first", "1.0", :path => tmp_path("gitz", "first"))
- lib_builder("second", "1.0", :path => tmp_path("gitz", "second")) do |s|
+ build_lib("first", "1.0", :path => tmp_path("gitz", "first"), :gemspec => true)
+ build_lib("second", "1.0", :path => tmp_path("gitz", "second"), :gemspec => true) do |s|
s.add_dependency "first", ">= 0"
s.write "lib/second.rb", "require 'first' ; SECOND = '1.0'"
end
@@ -127,7 +131,7 @@
describe "using a git block" do
it "loads the gems specified in the git block" do
- lib_builder "omg", "1.0"
+ build_lib "omg", "1.0", :gemspec => true, :path => "#{tmp_path}/dirs/omg"
gitify("#{tmp_path}/dirs/omg")
install_manifest <<-Gemfile
@@ -141,7 +145,7 @@
end
it "works when specifying a branch" do
- lib_builder "omg", "1.0"
+ build_lib "omg", "1.0", :gemspec => true, :path => "#{tmp_path}/dirs/omg"
gitify("#{tmp_path}/dirs/omg")
install_manifest <<-Gemfile
@@ -155,7 +159,7 @@
end
it "works when the gems don't have gemspecs" do
- lib_builder "omg", "1.0", :gemspec => false
+ build_lib "omg", "1.0", :gemspec => false, :path => "#{tmp_path}/dirs/omg"
gitify("#{tmp_path}/dirs/omg")
install_manifest <<-Gemfile
@@ -169,7 +173,7 @@
end
it "works when the gems are not at the root" do
- lib_builder "omg", "1.0", :gemspec => false
+ build_lib "omg", "1.0", :gemspec => false, :path => "#{tmp_path}/dirs/omg"
gitify("#{tmp_path}/dirs")
install_manifest <<-Gemfile
@@ -183,7 +187,7 @@
end
it "always pulls the dependency from git even if there is a newer gem available" do
- lib_builder "abstract", "0.5"
+ build_lib "abstract", "0.5", :path => "#{tmp_path}/dirs/abstract", :gemspec => true
gitify("#{tmp_path}/dirs/abstract")
install_manifest <<-Gemfile
View
14 spec/bundler/installer_spec.rb
@@ -17,7 +17,6 @@ def setup
@manifest = build_manifest <<-Gemfile
clear_sources
source "file://#{gem_repo1}"
- source "file://#{gem_repo2}"
gem "rails"
Gemfile
end
@@ -56,7 +55,6 @@ def setup
m = build_manifest <<-Gemfile
clear_sources
source "file://#{gem_repo1}"
- source "file://#{gem_repo2}"
bin_path "#{bundled_app("omgbinz")}"
gem "rails"
Gemfile
@@ -102,7 +100,7 @@ def setup
install_manifest <<-Gemfile
clear_sources
- source "file://#{gem_repo2}"
+ source "file://#{gem_repo1}"
gem "rack", "1.0.0"
Gemfile
@@ -150,15 +148,5 @@ def setup
@manifest.install
bundled_app('bin', 'rails').should be_file
end
-
- it "compiles binary gems" do
- m = build_manifest <<-Gemfile
- clear_sources
- source "file://#{gem_repo2}"
- gem "json"
- Gemfile
- m.install
- Dir["#{bundled_app}/vendor/gems/gems/json-*/**/*.#{Config::CONFIG['DLEXT']}"].should have_at_least(1).item
- end
end
end
View
45 spec/bundler/manifest_spec.rb
@@ -2,34 +2,15 @@
describe "Bundler::Environment" do
- def dep(name, version, options = {})
- Bundler::Dependency.new(name, {:version => version}.merge(options))
- end
-
- before(:each) do
- @sources = %W(file://#{gem_repo1} file://#{gem_repo2})
- @deps = []
- @deps << dep("rails", "2.3.2")
- @deps << dep("rack", "0.9.1")
- end
-
describe "Manifest with dependencies" do
- before(:each) do
+ before :each do
@manifest = build_manifest <<-Gemfile
clear_sources
source "file://#{gem_repo1}"
- source "file://#{gem_repo2}"
gem "rails", "2.3.2"
gem "rack", "0.9.1"
Gemfile
- @saved_load_path, @saved_loaded_features = $:.dup, $".dup
- end
-
- after(:each) do
- Object.send(:remove_const, :VerySimpleForTests) if defined?(VerySimpleForTests)
- $:.replace @saved_load_path
- $".replace @saved_loaded_features
end
it "bundles itself (running all of the steps)" do
@@ -47,7 +28,7 @@ def dep(name, version, options = {})
it "skips fetching the source index if all gems are present" do
Dir.chdir(bundled_app) do
gem_command :bundle
- lambda { gem_command :bundle }.should_not change { File.stat(gem_repo1.join("Marshal.4.8.Z")).atime }
+ lambda { sleep 0.1 ; gem_command :bundle }.should_not change { File.stat(gem_repo1.join("Marshal.4.8.Z")).atime }
end
end
@@ -56,14 +37,12 @@ def dep(name, version, options = {})
@log_output.should have_log_message("Done.")
end
-
it "does the full fetching if a gem in the cache does not match the manifest" do
@manifest.install
m = build_manifest <<-Gemfile
clear_sources
source "file://#{gem_repo1}"
- source "file://#{gem_repo2}"
gem "rails", "2.3.2"
gem "rack", "1.0.0"
Gemfile
@@ -89,7 +68,6 @@ def dep(name, version, options = {})
m = build_manifest <<-Gemfile
clear_sources
source "file://#{gem_repo1}"
- source "file://#{gem_repo2}"
gem "rails", "2.3.2"
Gemfile
@@ -129,7 +107,7 @@ def dep(name, version, options = {})
install_manifest <<-Gemfile
clear_sources
source "file://#{gem_repo1}"
- gem "very-simple"
+ gem "rack"
Gemfile
out = run_in_context "require 'rake' ; puts Rake"
@@ -140,7 +118,7 @@ def dep(name, version, options = {})
m = build_manifest <<-Gemfile
clear_sources
source "file://#{gem_repo1}"
- gem "very-simple"
+ gem "rack"
disable_system_gems
Gemfile
@@ -155,24 +133,24 @@ def dep(name, version, options = {})
m = build_manifest <<-Gemfile
clear_sources
source "file://#{gem_repo1}"
- gem "very-simple"
+ gem "rake"
#{'disable_system_gems' if i == 1}
Gemfile
m.install
end
it "sets loaded_from on the specs" do
- out = run_in_context "puts(Gem.loaded_specs['very-simple'].loaded_from || 'FAIL')"
+ out = run_in_context "puts(Gem.loaded_specs['rake'].loaded_from || 'FAIL')"
out.should_not == "FAIL"
end
it "finds the gems in the source_index" do
- out = run_in_context "puts Gem.source_index.find_name('very-simple').length"
+ out = run_in_context "puts Gem.source_index.find_name('rake').length"
out.should == "1"
end
it "still finds the gems in the source_index even if refresh! is called" do
- out = run_in_context "Gem.source_index.refresh! ; puts Gem.source_index.find_name('very-simple').length"
+ out = run_in_context "Gem.source_index.refresh! ; puts Gem.source_index.find_name('rake').length"
out.should == "1"
end
end
@@ -184,9 +162,8 @@ def dep(name, version, options = {})
@manifest = build_manifest <<-Gemfile
clear_sources
source "file://#{gem_repo1}"
- source "file://#{gem_repo2}"
- gem "very-simple", "1.0.0", :only => "testing"
- gem "rack", "1.0.0"
+ gem "rake", :only => "testing"
+ gem "rack", "1.0.0"
Gemfile
@manifest.install
@@ -205,7 +182,7 @@ def dep(name, version, options = {})
it "Gem.loaded_specs has the gems that are included in the testing environment" do
out = run_in_context %'puts Gem.loaded_specs.map{|k,v|"\#{k} - \#{v.version}"}'
out.should include("rack - 1.0.0")
- out.should include("very-simple - 1.0")
+ out.should include("rake - 0.8.7")
end
end
end
View
28 spec/bundler/runtime_spec.rb
@@ -12,25 +12,25 @@
out = run_in_context <<-RUBY
Bundler.require_env
- puts VerySimpleForTests
+ puts VERYSIMPLE
RUBY
- out.should == "VerySimpleForTests"
+ out.should == "1.0"
end
it "correctly requires the specified files" do
install_manifest <<-Gemfile
clear_sources
- source "file://#{gem_repo2}"
- gem "actionpack", :require_as => %w(action_controller action_view)
+ source "file://#{gem_repo1}"
+ gem "rspec", :require_as => %w(spec)
Gemfile
out = run_in_context <<-RUBY
Bundler.require_env
- puts "\#{ActionController} -- \#{ActionView}"
+ puts SPEC
RUBY
- out.should == "ActionController -- ActionView"
+ out.should == "1.2.7"
end
it "executes blocks at require time" do
@@ -94,10 +94,10 @@
out = run_in_context <<-RUBY
Bundler.require_env :test
- puts VerySimpleForTests
+ puts VERYSIMPLE
RUBY
- out.should == "VerySimpleForTests"
+ out.should == "1.0"
end
it "only requires gems in the environments they are exclusive to" do
@@ -108,9 +108,9 @@
Gemfile
out = run_in_context <<-RUBY
- Bundler.require_env ; puts defined?(VerySimpleForTests).inspect
- Bundler.require_env :foo ; puts defined?(VerySimpleForTests).inspect
- Bundler.require_env :bar ; puts defined?(VerySimpleForTests)
+ Bundler.require_env ; puts defined?(VERYSIMPLE).inspect
+ Bundler.require_env :foo ; puts defined?(VERYSIMPLE).inspect
+ Bundler.require_env :bar ; puts defined?(VERYSIMPLE)
RUBY
out.should == "nil\nnil\nconstant"
@@ -124,14 +124,14 @@
Gemfile
out = run_in_context <<-RUBY
- Bundler.require_env :bar ; puts defined?(VerySimpleForTests).inspect
- Bundler.require_env :foo ; puts defined?(VerySimpleForTests)
+ Bundler.require_env :bar ; puts defined?(VERYSIMPLE).inspect
+ Bundler.require_env :foo ; puts defined?(VERYSIMPLE)
RUBY
out.should == "nil\nconstant"
out = run_in_context <<-RUBY
- Bundler.require_env ; puts defined?(VerySimpleForTests)
+ Bundler.require_env ; puts defined?(VERYSIMPLE)
RUBY
out.should == "constant"
View
22 spec/resolver/engine_spec.rb
@@ -84,28 +84,6 @@
)
end
- it "supports merb-core" do
- index = Gem::SourceIndex.from_gems_in(gem_repo3.join("specifications"))
-
- deps = [
- build_dep("merb-core", "= 1.0.7.1"),
- ]
-
- solution = Bundler::Resolver.resolve(deps, [index])
- solution.should match_gems(
- "merb-core"=>["1.0.7.1"],
- "rake"=>["0.8.7"],
- "thor"=>["0.9.9"],
- "rspec"=>["1.2.2"],
- "mime-types"=>["1.16"],
- "abstract"=>["1.0.0"],
- "rack"=>["1.0.0"],
- "erubis"=>["2.6.4"],
- "extlib"=>["0.9.12"],
- "json_pure"=>["1.1.7"]
- )
- end
-
it "supports impossible situations" do
index = build_index do
add_spec "a", "1.0"
View
16 spec/spec_helper.rb
@@ -5,10 +5,17 @@
require "bundler"
require "spec"
require "rbconfig"
+
Dir[File.join(File.dirname(__FILE__), 'support', '*.rb')].each do |file|
require file
end
+tmpdir = File.expand_path('../../tmp', __FILE__)
+FileUtils.mkdir_p(tmpdir) unless File.exist?(tmpdir)
+Dir["#{tmpdir}/*"].each do |file|
+ FileUtils.rm_rf file
+end
+
Spec::Runner.configure do |config|
config.include Spec::Builders
config.include Spec::Matchers
@@ -20,8 +27,13 @@
# No rubygems output messages
Gem::DefaultUserInteraction.ui = Gem::SilentUI.new
+ config.before(:all) do
+ build_repo1
+ end
+
config.before(:each) do
- @log_output = StringIO.new
+ @_build_path = nil
+ @log_output = StringIO.new
Bundler.logger.instance_variable_set("@logdev", Logger::LogDevice.new(@log_output))
reset!
end
@@ -29,4 +41,4 @@
config.after(:each) do
Dir.chdir(original_wd)
end
-end
+end
View
166 spec/support/builders.rb
@@ -1,5 +1,83 @@
module Spec
module Builders
+
+ def build_repo1
+ build_repo gem_repo1 do
+ build_gem "rake", "0.8.7" do |s|
+ s.executables = "rake"
+ end
+ build_gem "rack", %w(0.9.1 1.0.0) do |s|
+ s.executables = "rackup"
+ end
+ build_gem "rails", "2.3.2" do |s|
+ s.executables = "rails"
+ s.add_dependency "rake"
+ s.add_dependency "actionpack", "2.3.2"
+ s.add_dependency "activerecord", "2.3.2"
+ s.add_dependency "actionmailer", "2.3.2"
+ s.add_dependency "activeresource", "2.3.2"
+ end
+ build_gem "actionpack", "2.3.2" do |s|
+ s.add_dependency "activesupport", "2.3.2"
+ end
+ build_gem "activerecord", "2.3.2" do |s|
+ s.add_dependency "activesupport", "2.3.2"
+ end
+ build_gem "actionmailer", "2.3.2" do |s|
+ s.add_dependency "activesupport", "2.3.2"
+ end
+ build_gem "activeresource", "2.3.2" do |s|
+ s.add_dependency "activesupport", "2.3.2"
+ end
+ build_gem "activesupport", "2.3.2"
+
+ build_gem "missing_dep" do |s|
+ s.add_dependency "not_here"
+ end
+
+ build_gem "rspec", "1.2.7", :no_default => true do |s|
+ s.write "lib/spec.rb", "SPEC = '1.2.7'"
+ end
+
+ build_gem "rack-test", :no_default => true do |s|
+ s.write "lib/rack/test.rb", "RACK_TEST = '1.0'"
+ end
+
+ build_gem "very-simple"
+
+ build_gem "very-simple-prerelease", "1.0.pre"
+
+ build_gem "very_simple_binary" do |s|
+ s.require_paths << 'ext'
+ s.extensions << "ext/extconf.rb"
+ s.write "ext/extconf.rb", <<-RUBY
+ require "mkmf"
+
+ exit 1 unless with_config("simple")
+
+ extension_name = "very_simple_binary"
+ dir_config extension_name
+ create_makefile extension_name
+ RUBY
+ s.write "ext/very_simple_binary.c", <<-C
+ #include "ruby.h"
+
+ void Init_very_simple_binary() {
+ rb_define_module("VerySimpleBinaryInC");
+ }
+ C
+ end
+ end
+ end
+
+ def build_repo(path)
+ return if File.directory?(path)
+ @_build_path = "#{path}/gems"
+ yield
+ @_build_path = nil
+ Dir.chdir(path) { gem_command :generate_index }
+ end
+
def build_index(&block)
index = Gem::SourceIndex.new
IndexBuilder.run(index, &block) if block_given?
@@ -18,6 +96,29 @@ def build_dep(name, requirements = Gem::Requirement.default, type = :runtime)
Gem::Dependency.new(name, requirements, type)
end
+ def build_lib(name, *args, &blk)
+ build_with(LibBuilder, name, args, &blk)
+ end
+
+ def build_gem(name, *args, &blk)
+ build_with(GemBuilder, name, args, &blk)
+ end
+
+ private
+
+ def build_with(builder, name, args, &blk)
+ options = args.last.is_a?(Hash) ? args.pop : {}
+ versions = args.last || "1.0"
+
+ options[:path] ||= @_build_path
+
+ Array(versions).each do |version|
+ spec = builder.new(self, name, version)
+ yield spec if block_given?
+ spec._build(options)
+ end
+ end
+
class IndexBuilder
include Builders
@@ -55,5 +156,70 @@ def runtime(name, requirements)
@spec.add_runtime_dependency(name, requirements)
end
end
+
+ class LibBuilder
+ def initialize(context, name, version)
+ @context = context
+ @name = name
+ @spec = Gem::Specification.new do |s|
+ s.name = name
+ s.version = version
+ s.summary = "This is just a fake gem for testing"
+ end
+ @files = {}
+ @default_files = { "lib/#{name}.rb" => "#{name.gsub('-', '').upcase} = '#{version}'" }
+ end
+
+ def method_missing(*args, &blk)
+ @spec.send(*args, &blk)
+ end
+
+ def write(file, source)
+ @files[file] = source
+ end
+
+ def executables=(val)
+ Array(val).each do |file|
+ write "bin/#{file}", "require '#{@name}' ; puts #{@name.upcase}"
+ end
+ @spec.executables = Array(val)
+ end
+
+ def _build(options)
+ path = options[:path] || _default_path
+ @files["#{name}.gemspec"] = @spec.to_ruby if options[:gemspec]
+ unless options[:no_default]
+ @files = @default_files.merge(@files)
+ end
+ @files.each do |file, source|
+ file = Pathname.new(path).join(file)
+ FileUtils.mkdir_p(file.dirname)
+ File.open(file, 'w') { |f| f.puts source }
+ end
+ @spec.files = @files.keys
+ path
+ end
+
+ def _default_path
+ @context.tmp_path('libs', @spec.full_name)
+ end
+ end
+
+ class GemBuilder < LibBuilder
+
+ def _build(opts)
+ lib_path = super(:path => @context.tmp_path(".tmp/#{@spec.full_name}"), :no_default => opts[:no_default])
+ Dir.chdir(lib_path) do
+ destination = opts[:path] || _default_path
+ FileUtils.mkdir_p(destination)
+ Gem::Builder.new(@spec).build
+ FileUtils.mv("#{@spec.full_name}.gem", opts[:path] || _default_path)
+ end
+ end
+
+ def _default_path
+ @context.gem_repo1('gems')
+ end
+ end
end
end
View
49 spec/support/helpers.rb
@@ -87,49 +87,10 @@ def gitify(path)
end
end
- class LibBuilder
- def initialize(name, version, options)
- @spec = Gem::Specification.new do |s|
- s.name = name
- s.version = version
- end
- @options = options
- @files = { "lib/#{name}.rb" => "#{name.upcase} = '#{version}'" }
- end
-
- def method_missing(*args, &blk)
- @spec.send(*args, &blk)
- end
-
- def write(file, source)
- @files[file] = source
- end
-
- def _build(path)
- path ||= tmp_path('dirs', name)
- path = Pathname.new(path)
- @files["#{name}.gemspec"] = @spec.to_ruby if @options[:gemspec]
- @files.each do |file, source|
- file = path.join(file)
- file.dirname.mkdir_p
- File.open(file, 'w') { |f| f.puts source }
- end
- path
- end
- end
-
- def lib_builder(name, version, options = {})
- options[:gemspec] = true unless options.key?(:gemspec)
-
- spec = LibBuilder.new(name, version, options)
- yield spec if block_given?
- spec._build(options[:path] || tmp_path('dirs', name))
- end
-
def install_gems(*gems)
- Dir["#{fixture_dir}/*/gems/*.gem"].each do |path|
+ Dir["#{tmp_path}/repos/**/*.gem"].each do |path|
if gems.include?(File.basename(path, ".gem"))
- `gem install --no-rdoc --no-ri --ignore-dependencies #{path}`
+ gem_command :install, "--no-rdoc --no-ri --ignore-dependencies #{path}"
end
end
end
@@ -148,8 +109,10 @@ def system_gems(*gems)
end
def reset!
- tmp_path.rmtree if tmp_path.exist?
- tmp_path.mkdir
+ Dir["#{tmp_path}/*"].each do |file|
+ FileUtils.rm_rf(file) unless File.basename(file) == "repos"
+ end
+ FileUtils.mkdir_p(tmp_path)
end
end
end
View
30 spec/support/path_utils.rb
@@ -8,9 +8,7 @@ def tmp_path(*path)
root.join("tmp", *path).expand_path
end
- # def tmp_dir
- # this_file.join("..", "tmp")
- # end
+ alias fixture_dir tmp_path
def bundled_app(*path)
tmp_path.join("bundled_app").join(*path)
@@ -24,10 +22,6 @@ def tmp_bindir(*path)
bundled_app("bin").join(*path)
end
- # def tmp_file(*path)
- # tmp_dir.join(*path)
- # end
-
def cache_path(*path)
bundled_app.join("cache", *path)
end
@@ -36,24 +30,12 @@ def cached(gem_name)
cache_path.join("#{gem_name}.gem")
end
- def fixture_dir
- root.join("spec", "fixtures")
- end
-
def gem_repo1(*path)
- fixture_dir.join("repository1", *path).expand_path
+ tmp_path("repos/1")
end
def gem_repo2(*path)
- fixture_dir.join("repository2", *path).expand_path
- end
-
- def gem_repo3(*path)
- fixture_dir.join("repository3", *path).expand_path
- end
-
- def fixture(gem_name)
- fixture_dir.join("repository1", "gems", "#{gem_name}.gem")
+ tmp_path("repos/2")
end
def system_gem_path(*path)
@@ -63,5 +45,11 @@ def system_gem_path(*path)
def copy(gem_name)
FileUtils.cp(fixture(gem_name), File.join(tmp_dir, 'cache'))
end
+
+ def app_root
+ Dir.chdir bundled_app do
+ yield
+ end
+ end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.