diff --git a/lib/sashimi/repositories/abstract_repository.rb b/lib/sashimi/repositories/abstract_repository.rb index f303172..9ad6fda 100644 --- a/lib/sashimi/repositories/abstract_repository.rb +++ b/lib/sashimi/repositories/abstract_repository.rb @@ -117,7 +117,7 @@ def scm_remove(file) # Execute the given command for the current SCM system used by the Rails app. def scm_command(command, file) scm = guess_version_control_system - system("#{scm} #{command} #{file}") + Kernel.system("#{scm} #{command} #{file}") end def local_repository_path #:nodoc: diff --git a/test/test_helper.rb b/test/test_helper.rb index 92a038c..9b7634e 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -68,10 +68,10 @@ def create_plugin(name, url = nil) Plugin.new(name, url) end - def cached_plugin - { 'sashimi' => {'type' => 'git'}, + def cached_plugins + { 'plug-in' => {'type' => 'svn'}, 'plugin' => {'type' => 'svn'}, - 'plug-in' => {'type' => 'svn'} } + 'sashimi' => {'type' => 'git'} } end def cache_file @@ -100,7 +100,7 @@ def prepare_installation end def create_cache_file - File.open(cache_file, 'w+'){|f| f.write(cached_plugin.to_yaml)} + File.open(cache_file, 'w+'){|f| f.write(cached_plugins.to_yaml)} end def with_local_repository_path(&block) diff --git a/test/unit/repositories/abstract_repository_test.rb b/test/unit/repositories/abstract_repository_test.rb index 071eb5b..656b807 100644 --- a/test/unit/repositories/abstract_repository_test.rb +++ b/test/unit/repositories/abstract_repository_test.rb @@ -16,6 +16,10 @@ 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 + ### COMMANDS # ADD @@ -48,4 +52,84 @@ def test_should_raise_exception_on_uninstalling_missing_plugin 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 + 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 end