1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
|
require 'plugin_test_helper'
class Rails::GemDependency
public :install_command, :unpack_command
end
Rails::VendorGemSourceIndex.silence_spec_warnings = true
uses_mocha "Plugin Tests" do
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
def test_configuration_adds_gem_dependency
config = Rails::Configuration.new
config.gem "xaws-s3x", :lib => "aws/s3", :version => "0.4.0"
assert_equal [["install", "xaws-s3x", "--version", '"= 0.4.0"']], config.gems.collect(&:install_command)
end
def test_gem_creates_install_command
assert_equal %w(install xhpricotx), @gem.install_command
end
def test_gem_with_source_creates_install_command
assert_equal %w(install xhpricotx --source http://code.whytheluckystiff.net), @gem_with_source.install_command
end
def test_gem_with_version_creates_install_command
assert_equal ["install", "xhpricotx", "--version", '"= 0.6"'], @gem_with_version.install_command
end
def test_gem_creates_unpack_command
assert_equal %w(unpack xhpricotx), @gem.unpack_command
end
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
def test_gem_adds_load_paths
@gem.expects(:gem).with(Gem::Dependency.new(@gem.name, nil))
@gem.add_load_paths
end
def test_gem_with_version_adds_load_paths
@gem_with_version.expects(:gem).with(Gem::Dependency.new(@gem_with_version.name, @gem_with_version.requirement.to_s))
@gem_with_version.add_load_paths
end
def test_gem_loading
@gem.expects(:gem).with(Gem::Dependency.new(@gem.name, nil))
@gem.expects(:require).with(@gem.name)
@gem.add_load_paths
@gem.load
end
def test_gem_with_lib_loading
@gem_with_lib.expects(:gem).with(Gem::Dependency.new(@gem_with_lib.name, nil))
@gem_with_lib.expects(:require).with(@gem_with_lib.lib)
@gem_with_lib.add_load_paths
@gem_with_lib.load
end
def test_gem_without_lib_loading
@gem_without_load.expects(:gem).with(Gem::Dependency.new(@gem_without_load.name, nil))
@gem_without_load.expects(:require).with(@gem_without_load.lib).never
@gem_without_load.add_load_paths
@gem_without_load.load
end
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
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
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
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
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
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
def test_gem_handle_missing_dependencies
dummy_gem = Rails::GemDependency.new "dummy-gem-g"
dummy_gem.add_load_paths
dummy_gem.load
assert dummy_gem.loaded?
assert_equal 2, dummy_gem.dependencies.size
assert_nothing_raised do
dummy_gem.dependencies.each do |g|
g.dependencies
end
end
end
end
end
|