/
abstract_repository_test.rb
260 lines (207 loc) · 6.52 KB
/
abstract_repository_test.rb
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
require 'test/unit'
require 'test/test_helper'
class AbstractRepositoryTest < Test::Unit::TestCase
include Sashimi
def test_initialize
assert repository.plugin
end
def test_plugins_path
assert_equal 'sashimi_test/.rails/plugins', repository.class.plugins_path
end
def test_cache_file
assert_equal cache_file, repository.class.cache_file
end
def test_plugins_names
assert_equal cached_plugins.keys.sort, repository.class.plugins_names
end
def test_temp_suffix
assert_equal '-tmp', AbstractRepository::TEMP_SUFFIX
end
### INSTANTIATE
def test_instantiate_repository
assert_kind_of GitRepository, repository.class.instantiate_repository(plugin)
assert_kind_of GitRepository, repository.class.instantiate_repository(create_plugin('sashimi', plugin.url))
end
def test_should_instantiate_repository_by_url
assert_equal SvnRepository, AbstractRepository.instantiate_repository_by_url(create_plugin(nil, 'http://svn.com'))
assert_equal GitRepository, AbstractRepository.instantiate_repository_by_url(plugin)
end
def test_should_instantiate_repository_by_cache
assert repository.class.instantiate_repository_by_cache(create_plugin('sashimi', plugin.url))
end
### COMMANDS
# ADD
def test_should_add_plugin_to_rails_app
with_path rails_app_path do
repository.add
assert_path_exists "vendor/plugins/#{repository.plugin.name}"
end
end
def test_should_raise_exception_on_adding_missing_plugin
with_path rails_app_path do
assert_raise PluginNotFound do
create_repository('unexistent').add
end
end
end
# UNINSTALL
def test_should_uninstall_plugin_from_repository
repository.uninstall
with_path plugins_path do
assert_path_not_exists repository.plugin.name
end
assert_not repository.class.plugins_names.include?(repository.plugin.name)
end
def test_should_raise_exception_on_uninstalling_missing_plugin
assert_raise PluginNotFound do
create_repository('unexistent').uninstall
end
end
# LIST
# TODO cleanup
def test_should_list_installed_plugins
assert_equal "plug-in\t\t\nplugin\t\t\nsashimi\t\t", repository.class.list
end
### SCM
uses_mocha 'AbstractRepositoryTestSCM' do
def test_guess_version_control_system
File.expects(:exists?).with('.git').returns true
assert_equal :git, repository.class.guess_version_control_system
File.expects(:exists?).with('.git').returns false
assert_equal :svn, repository.class.guess_version_control_system
end
def test_scm_command
File.stubs(:exists?).with('.git').returns true
Kernel.expects(:system).with('git add file.rb')
repository.class.scm_command('add', 'file.rb')
end
def test_scm_add
File.stubs(:exists?).with('.git').returns true
Kernel.expects(:system).with('git add file.rb')
repository.class.scm_add('file.rb')
end
def test_scm_remove
File.stubs(:exists?).with('.git').returns true
Kernel.expects(:system).with('git rm file.rb')
repository.class.scm_remove('file.rb')
end
def test_under_version_control
Dir.expects(:glob).with(".{git,svn}").returns %w(.git)
assert repository.class.under_version_control?
end
end
def test_git_url
assert repository.class.git_url?(plugin.url)
assert repository.class.git_url?(plugin.url.gsub('git:', 'http:'))
assert_not repository.class.git_url?('http://repository.com/plugin/trunk')
end
### PATH
uses_mocha 'AbstractRepositoryTestPath' do
def test_local_repository_path
AbstractRepository.stubs(:find_home).returns '/Users/luca'
File.stubs(:SEPARATOR).returns '/'
expected = [ repository.class.find_home, repository.class.plugins_path ].to_path
assert_equal expected, repository.local_repository_path
end
def test_find_home
flunk
end
def test_with_path
old_path = Dir.pwd
repository.with_path 'test' do
assert_equal [old_path, 'test'].to_path, Dir.pwd
end
assert_equal old_path, Dir.pwd
end
end
def test_path_to_rails_app
with_path rails_app_path do
assert_equal Dir.pwd, repository.class.path_to_rails_app
end
end
def test_absolute_rails_plugins_path
with_path rails_app_path do
expected = "#{Dir.pwd}/vendor/plugins".to_path
assert_equal expected, repository.class.absolute_rails_plugins_path
end
end
def test_rails_plugins_path
assert_equal 'vendor/plugins'.to_path, repository.class.rails_plugins_path
end
def test_plugin_path
expected = [ plugins_path, repository.plugin.name ].to_path
assert_equal expected, repository.plugin_path
end
### FILES
def test_copy_plugin_and_remove_hidden_folders
flunk
end
def test_update_rails_plugins
flunk
end
def test_update_unversioned_rails_plugins
flunk
end
def test_update_versioned_rails_plugins
flunk
end
def test_files_scheduled_for_add
flunk
end
def test_files_scheduled_for_remove
flunk
end
def test_remove_temp_folder
flunk
end
def test_prepare_installation
flunk
end
def test_copy_plugin_to_rails_app
flunk
end
def test_remove_hidden_folders
flunk
end
### CACHE
def test_cache_content
assert_equal cached_plugins, repository.class.cache_content
end
def test_should_add_a_new_plugin_to_cache
with_clear_cache do
create_plugin_directory('brand_new')
plugin = create_plugin(nil, 'git://github.com/jodosha/brand_new.git')
repository.add_to_cache(plugin)
assert_equal cached_plugins.merge(plugin.to_hash), repository.class.cache_content
end
end
def test_should_merge_an_existent_plugin_into_cache
with_clear_cache do
repository.add_to_cache(plugin)
assert_equal cached_plugins.merge(plugin.to_hash), repository.class.cache_content
end
end
def test_remove_from_cache
with_clear_cache do
repository.remove_from_cache
assert_not repository.class.plugins_names.include?(plugin.name)
end
end
def test_write_to_cache
with_clear_cache do
repository.write_to_cache(plugin.to_hash)
assert_equal plugin.to_hash, repository.class.cache_content
end
end
### OTHER
def test_about
flunk
end
def test_temp_plugin_name
assert_equal repository.plugin.name + AbstractRepository::TEMP_SUFFIX,
repository.temp_plugin_name
end
def test_run_install_hook
flunk
end
end