sashimi 0.1.7 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,137 +2,312 @@ require 'test/unit'
2
2
  require 'test/test_helper'
3
3
 
4
4
  class AbstractRepositoryTest < Test::Unit::TestCase
5
+ include Sashimi
6
+
5
7
  def test_initialize
6
- assert repository
7
- assert repository.plugin.name
8
- assert repository.plugin.url
8
+ assert repository.plugin
9
9
  end
10
10
 
11
- # CLASS CONSTANTS
12
- def test_local_repository_path
13
- assert_match(/\.rails\/plugins$/, repository.local_repository_path)
11
+ def test_plugins_path
12
+ assert_equal 'sashimi_test/.rails/plugins', repository.class.plugins_path
14
13
  end
15
14
 
16
15
  def test_cache_file
17
- assert_equal(".plugins", repository.cache_file)
16
+ assert_equal cache_file, repository.class.cache_file
18
17
  end
19
-
20
- def test_plugins_dir
21
- assert_equal('vendor/plugins', repository.plugins_dir)
18
+
19
+ def test_plugins_names
20
+ assert_equal cached_plugins.keys.sort, repository.class.plugins_names
22
21
  end
23
-
24
- # INSTANTIATE
22
+
23
+ def test_temp_suffix
24
+ assert_equal '-tmp', AbstractRepository::TEMP_SUFFIX
25
+ end
26
+
27
+ ### INSTANTIATE
28
+
29
+ def test_instantiate_repository
30
+ assert_kind_of GitRepository, repository.class.instantiate_repository(plugin)
31
+ assert_kind_of GitRepository, repository.class.instantiate_repository(create_plugin('sashimi', plugin.url))
32
+ end
33
+
25
34
  def test_should_instantiate_repository_by_url
26
- assert_kind_of(SvnRepository, AbstractRepository.instantiate_repository(create_plugin(nil, 'http://svn.com')))
27
- assert_kind_of(GitRepository, AbstractRepository.instantiate_repository(plugin))
35
+ assert_equal SvnRepository, AbstractRepository.instantiate_repository_by_url(create_plugin(nil, 'http://svn.com'))
36
+ assert_equal GitRepository, AbstractRepository.instantiate_repository_by_url(plugin)
28
37
  end
29
38
 
30
39
  def test_should_instantiate_repository_by_cache
31
- initialize_repository_for_test do
32
- assert AbstractRepository.instantiate_repository(create_plugin('sashimi', ''))
40
+ assert repository.class.instantiate_repository_by_cache(create_plugin('sashimi', plugin.url))
41
+ end
42
+
43
+ ### COMMANDS
44
+
45
+ # ADD
46
+ def test_should_add_plugin_to_rails_app
47
+ with_path rails_app_path do
48
+ repository.add
49
+ assert_path_exists "vendor/plugins/#{repository.plugin.name}"
33
50
  end
34
51
  end
35
52
 
36
- def test_should_recognize_git_url
37
- assert AbstractRepository.git_url?('git://github.com/jodosha/sashimi.git')
53
+ def test_should_raise_exception_on_adding_missing_plugin
54
+ with_path rails_app_path do
55
+ assert_raise PluginNotFound do
56
+ create_repository('unexistent').add
57
+ end
58
+ end
38
59
  end
39
60
 
40
- # COMMANDS
41
- def test_should_list_all_installed_plugins
42
- initialize_repository_for_test do
43
- assert_equal("plug-in\t\t\nplugin\t\t\nsashimi\t\t", AbstractRepository.list)
61
+ # UNINSTALL
62
+ def test_should_uninstall_plugin_from_repository
63
+ repository.uninstall
64
+ with_path plugins_path do
65
+ assert_path_not_exists repository.plugin.name
44
66
  end
67
+ assert_not repository.class.plugins_names.include?(repository.plugin.name)
45
68
  end
46
69
 
