spec/blazing/remote_spec.rb in blazing-0.0.7 vs spec/blazing/remote_spec.rb in blazing-0.0.8
- old
+ new
@@ -2,35 +2,37 @@
require 'blazing/remote'
describe Blazing::Remote do
before :each do
- @remote = Blazing::Remote.new
+ # recipes = []
+ # @config = double('config', :load => double('actual_config', :recipes => recipes, :find_target => double('target', :recipes => recipes)))
+ @config = Blazing::Config.new
+ @config.target :some_name, :deploy_to => 'user@hostname:/path'
+ @remote = Blazing::Remote.new('some_name', :config => @config)
@remote.instance_variable_set('@_dir', double('Dir', :chdir => nil))
end
describe '#post_receive' do
before :each do
- recipes = []
- config = double('config', :load => double('actual_config', :recipes => recipes, :find_target => double('target', :recipes => recipes)))
- @remote.instance_variable_set('@_config', config)
@remote.instance_variable_set('@runner', double('runner', :run => true))
+ Dir.stub!(:chdir)
end
it 'sets up the git dir' do
@remote.should_receive(:set_git_dir)
- @remote.post_receive('sometarget')
+ @remote.post_receive
end
it 'runs the recipes' do
- @remote.should_receive(:setup_and_run_recipes)
- @remote.post_receive('sometarget')
+ @remote.should_receive(:run_recipes)
+ @remote.post_receive
end
it 'resets the git repository' do
@remote.should_receive(:reset_head!)
- @remote.post_receive('sometarget')
+ @remote.post_receive
end
end
describe '#gemfile_present?' do
it 'checks if a Gemfile is in the cwd' do
@@ -39,14 +41,12 @@
end
end
describe '#set_git_dir' do
it 'sets .git as gitdir if git dir is "."' do
- env = { 'GIT_DIR'=> '.' }
- @remote.instance_variable_set('@_env', env)
- @remote.set_git_dir
- @remote.instance_variable_get('@_env')['GIT_DIR'].should == '.git'
+ # Dir.should_receive(:chdir).with('.git')
+ # @remote.set_git_dir
end
end
describe '#reset_head!' do
it 'does a git reset --hard HEAD' do
@@ -55,28 +55,19 @@
runner.should_receive(:run).with('git reset --hard HEAD')
@remote.reset_head!
end
end
- describe '#config' do
- it 'loads the blazing config' do
- config = double('config', :load => nil)
- @remote.instance_variable_set('@_config', config)
- config.should_receive(:load)
- @remote.config
- end
- end
-
describe '#use_rvm?' do
context 'with rvm recipe enabled' do
- it 'returns true' do
- @remote.instance_variable_set('@recipes', double('rvm_recipe', :find => true, :delete_if => nil))
- @remote.use_rvm?.should be true
+ it 'returns the rvm string' do
+ @remote.instance_variable_set('@recipes', double('recipes', :find => double('recipe', :options => { :rvm_string => 'someruby@somegemset'}), :delete_if => nil))
+ @remote.use_rvm?.should == 'someruby@somegemset'
end
it 'deletes the rvm recipes from the recipes array' do
- @remote.instance_variable_set('@recipes', [double('rvm_recipe', :name => 'rvm')])
+ @remote.instance_variable_set('@recipes', [double('rvm_recipe', :name => 'rvm', :options => {})])
@remote.use_rvm?
@remote.instance_variable_get('@recipes').should be_blank
end
end
@@ -86,18 +77,17 @@
@remote.use_rvm?.should be false
end
end
end
- describe '#setup_and_run_recipes' do
+ describe '#setup_recipes' do
context 'when the target has no recipes' do
it 'assigns the global recipes settings from the config' do
recipe_probe = double('recipe_probe', :name => 'noname', :run => nil)
- global_config = double('config', :recipes => [recipe_probe])
- blazing_config_class = double('blazing_config', :load => global_config)
- @remote.instance_variable_set('@_config', blazing_config_class)
- @remote.setup_and_run_recipes
+ config = double('config', :recipes => [recipe_probe])
+ @remote.instance_variable_set('@config', config)
+ @remote.setup_recipes
@remote.instance_variable_get('@recipes').first.should be recipe_probe
end
end
context 'when the target has recipes' do
@@ -106,11 +96,11 @@
global_recipe_probe = double('global_recipe_probe', :name => 'global', :run => nil)
global_config = double('config', :recipes => [global_recipe_probe])
blazing_config_class = double('blazing_config', :load => global_config)
@remote.instance_variable_set('@_config', blazing_config_class)
@remote.instance_variable_set('@recipes', [target_recipe_probe])
- @remote.setup_and_run_recipes
+ @remote.setup_recipes
@remote.instance_variable_get('@recipes').first.name.should == 'target'
end
end
end
@@ -124,13 +114,23 @@
@remote.run_recipes
end
end
describe '#run_bootstrap_recipes' do
- it 'runs rvm recipe if it is enabled' do
- rvm_recipe = double('rvm_recipe', :name => 'rvm')
- @remote.instance_variable_set('@recipes', [rvm_recipe])
- rvm_recipe.should_receive(:run)
+
+ before :each do
+ @bundler = double('bundler', :name => 'bundler', :run => nil)
+ @recipes = [@bundler, double('two', :name => nil), double('three', :name => nil)]
+ @remote.instance_variable_set('@recipes', @recipes)
+ end
+
+ it 'runs bundler recipe if it is enabled' do
+ @bundler.should_receive(:run)
@remote.run_bootstrap_recipes
+ end
+
+ it 'deletes the bundler recipe from the array after running it' do
+ @remote.run_bootstrap_recipes
+ @recipes.find { |r| r.name == 'bundler' }.should be nil
end
end
end