Skip to content

Commit

Permalink
Improved test coverage for AbstractRepository
Browse files Browse the repository at this point in the history
  • Loading branch information
Luca Guidi committed Jul 10, 2008
1 parent a8a9f75 commit 68ce881
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/sashimi/repositories/abstract_repository.rb
Expand Up @@ -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:
Expand Down
8 changes: 4 additions & 4 deletions test/test_helper.rb
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
84 changes: 84 additions & 0 deletions test/unit/repositories/abstract_repository_test.rb
Expand Up @@ -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
Expand Down Expand Up @@ -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

0 comments on commit 68ce881

Please sign in to comment.