47
- def test_should_return_all_installed_plugins_names
48
- initialize_repository_for_test do
49
- assert_equal(['plug-in', 'plugin'], AbstractRepository.plugins_names)
70
+ def test_should_raise_exception_on_uninstalling_missing_plugin
71
+ assert_raise PluginNotFound do
72
+ create_repository('unexistent').uninstall
50
73
  end
51
74
  end
52
75
 
53
- # DIRECTORIES
54
- def test_should_change_current_dir
55
- repository.change_dir(repository.class.find_home)
56
- assert_equal(repository.class.find_home, Dir.pwd)
76
+ # LIST
77
+ def test_should_list_installed_plugins
78
+ assert_equal cached_plugins, repository.class.list
57
79
  end
80
+
81
+ ### SCM
58
82
 
59
- def test_should_change_current_dir_with_local_repository_path
60
- initialize_repository_for_test do
61
- repository.change_dir_to_local_repository
62
- assert_equal(repository.local_repository_path, Dir.pwd)
83
+ uses_mocha 'AbstractRepositoryTestSCM' do
84
+ def test_guess_version_control_system
85
+ File.expects(:exists?).with('.git').returns true
86
+ assert_equal :git, repository.class.guess_version_control_system
87
+
88
+ File.expects(:exists?).with('.git').returns false
89
+ assert_equal :svn, repository.class.guess_version_control_system
90
+ end
91
+
92
+ def test_scm_command
93
+ File.stubs(:exists?).with('.git').returns true
94
+ Kernel.expects(:system).with('git add file.rb')
95
+ repository.class.scm_command('add', 'file.rb')
63
96
  end
97
+
98
+ def test_scm_add
99
+ File.stubs(:exists?).with('.git').returns true
100
+ Kernel.expects(:system).with('git add file.rb')
101
+ repository.class.scm_add('file.rb')
102
+ end
103
+
104
+ def test_scm_remove
105
+ File.stubs(:exists?).with('.git').returns true
106
+ Kernel.expects(:system).with('git rm file.rb')
107
+ repository.class.scm_remove('file.rb')
108
+ end
109
+
110
+ def test_under_version_control
111
+ Dir.expects(:glob).with(".{git,svn}").returns %w(.git)
112
+ assert repository.class.under_version_control?
113
+ end
64
114
  end
65
115
 
66
- def test_should_change_current_dir_with_plugin_cache_path
67
- initialize_repository_for_test do
68
- FileUtils.mkdir_p(cached_plugin_path)
69
- repository.change_dir_to_plugin_path
70
- assert_equal(cached_plugin_path, Dir.pwd)
116
+ def test_git_url
117
+ assert repository.class.git_url?(plugin.url)
118
+ assert repository.class.git_url?(plugin.url.gsub('git:', 'http:'))
119
+ assert_not repository.class.git_url?('http://repository.com/plugin/trunk')
120
+ end
121
+
122
+ ### PATH
123
+
124
+ uses_mocha 'AbstractRepositoryTestPath' do
125
+ def test_local_repository_path
126
+ AbstractRepository.expects(:find_home).returns '/Users/luca'
127
+ File.stubs(:SEPARATOR).returns '/'
128
+ expected = [ repository.class.find_home, repository.class.plugins_path ].to_path
129
+ assert_equal expected, repository.local_repository_path
130
+ end
131
+
132
+ def _ignore_test_find_home
133
+ flunk
134
+ end
135
+
136
+ def test_with_path
137
+ old_path = Dir.pwd
138
+ repository.with_path 'test' do
139
+ assert_equal [old_path, 'test'].to_path, Dir.pwd
140
+ end
141
+ assert_equal old_path, Dir.pwd
71
142
  end
72
143
  end
73
144
 
74
- def _ignore_test_should_copy_plugin_to_a_rails_app
75
- initialize_repository_for_test do
76
- repository.change_dir_to_local_repository
77
- create_repository('plugin', '').copy_plugin_to_rails_app
78
- assert File.exists?(File.join('vendor', 'plugins', 'plugin', 'about.yml'))
145
+ def test_path_to_rails_app
146
+ with_path rails_app_path do
147
+ assert_equal Dir.pwd, repository.class.path_to_rails_app
79
148
  end
