Skip to content

Commit

Permalink
Fixed specs
Browse files Browse the repository at this point in the history
  • Loading branch information
fabien committed Sep 19, 2008
1 parent 8bc3e5f commit 47c8096
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
2 changes: 1 addition & 1 deletion bin/minigem
Expand Up @@ -72,7 +72,7 @@ elsif ARGV[0] == 'revert'
elsif ARGV[0] == 'install' || ARGV[0] == 'update' elsif ARGV[0] == 'install' || ARGV[0] == 'update'
# Install or update a rubygem and prepare it for minigems. # Install or update a rubygem and prepare it for minigems.
command = ARGV.shift.to_sym # skip command argument command = ARGV.shift.to_sym # skip command argument
ensure_in_load_path! ensure_in_load_path!(ARGV.empty?)
# Remove any gems that have been specified. # Remove any gems that have been specified.
unless ARGV.empty? unless ARGV.empty?
cmd = Gem::GemRunner.new.run_command(command, ARGV) cmd = Gem::GemRunner.new.run_command(command, ARGV)
Expand Down
12 changes: 5 additions & 7 deletions lib/minigems.rb
Expand Up @@ -114,20 +114,18 @@ def self.activate(gem, *version_requirements)
elsif already_loaded elsif already_loaded
return false return false
end end

# Keep track of loaded gems - by name instead of full specs (memory!) # Keep track of loaded gems - by name instead of full specs (memory!)
self.loaded_gems[gem_spec.name] = gem_spec.full_name self.loaded_gems[gem_spec.name] = gem_spec.full_name


# Load dependent gems first # Load dependent gems first
gem_spec.runtime_dependencies.each { |dep_gem| activate(dep_gem) } gem_spec.runtime_dependencies.each { |dep_gem| activate(dep_gem) }


# Add gem bindir path to $LOAD_PATH # bin directory must come before library directories
unless gem_spec.executables.empty? gem_spec.require_paths.unshift(gem_spec.bindir) if gem_spec.bindir
$LOAD_PATH.unshift File.join(gem_spec.full_gem_path, gem_spec.bindir)
end


# Add gem require paths to $LOAD_PATH # Add gem require paths to $LOAD_PATH
gem_spec.require_paths.each do |require_path| gem_spec.require_paths.reverse.each do |require_path|
$LOAD_PATH.unshift File.join(gem_spec.full_gem_path, require_path) $LOAD_PATH.unshift File.join(gem_spec.full_gem_path, require_path)
end end
return true return true
Expand Down
12 changes: 8 additions & 4 deletions spec/minigems_spec.rb
Expand Up @@ -51,24 +51,28 @@
gem_bin_path = File.join(@gem_dir, "gems", "gem_with_lib-0.0.2", "bin") gem_bin_path = File.join(@gem_dir, "gems", "gem_with_lib-0.0.2", "bin")
$LOAD_PATH.should_not include(gem_lib_path) $LOAD_PATH.should_not include(gem_lib_path)
gem("gem_with_lib").should be_true gem("gem_with_lib").should be_true
$LOAD_PATH.first.should == gem_lib_path $LOAD_PATH.first.should == gem_bin_path
$LOAD_PATH.should include(gem_bin_path) $LOAD_PATH.should include(gem_lib_path)
$LOAD_PATH.select { |path| path == gem_lib_path }.length.should == 1 $LOAD_PATH.select { |path| path == gem_lib_path }.length.should == 1
lambda { GemWithLib::Awesome }.should raise_error(NameError) lambda { GemWithLib::Awesome }.should raise_error(NameError)
end end


it "uses 'gem' to setup additional load path entries (for a specific gem version)" do it "uses 'gem' to setup additional load path entries (for a specific gem version)" do
gem_lib_path = File.join(@gem_dir, "gems", "gem_with_lib-0.0.1", "lib") gem_lib_path = File.join(@gem_dir, "gems", "gem_with_lib-0.0.1", "lib")
gem_bin_path = File.join(@gem_dir, "gems", "gem_with_lib-0.0.1", "bin")
$LOAD_PATH.should_not include(gem_lib_path) $LOAD_PATH.should_not include(gem_lib_path)
gem("gem_with_lib", "0.0.1").should be_true gem("gem_with_lib", "0.0.1").should be_true
$LOAD_PATH.first.should == gem_lib_path $LOAD_PATH.first.should == gem_bin_path
$LOAD_PATH.should include(gem_lib_path)
end end


it "uses 'gem' to setup additional load path entries (for a gem version requirement)" do it "uses 'gem' to setup additional load path entries (for a gem version requirement)" do
gem_lib_path = File.join(@gem_dir, "gems", "gem_with_lib-0.0.2", "lib") gem_lib_path = File.join(@gem_dir, "gems", "gem_with_lib-0.0.2", "lib")
gem_bin_path = File.join(@gem_dir, "gems", "gem_with_lib-0.0.2", "bin")
$LOAD_PATH.should_not include(gem_lib_path) $LOAD_PATH.should_not include(gem_lib_path)
gem("gem_with_lib", ">0.0.1").should be_true gem("gem_with_lib", ">0.0.1").should be_true
$LOAD_PATH.first.should == gem_lib_path $LOAD_PATH.first.should == gem_bin_path
$LOAD_PATH.should include(gem_lib_path)
end end


it "correctly requires a file from the load path" do it "correctly requires a file from the load path" do
Expand Down

0 comments on commit 47c8096

Please sign in to comment.