2008-03-29 22:17:28 -04:00
|
|
|
require 'plugin_test_helper'
|
2009-04-28 21:21:03 -04:00
|
|
|
require 'rails/gem_dependency'
|
2008-03-29 22:17:28 -04:00
|
|
|
|
2008-04-21 13:23:15 -04:00
|
|
|
class Rails::GemDependency
|
|
|
|
public :install_command, :unpack_command
|
|
|
|
end
|
|
|
|
|
2008-10-31 02:12:48 -04:00
|
|
|
Rails::VendorGemSourceIndex.silence_spec_warnings = true
|
|
|
|
|
2009-02-03 21:25:37 -05:00
|
|
|
class GemDependencyTest < Test::Unit::TestCase
|
|
|
|
def setup
|
|
|
|
@gem = Rails::GemDependency.new "xhpricotx"
|
|
|
|
@gem_with_source = Rails::GemDependency.new "xhpricotx", :source => "http://code.whytheluckystiff.net"
|
|
|
|
@gem_with_version = Rails::GemDependency.new "xhpricotx", :version => "= 0.6"
|
|
|
|
@gem_with_lib = Rails::GemDependency.new "xaws-s3x", :lib => "aws/s3"
|
|
|
|
@gem_without_load = Rails::GemDependency.new "xhpricotx", :lib => false
|
|
|
|
end
|
2008-03-29 22:17:28 -04:00
|
|
|
|
2009-02-03 21:25:37 -05:00
|
|
|
def test_configuration_adds_gem_dependency
|
|
|
|
config = Rails::Configuration.new
|
|
|
|
config.gem "xaws-s3x", :lib => "aws/s3", :version => "0.4.0"
|
2009-04-22 22:52:28 -04:00
|
|
|
assert_equal [["install", "xaws-s3x", "--version", '"= 0.4.0"']], config.gems.collect { |g| g.install_command }
|
2009-02-03 21:25:37 -05:00
|
|
|
end
|
2008-03-29 22:17:28 -04:00
|
|
|
|
2009-02-03 21:25:37 -05:00
|
|
|
def test_gem_creates_install_command
|
|
|
|
assert_equal %w(install xhpricotx), @gem.install_command
|
|
|
|
end
|
2008-03-29 22:17:28 -04:00
|
|
|
|
2009-02-03 21:25:37 -05:00
|
|
|
def test_gem_with_source_creates_install_command
|
|
|
|
assert_equal %w(install xhpricotx --source http://code.whytheluckystiff.net), @gem_with_source.install_command
|
|
|
|
end
|
2008-03-29 22:17:28 -04:00
|
|
|
|
2009-02-03 21:25:37 -05:00
|
|
|
def test_gem_with_version_creates_install_command
|
|
|
|
assert_equal ["install", "xhpricotx", "--version", '"= 0.6"'], @gem_with_version.install_command
|
|
|
|
end
|
2008-03-29 22:17:28 -04:00
|
|
|
|
2009-02-03 21:25:37 -05:00
|
|
|
def test_gem_creates_unpack_command
|
|
|
|
assert_equal %w(unpack xhpricotx), @gem.unpack_command
|
|
|
|
end
|
2008-03-29 22:17:28 -04:00
|
|
|
|
2009-02-03 21:25:37 -05:00
|
|
|
def test_gem_with_version_unpack_install_command
|
|
|
|
# stub out specification method, or else test will fail if hpricot 0.6 isn't installed
|
|
|
|
mock_spec = mock()
|
|
|
|
mock_spec.stubs(:version).returns('0.6')
|
|
|
|
@gem_with_version.stubs(:specification).returns(mock_spec)
|
|
|
|
assert_equal ["unpack", "xhpricotx", "--version", '= 0.6'], @gem_with_version.unpack_command
|
|
|
|
end
|
2008-03-29 22:17:28 -04:00
|
|
|
|
2009-02-03 21:25:37 -05:00
|
|
|
def test_gem_adds_load_paths
|
2009-03-13 06:20:23 -04:00
|
|
|
@gem.expects(:gem).with(@gem)
|
2009-02-03 21:25:37 -05:00
|
|
|
@gem.add_load_paths
|
|
|
|
end
|
2008-06-02 10:54:36 -04:00
|
|
|
|
2009-02-03 21:25:37 -05:00
|
|
|
def test_gem_with_version_adds_load_paths
|
2009-03-13 06:20:23 -04:00
|
|
|
@gem_with_version.expects(:gem).with(@gem_with_version)
|
2009-02-03 21:25:37 -05:00
|
|
|
@gem_with_version.add_load_paths
|
2009-03-13 06:20:23 -04:00
|
|
|
assert @gem_with_version.load_paths_added?
|
2009-02-03 21:25:37 -05:00
|
|
|
end
|
2008-06-02 10:54:36 -04:00
|
|
|
|
2009-02-03 21:25:37 -05:00
|
|
|
def test_gem_loading
|
2009-03-13 06:20:23 -04:00
|
|
|
@gem.expects(:gem).with(@gem)
|
2009-02-03 21:25:37 -05:00
|
|
|
@gem.expects(:require).with(@gem.name)
|
|
|
|
@gem.add_load_paths
|
|
|
|
@gem.load
|
2009-03-13 06:20:23 -04:00
|
|
|
assert @gem.loaded?
|
2009-02-03 21:25:37 -05:00
|
|
|
end
|
2008-06-02 10:54:36 -04:00
|
|
|
|
2009-02-03 21:25:37 -05:00
|
|
|
def test_gem_with_lib_loading
|
2009-03-13 06:20:23 -04:00
|
|
|
@gem_with_lib.expects(:gem).with(@gem_with_lib)
|
2009-02-03 21:25:37 -05:00
|
|
|
@gem_with_lib.expects(:require).with(@gem_with_lib.lib)
|
|
|
|
@gem_with_lib.add_load_paths
|
|
|
|
@gem_with_lib.load
|
2009-03-13 06:20:23 -04:00
|
|
|
assert @gem_with_lib.loaded?
|
2009-02-03 21:25:37 -05:00
|
|
|
end
|
2008-08-01 20:01:10 -04:00
|
|
|
|
2009-02-03 21:25:37 -05:00
|
|
|
def test_gem_without_lib_loading
|
2009-03-13 06:20:23 -04:00
|
|
|
@gem_without_load.expects(:gem).with(@gem_without_load)
|
2009-02-03 21:25:37 -05:00
|
|
|
@gem_without_load.expects(:require).with(@gem_without_load.lib).never
|
|
|
|
@gem_without_load.add_load_paths
|
|
|
|
@gem_without_load.load
|
|
|
|
end
|
2008-08-01 20:01:10 -04:00
|
|
|
|
2009-02-03 21:25:37 -05:00
|
|
|
def test_gem_dependencies_compare_for_uniq
|
|
|
|
gem1 = Rails::GemDependency.new "gem1"
|
|
|
|
gem1a = Rails::GemDependency.new "gem1"
|
|
|
|
gem2 = Rails::GemDependency.new "gem2"
|
|
|
|
gem2a = Rails::GemDependency.new "gem2"
|
|
|
|
gem3 = Rails::GemDependency.new "gem2", :version => ">=0.1"
|
|
|
|
gem3a = Rails::GemDependency.new "gem2", :version => ">=0.1"
|
|
|
|
gem4 = Rails::GemDependency.new "gem3"
|
|
|
|
gems = [gem1, gem2, gem1a, gem3, gem2a, gem4, gem3a, gem2, gem4]
|
|
|
|
assert_equal 4, gems.uniq.size
|
|
|
|
end
|
Fix a number of errors in the config.gem mechanism.
* Rails::GemDependency was missing definitions for hash and eql?, causing Array#uniq to not work.
* If several versions of a gem are unpacked in vendor, now chooses the highest if no version is specified.
* streamlined add_load_path. Now sets up Rubygems correctly to allow 'gem' to find frozen gems, with
gems frozen to vendor/gems and specifications in vendor/gems/<gem-name>/.specification
* Rails::GemDependency#specification would return a spec for the highest installed version, even for
frozen gems and/or previously loaded lower versions. See in part ticket #1123.
* removed vendor from default_load_paths - it was causing autoloading to append Gems::Gems::<gem-dir> to
constant names
* added additional tests for loading frozen gems.
* incorporates the fix from #1107 for vendor rails
* defers to freeze:gems for handling the Rails framework. gems:unpack WILL NOT place a copy of Rails
in vendor/gems. Should close #1123 completely.
* incorporates, via using the gem loader for frozen gems, fixes corresponding to #227, #324, #362, #527, and #742.
* gem plugins now work the same whether frozen or not. Correctness of the behavior is a matter for another ticket...
Signed-off-by: rick <technoweenie@gmail.com>
2008-10-04 13:51:23 -04:00
|
|
|
|
2009-02-03 21:25:37 -05:00
|
|
|
def test_gem_load_frozen
|
|
|
|
dummy_gem = Rails::GemDependency.new "dummy-gem-a"
|
|
|
|
dummy_gem.add_load_paths
|
|
|
|
dummy_gem.load
|
|
|
|
assert_not_nil DUMMY_GEM_A_VERSION
|
|
|
|
end
|
Fix a number of errors in the config.gem mechanism.
* Rails::GemDependency was missing definitions for hash and eql?, causing Array#uniq to not work.
* If several versions of a gem are unpacked in vendor, now chooses the highest if no version is specified.
* streamlined add_load_path. Now sets up Rubygems correctly to allow 'gem' to find frozen gems, with
gems frozen to vendor/gems and specifications in vendor/gems/<gem-name>/.specification
* Rails::GemDependency#specification would return a spec for the highest installed version, even for
frozen gems and/or previously loaded lower versions. See in part ticket #1123.
* removed vendor from default_load_paths - it was causing autoloading to append Gems::Gems::<gem-dir> to
constant names
* added additional tests for loading frozen gems.
* incorporates the fix from #1107 for vendor rails
* defers to freeze:gems for handling the Rails framework. gems:unpack WILL NOT place a copy of Rails
in vendor/gems. Should close #1123 completely.
* incorporates, via using the gem loader for frozen gems, fixes corresponding to #227, #324, #362, #527, and #742.
* gem plugins now work the same whether frozen or not. Correctness of the behavior is a matter for another ticket...
Signed-off-by: rick <technoweenie@gmail.com>
2008-10-04 13:51:23 -04:00
|
|
|
|
2009-02-03 21:25:37 -05:00
|
|
|
def test_gem_load_frozen_specific_version
|
|
|
|
dummy_gem = Rails::GemDependency.new "dummy-gem-b", :version => '0.4.0'
|
|
|
|
dummy_gem.add_load_paths
|
|
|
|
dummy_gem.load
|
|
|
|
assert_not_nil DUMMY_GEM_B_VERSION
|
|
|
|
assert_equal '0.4.0', DUMMY_GEM_B_VERSION
|
|
|
|
end
|
Fix a number of errors in the config.gem mechanism.
* Rails::GemDependency was missing definitions for hash and eql?, causing Array#uniq to not work.
* If several versions of a gem are unpacked in vendor, now chooses the highest if no version is specified.
* streamlined add_load_path. Now sets up Rubygems correctly to allow 'gem' to find frozen gems, with
gems frozen to vendor/gems and specifications in vendor/gems/<gem-name>/.specification
* Rails::GemDependency#specification would return a spec for the highest installed version, even for
frozen gems and/or previously loaded lower versions. See in part ticket #1123.
* removed vendor from default_load_paths - it was causing autoloading to append Gems::Gems::<gem-dir> to
constant names
* added additional tests for loading frozen gems.
* incorporates the fix from #1107 for vendor rails
* defers to freeze:gems for handling the Rails framework. gems:unpack WILL NOT place a copy of Rails
in vendor/gems. Should close #1123 completely.
* incorporates, via using the gem loader for frozen gems, fixes corresponding to #227, #324, #362, #527, and #742.
* gem plugins now work the same whether frozen or not. Correctness of the behavior is a matter for another ticket...
Signed-off-by: rick <technoweenie@gmail.com>
2008-10-04 13:51:23 -04:00
|
|
|
|
2009-02-03 21:25:37 -05:00
|
|
|
def test_gem_load_frozen_minimum_version
|
|
|
|
dummy_gem = Rails::GemDependency.new "dummy-gem-c", :version => '>=0.5.0'
|
|
|
|
dummy_gem.add_load_paths
|
|
|
|
dummy_gem.load
|
|
|
|
assert_not_nil DUMMY_GEM_C_VERSION
|
|
|
|
assert_equal '0.6.0', DUMMY_GEM_C_VERSION
|
|
|
|
end
|
Fix a number of errors in the config.gem mechanism.
* Rails::GemDependency was missing definitions for hash and eql?, causing Array#uniq to not work.
* If several versions of a gem are unpacked in vendor, now chooses the highest if no version is specified.
* streamlined add_load_path. Now sets up Rubygems correctly to allow 'gem' to find frozen gems, with
gems frozen to vendor/gems and specifications in vendor/gems/<gem-name>/.specification
* Rails::GemDependency#specification would return a spec for the highest installed version, even for
frozen gems and/or previously loaded lower versions. See in part ticket #1123.
* removed vendor from default_load_paths - it was causing autoloading to append Gems::Gems::<gem-dir> to
constant names
* added additional tests for loading frozen gems.
* incorporates the fix from #1107 for vendor rails
* defers to freeze:gems for handling the Rails framework. gems:unpack WILL NOT place a copy of Rails
in vendor/gems. Should close #1123 completely.
* incorporates, via using the gem loader for frozen gems, fixes corresponding to #227, #324, #362, #527, and #742.
* gem plugins now work the same whether frozen or not. Correctness of the behavior is a matter for another ticket...
Signed-off-by: rick <technoweenie@gmail.com>
2008-10-04 13:51:23 -04:00
|
|
|
|
2009-02-03 21:25:37 -05:00
|
|
|
def test_gem_load_missing_specification
|
|
|
|
dummy_gem = Rails::GemDependency.new "dummy-gem-d"
|
|
|
|
dummy_gem.add_load_paths
|
|
|
|
dummy_gem.load
|
|
|
|
assert_not_nil DUMMY_GEM_D_VERSION
|
|
|
|
assert_equal '1.0.0', DUMMY_GEM_D_VERSION
|
|
|
|
assert_equal ['lib', 'lib/dummy-gem-d.rb'], dummy_gem.specification.files
|
|
|
|
end
|
2008-10-11 13:54:21 -04:00
|
|
|
|
2009-02-03 21:25:37 -05:00
|
|
|
def test_gem_load_bad_specification
|
|
|
|
dummy_gem = Rails::GemDependency.new "dummy-gem-e", :version => "= 1.0.0"
|
|
|
|
dummy_gem.add_load_paths
|
|
|
|
dummy_gem.load
|
|
|
|
assert_not_nil DUMMY_GEM_E_VERSION
|
|
|
|
assert_equal '1.0.0', DUMMY_GEM_E_VERSION
|
|
|
|
end
|
2008-10-11 13:54:21 -04:00
|
|
|
|
2009-02-03 21:25:37 -05:00
|
|
|
def test_gem_handle_missing_dependencies
|
|
|
|
dummy_gem = Rails::GemDependency.new "dummy-gem-g"
|
|
|
|
dummy_gem.add_load_paths
|
|
|
|
dummy_gem.load
|
2009-03-13 06:20:23 -04:00
|
|
|
assert_equal 1, dummy_gem.dependencies.size
|
|
|
|
assert_equal 1, dummy_gem.dependencies.first.dependencies.size
|
2009-02-03 21:25:37 -05:00
|
|
|
assert_nothing_raised do
|
|
|
|
dummy_gem.dependencies.each do |g|
|
|
|
|
g.dependencies
|
2008-11-24 23:07:12 -05:00
|
|
|
end
|
|
|
|
end
|
2008-03-29 22:17:28 -04:00
|
|
|
end
|
2009-02-03 21:25:37 -05:00
|
|
|
|
2009-04-29 10:04:17 -04:00
|
|
|
def test_gem_ignores_development_dependencies
|
|
|
|
dummy_gem = Rails::GemDependency.new "dummy-gem-k"
|
|
|
|
dummy_gem.add_load_paths
|
|
|
|
dummy_gem.load
|
|
|
|
assert_equal 1, dummy_gem.dependencies.size
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_gem_guards_against_duplicate_unpacks
|
|
|
|
dummy_gem = Rails::GemDependency.new "dummy-gem-a"
|
|
|
|
dummy_gem.stubs(:frozen?).returns(true)
|
|
|
|
dummy_gem.expects(:unpack_base).never
|
|
|
|
dummy_gem.unpack
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_gem_does_not_unpack_framework_gems
|
|
|
|
dummy_gem = Rails::GemDependency.new "dummy-gem-a"
|
|
|
|
dummy_gem.stubs(:framework_gem?).returns(true)
|
|
|
|
dummy_gem.expects(:unpack_base).never
|
|
|
|
dummy_gem.unpack
|
|
|
|
end
|
|
|
|
|
2009-06-06 17:59:33 -04:00
|
|
|
def test_gem_from_directory_name_attempts_to_load_specification
|
|
|
|
assert_raises RuntimeError do
|
|
|
|
dummy_gem = Rails::GemDependency.from_directory_name('dummy-gem-1.1')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-04-29 01:22:54 -04:00
|
|
|
def test_gem_from_directory_name
|
2009-06-06 17:59:33 -04:00
|
|
|
dummy_gem = Rails::GemDependency.from_directory_name('dummy-gem-1.1', false)
|
2009-04-29 01:22:54 -04:00
|
|
|
assert_equal 'dummy-gem', dummy_gem.name
|
|
|
|
assert_equal '= 1.1', dummy_gem.version_requirements.to_s
|
|
|
|
end
|
|
|
|
|
2009-06-09 12:26:52 -04:00
|
|
|
def test_gem_from_directory_name_loads_specification_successfully
|
|
|
|
assert_nothing_raised do
|
|
|
|
dummy_gem = Rails::GemDependency.from_directory_name(File.join(Rails::GemDependency.unpacked_path, 'dummy-gem-g-1.0.0'))
|
|
|
|
assert_not_nil dummy_gem.specification
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-04-29 01:22:54 -04:00
|
|
|
def test_gem_from_invalid_directory_name
|
|
|
|
assert_raises RuntimeError do
|
|
|
|
dummy_gem = Rails::GemDependency.from_directory_name('dummy-gem')
|
|
|
|
end
|
|
|
|
assert_raises RuntimeError do
|
|
|
|
dummy_gem = Rails::GemDependency.from_directory_name('dummy')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_gem_determines_build_status
|
|
|
|
assert_equal true, Rails::GemDependency.new("dummy-gem-a").built?
|
|
|
|
assert_equal true, Rails::GemDependency.new("dummy-gem-i").built?
|
|
|
|
assert_equal false, Rails::GemDependency.new("dummy-gem-j").built?
|
|
|
|
end
|
2009-06-30 08:58:35 -04:00
|
|
|
|
|
|
|
def test_gem_determines_build_status_only_on_vendor_gems
|
|
|
|
framework_gem = Rails::GemDependency.new('dummy-framework-gem')
|
|
|
|
framework_gem.stubs(:framework_gem?).returns(true) # already loaded
|
|
|
|
framework_gem.stubs(:vendor_rails?).returns(false) # but not in vendor/rails
|
|
|
|
framework_gem.stubs(:vendor_gem?).returns(false) # and not in vendor/gems
|
|
|
|
framework_gem.add_load_paths # freeze framework gem early
|
|
|
|
assert framework_gem.built?
|
|
|
|
end
|
2009-04-29 01:22:54 -04:00
|
|
|
|
2009-06-06 17:59:33 -04:00
|
|
|
def test_gem_build_passes_options_to_dependencies
|
|
|
|
start_gem = Rails::GemDependency.new("dummy-gem-g")
|
|
|
|
dep_gem = Rails::GemDependency.new("dummy-gem-f")
|
|
|
|
start_gem.stubs(:dependencies).returns([dep_gem])
|
|
|
|
dep_gem.expects(:build).with({ :force => true }).once
|
|
|
|
start_gem.build(:force => true)
|
|
|
|
end
|
|
|
|
|
2008-06-02 10:54:36 -04:00
|
|
|
end
|