80
149
  end
81
150
 
82
- # REPOSITORY
83
- def test_should_prepare_installation
84
- initialize_repository_for_test do
85
- assert File.exists?(repository.local_repository_path)
86
- assert_equal(repository.local_repository_path, Dir.pwd)
87
- assert File.exists?(repository.cache_file)
151
+ def test_absolute_rails_plugins_path
152
+ with_path rails_app_path do
153
+ expected = "#{Dir.pwd}/vendor/plugins".to_path
154
+ assert_equal expected, repository.class.absolute_rails_plugins_path
88
155
  end
89
156
  end
157
+
158
+ def test_rails_plugins_path
159
+ assert_equal 'vendor/plugins'.to_path, repository.class.rails_plugins_path
160
+ end
161
+
162
+ def test_plugin_path
163
+ expected = [ plugins_path, repository.plugin.name ].to_path
164
+ assert_equal expected, repository.plugin_path
165
+ end
166
+
167
+ ### FILES
168
+
169
+ uses_mocha 'AbstractRepositoryTestFile' do
170
+ def _ignore_test_copy_plugin_and_remove_hidden_folders
171
+ flunk
172
+ end
173
+
174
+ def test_update_rails_plugins
175
+ AbstractRepository.expects(:under_version_control?).returns true
176
+ AbstractRepository.expects(:update_versioned_rails_plugins)
177
+ AbstractRepository.update_rails_plugins plugin.name
178
+
179
+ AbstractRepository.expects(:under_version_control?).returns false
180
+ AbstractRepository.expects(:update_unversioned_rails_plugins)
181
+ AbstractRepository.update_rails_plugins plugin.name
182
+ end
183
+
184
+ def _ignore_test_update_unversioned_rails_plugins
185
+ FileUtils.stubs(:rm_rf) # because of teardown
186
+ FileUtils.expects(:rm_rf).with 'sashimi'
187
+ FileUtils.stubs(:cd)
188
+ AbstractRepository.expects(:instantiate_repository_by_cache).returns GitRepository
189
+ GitRepository.stubs(:cache_content).returns({ 'sashimi' => nil })
190
+ Plugin.expects(:add)
191
+ FileUtils.expects(:cp_r).with [ plugins_path, repository.plugin.name ].to_path,
192
+ [ repository.class.rails_plugins_path, repository.temp_plugin_name ].to_path
193
+ FileUtils.expects(:mv).with [ repository.rails_plugins_path, repository.temp_plugin_name ].to_path,
194
+ [ repository.rails_plugins_path, repository.plugin.name ].to_path
195
+
196
+ AbstractRepository.update_unversioned_rails_plugins 'sashimi'
197
+ end
198
+
199
+ def _ignore_test_update_versioned_rails_plugins
200
+ flunk
201
+ end
202
+
203
+ def _ignore_test_files_scheduled_for_add
204
+ flunk
205
+ end
206
+
207
+ def _ignore_test_files_scheduled_for_remove
208
+ flunk
209
+ end
210
+
211
+ def test_remove_temp_folder
212
+ with_path rails_app_path do
213
+ FileUtils.expects(:rm_rf).with [ repository.absolute_rails_plugins_path,
214
+ repository.temp_plugin_name].to_path
215
+ repository.remove_temp_folder
216
+ FileUtils.stubs(:rm_rf) # because of teardown
217
+ end
218
+ end
219
+
220
+ def test_prepare_installation
221
+ FileUtils.expects(:mkdir_p).with repository.local_repository_path
222
+ FileUtils.expects(:touch).with [ repository.local_repository_path, cache_file ].to_path
223
+ repository.prepare_installation
224
+ end
90
225
 
91
- # CACHE
92
- def test_should_read_cache_content
93
- initialize_repository_for_test do
94
- assert_equal(cache_content, repository.cache_content)
226
+ def test_copy_plugin_to_rails_app
227
+ FileUtils.expects(:mkdir_p).with repository.absolute_rails_plugins_path
228
+ FileUtils.expects(:cp_r).with [ repository.local_repository_path, repository.plugin.name ].to_path,
229
+ [ repository.absolute_rails_plugins_path, repository.temp_plugin_name ].to_path
230
+ repository.copy_plugin_to_rails_app
95
231
  end
96
232
  end
233
+
234
+ def _ignore_test_remove_hidden_folders
235
+ flunk
236
+ end
237
+
238
+ ### CACHE
239
+
240
+ def test_cache_content
241
+ assert_equal cached_plugins, repository.class.cache_content
242
+ end
97
243
 
98
- def test_should_add_plugin_to_the_cache
99
- initialize_repository_for_test do
100
- expected = cache_content.merge(cached_plugin)
101
- repository.add_to_cache(cached_plugin)
102
- assert_equal expected, cache_content
244
+ def test_should_add_a_new_plugin_to_cache
245
+ with_clear_cache do
246
+ with_path local_repository_path do
247
+ create_plugin_directory('brand_new')
248
+ plugin = create_plugin(nil, 'git://github.com/jodosha/brand_new.git')
249
+ repository.add_to_cache(plugin)
250
+ assert_equal cached_plugins.merge(plugin.to_hash), repository.class.cache_content
251
+ end
103
252
  end
104
253
  end
105
254
 
106
- def test_should_remove_plugin_from_cache
107
- initialize_repository_for_test do
108
- AbstractRepository.new(create_plugin('sashimi', '')).remove_from_cache
109
- assert_equal({"plugin"=>{"type"=>"svn"}, "plug-in"=>{"type"=>"svn"}}, cache_content)
255
+ def test_should_merge_an_existent_plugin_into_cache
256
+ with_clear_cache do
257
+ with_path local_repository_path do
258
+ repository.add_to_cache(plugin)
259
+ assert_equal cached_plugins.merge(plugin.to_hash), repository.class.cache_content
260
+ end
110
261
  end
111
262
  end
112
263
 
113
- # ABOUT
114
- def test_should_return_about_contents_from_about_yml
115
- initialize_repository_for_test do
116
- plugin = create_plugin('plugin', 'http://dev.repository.com/svn/plugin/trunk')
117
- assert_equal({'summary' => "Plugin summary"}, plugin.about)
264
+ def test_remove_from_cache
265
+ with_clear_cache do
266
+ with_path local_repository_path do
267
+ repository.remove_from_cache
268
+ assert_not repository.class.plugins_names.include?(plugin.name)
269
+ end
118
270
  end
119
271
  end
120
272
 
121
- def test_should_return_empty_hash_for_unexstistent_about_yml
122
- initialize_repository_for_test do
123
-
124
- plugin = create_plugin('plug-in', 'http://dev.repository.com/svn/plug-in/trunk')
125
- assert_equal({}, plugin.about)
273
+ def test_write_to_cache
274
+ with_clear_cache do
275
+ with_path plugins_path do
276
+ repository.write_to_cache(plugin.to_hash)
277
+ assert_equal plugin.to_hash, repository.class.cache_content
278
+ end
126
279
  end
127
280
  end
128
281
 
129
- private
130
- def cache_content
131
- FileUtils.cd(repository.local_repository_path)
132
- YAML::load_file(repository.cache_file).to_hash
282
+ ### OTHER
283
+
284
+ def test_should_load_about_yml
285
+ assert_not_empty repository.about.keys
133
286
  end
134
-
135
- def cached_plugin_path
136
- File.join(repository.local_repository_path, 'sashimi')
287
+
288
+ def test_should_return_empty_hash_for_unexistent_about_yml
289
+ assert_nothing_raised Exception do
290
+ assert_empty create_repository('plug-in').about.keys
291
+ end
292
+ end
293
+
294
+ def test_temp_plugin_name
295
+ assert_equal repository.plugin.name + AbstractRepository::TEMP_SUFFIX,
296
+ repository.temp_plugin_name
297
+ end
298
+
299
+ uses_mocha 'AbstractRepositoryTestOther' do
300
+ def test_should_run_install_hook
301
+ File.expects(:exists?).returns true
302
+ Kernel.expects(:load)
303
+ repository.run_install_hook
304
+ end
305
+
306
+ def test_should_not_raise_exception_running_install_hook_with_missing_file
307
+ assert_nothing_raised Exception do
308
+ Kernel.expects(:load).never
309
+ create_repository('plug-in').run_install_hook
310
+ end
311
+ end
137
312
  end
138
313
  end
@@ -20,7 +20,7 @@ class GitRepositoryTest < Test::Unit::TestCase
20
20
  end
21
21
 
22
22
  def test_should_create_git_repository
23
- initialize_repository_for_test do
23
+ repository.with_path plugins_path do
24
24
  FileUtils.mkdir_p('sashimi')
25
25
  Kernel.expects(:system).with('git clone git://github.com/jodosha/sashimi.git')
26
26
  GitRepository.new(plugin).install
@@ -19,8 +19,8 @@ class SvnRepositoryTest < Test::Unit::TestCase
19
19
  assert_raise(Errno::ENOENT) { repository.install }
20
20
  end
21
21
 
22
- def test_should_create_git_repository
23
- initialize_repository_for_test do
22
+ def test_should_create_svn_repository
23
+ repository.with_path plugins_path do
24
24
  FileUtils.mkdir_p('sashimi')
25
25
  Kernel.expects(:system).with('svn co http://dev.repository.com/svn/sashimi/trunk sashimi')
26
26
  SvnRepository.new(create_plugin(nil, 'http://dev.repository.com/svn/sashimi/trunk')).install
@@ -3,6 +3,6 @@ require 'test/test_helper'
3
3
 
4
4
  class VersionTest < Test::Unit::TestCase
5
5
  def test_version
6
- assert_equal '0.1.7', Sashimi::VERSION::STRING
6
+ assert_equal '0.2.0', Sashimi::VERSION::STRING
7
7
  end
8
8
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sashimi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Luca Guidi
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-06-23 00:00:00 +02:00
12
+ date: 2008-07-14 00:00:00 +02:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -39,7 +39,9 @@ files:
39
39
  - lib/sashimi.rb
40
40
  - lib/sashimi/commands.rb
41
41
  - lib/sashimi/core_ext.rb
42
+ - lib/sashimi/core_ext/array.rb
42
43
  - lib/sashimi/core_ext/class.rb
44
+ - lib/sashimi/core_ext/string.rb
43
45
  - lib/sashimi/plugin.rb
44
46
  - lib/sashimi/repositories.rb
45
47
  - lib/sashimi/repositories/abstract_repository.rb
@@ -49,7 +51,9 @@ files:
49
51
  - sashimi.gemspec
50
52
  - setup.rb
51
53
  - test/test_helper.rb
54
+ - test/unit/core_ext/array_test.rb
52
55
  - test/unit/core_ext/class_test.rb
56
+ - test/unit/core_ext/string_test.rb
53
57
  - test/unit/plugin_test.rb
54
58
  - test/unit/repositories/abstract_repository_test.rb
55
59
  - test/unit/repositories/git_repository_test.rb
@@ -82,7 +86,9 @@ signing_key:
82
86
  specification_version: 2
83
87
  summary: Rails plugins manager
84
88
  test_files:
89
+ - test/unit/core_ext/array_test.rb
85
90
  - test/unit/core_ext/class_test.rb
91
+ - test/unit/core_ext/string_test.rb
86
92
  - test/unit/plugin_test.rb
87
93
  - test/unit/repositories/abstract_repository_test.rb
88
94
  - test/unit/repositories/git_repository_test.rb