From 9e682025da6d175752fef53ecef3fe5432d431de Mon Sep 17 00:00:00 2001 From: Ryan Rosenblum Date: Thu, 22 Oct 2015 21:29:03 -0400 Subject: [PATCH 1/4] Update rspec dependency to ~> 3.3 --- Rakefile | 2 +- cf_deployer.gemspec | 2 +- spec/unit/application_spec.rb | 18 +-- spec/unit/component_spec.rb | 6 +- spec/unit/config_loader_spec.rb | 130 +++++++++--------- .../auto_scaling_group_swap_spec.rb | 16 +-- spec/unit/deployment_strategy/base_spec.rb | 34 ++--- .../deployment_strategy/cname_swap_spec.rb | 14 +- .../create_or_update_spec.rb | 16 +-- spec/unit/driver/auto_scaling_group_spec.rb | 2 +- spec/unit/driver/cloud_formation_spec.rb | 4 +- spec/unit/driver/elb_spec.rb | 2 +- spec/unit/driver/route53_spec.rb | 8 +- spec/unit/hook_spec.rb | 2 +- spec/unit/stack_spec.rb | 2 +- 15 files changed, 129 insertions(+), 129 deletions(-) diff --git a/Rakefile b/Rakefile index 01828d2..523e9ca 100644 --- a/Rakefile +++ b/Rakefile @@ -5,7 +5,7 @@ require 'bundler/gem_tasks' require 'rspec/core/rake_task' namespace :spec do - RSPEC_OPTS = ["--format", "nested", "--format", "html", "--out", "spec_result.html", "--colour"] + RSPEC_OPTS = ["--format", "documentation", "--format", "html", "--out", "spec_result.html", "--colour"] RSpec::Core::RakeTask.new(:file) do |t| t.rspec_opts = RSPEC_OPTS diff --git a/cf_deployer.gemspec b/cf_deployer.gemspec index b2e6453..29d4e79 100644 --- a/cf_deployer.gemspec +++ b/cf_deployer.gemspec @@ -16,7 +16,7 @@ Gem::Specification.new do |gem| gem.add_runtime_dependency 'diffy' gem.add_development_dependency 'yard', '~> 0.8.7.6' gem.add_development_dependency 'pry', '~> 0.10.1' - gem.add_development_dependency 'rspec', '2.14.1' + gem.add_development_dependency 'rspec', '~> 3.3' gem.add_development_dependency 'rake', '~> 10.3.0' gem.files = `git ls-files`.split($\).reject {|f| f =~ /^samples\// } diff --git a/spec/unit/application_spec.rb b/spec/unit/application_spec.rb index 7fcd716..3606d2b 100644 --- a/spec/unit/application_spec.rb +++ b/spec/unit/application_spec.rb @@ -28,11 +28,11 @@ end it "application should get all components" do - @app.components.length.should eq(4) - @base.should_not be_nil - @db.should_not be_nil - @queue.should_not be_nil - @web.should_not be_nil + expect(@app.components.length).to eq(4) + expect(@base).not_to be_nil + expect(@db).not_to be_nil + expect(@queue).not_to be_nil + expect(@web).not_to be_nil end context "order components by dependencies" do @@ -154,7 +154,7 @@ context "deploy all components" do it "should deploy all components if no component specified" do @app.deploy - @log.should eq("base db queue web ") + expect(@log).to eq("base db queue web ") end end @@ -162,7 +162,7 @@ it "should deploy specified components" do @context[:targets] = ['web', 'db'] @app.deploy - @log.should eq("db web ") + expect(@log).to eq("db web ") end end end @@ -179,13 +179,13 @@ it 'should get json templates for all components' do @app.json - @log.should eq("base db queue web ") + expect(@log).to eq("base db queue web ") end it 'should get json templates for components specified' do @context[:targets] = ['web', 'db'] @app.json - @log.should eq('db web ') + expect(@log).to eq('db web ') end end end diff --git a/spec/unit/component_spec.rb b/spec/unit/component_spec.rb index 6c3e8bb..f03f63d 100644 --- a/spec/unit/component_spec.rb +++ b/spec/unit/component_spec.rb @@ -68,7 +68,7 @@ it "should ask strategy if component exists" do expect(@strategy).to receive(:exists?){ true } - @web.exists?.should eq(true) + expect(@web.exists?).to eq(true) end it "should find direct dependencies" do @@ -76,7 +76,7 @@ base = CfDeployer::Component.new('myApp', 'uat', 'base', {}) web.dependencies << base - web.depends_on?(base).should eq(true) + expect(web.depends_on?(base)).to eq(true) end it "should find transitive dependencies" do @@ -87,7 +87,7 @@ haproxy.dependencies << base web.dependencies << haproxy - web.depends_on?(base).should eq(true) + expect(web.depends_on?(base)).to eq(true) end it "should find cyclic dependency" do diff --git a/spec/unit/config_loader_spec.rb b/spec/unit/config_loader_spec.rb index bbab941..723cd86 100644 --- a/spec/unit/config_loader_spec.rb +++ b/spec/unit/config_loader_spec.rb @@ -146,143 +146,143 @@ it "all the keys should be symbols in config" do config = CfDeployer::ConfigLoader.new.load({:'config-file' => @config_file}) - config[:components][:base][:'deployment-strategy'].should eq('create-or-update') - config['components'].should be_nil + expect(config[:components][:base][:'deployment-strategy']).to eq('create-or-update') + expect(config['components']).to be_nil end it "should copy application, environment, component to component settings" do config = CfDeployer::ConfigLoader.new.load({:'config-file' => @config_file, :environment => 'uat'}) - config[:components][:api][:settings][:application].should eq("myApp") - config[:components][:api][:settings][:component].should eq("api") - config[:components][:api][:settings][:environment].should eq("uat") - config[:components][:base][:settings][:application].should eq("myApp") - config[:components][:base][:settings][:component].should eq("base") - config[:components][:base][:settings][:environment].should eq("uat") + expect(config[:components][:api][:settings][:application]).to eq("myApp") + expect(config[:components][:api][:settings][:component]).to eq("api") + expect(config[:components][:api][:settings][:environment]).to eq("uat") + expect(config[:components][:base][:settings][:application]).to eq("myApp") + expect(config[:components][:base][:settings][:component]).to eq("base") + expect(config[:components][:base][:settings][:environment]).to eq("uat") end it "should copy region to coponent settings" do config = CfDeployer::ConfigLoader.new.load({:'config-file' => @config_file, :environment => 'uat', :region => 'us-west-1'}) - config[:components][:api][:settings][:region].should eq("us-west-1") - config[:components][:base][:settings][:region].should eq("us-west-1") + expect(config[:components][:api][:settings][:region]).to eq("us-west-1") + expect(config[:components][:base][:settings][:region]).to eq("us-west-1") end it "should copy application, environment, component to component inputs" do config = CfDeployer::ConfigLoader.new.load({:'config-file' => @config_file, :environment => 'uat'}) - config[:components][:api][:inputs][:application].should eq("myApp") - config[:components][:api][:inputs][:component].should eq("api") - config[:components][:api][:inputs][:environment].should eq("uat") - config[:components][:base][:inputs][:application].should eq("myApp") - config[:components][:base][:inputs][:component].should eq("base") - config[:components][:base][:inputs][:environment].should eq("uat") + expect(config[:components][:api][:inputs][:application]).to eq("myApp") + expect(config[:components][:api][:inputs][:component]).to eq("api") + expect(config[:components][:api][:inputs][:environment]).to eq("uat") + expect(config[:components][:base][:inputs][:application]).to eq("myApp") + expect(config[:components][:base][:inputs][:component]).to eq("base") + expect(config[:components][:base][:inputs][:environment]).to eq("uat") end it "should copy region to coponent inputs" do config = CfDeployer::ConfigLoader.new.load({:'config-file' => @config_file, :environment => 'uat', :region => 'us-west-1'}) - config[:components][:api][:inputs][:region].should eq("us-west-1") - config[:components][:base][:inputs][:region].should eq("us-west-1") + expect(config[:components][:api][:inputs][:region]).to eq("us-west-1") + expect(config[:components][:base][:inputs][:region]).to eq("us-west-1") end it "config_dir option should be copied to component context" do config_dir = File.dirname(@config_file) config = CfDeployer::ConfigLoader.new.load({:'config-file' => @config_file, :environment => 'uat'}) - config[:components][:api][:config_dir].should eq(config_dir) - config[:components][:base][:config_dir].should eq(config_dir) - config[:components][:'front-end'][:config_dir].should eq(config_dir) + expect(config[:components][:api][:config_dir]).to eq(config_dir) + expect(config[:components][:base][:config_dir]).to eq(config_dir) + expect(config[:components][:'front-end'][:config_dir]).to eq(config_dir) end it "notify option should be merged to component context" do config = CfDeployer::ConfigLoader.new.load({:'config-file' => @config_file, :environment => 'dev'}) - config[:components][:base][:notify].should eq(['arn:root', 'arn:base', 'arn:dev']) - config[:components][:api][:notify].should eq(['arn:root', 'arn:api', 'arn:dev']) - config[:components][:'front-end'][:notify].should eq(['arn:root', 'arn:base', 'arn:dev']) + expect(config[:components][:base][:notify]).to eq(['arn:root', 'arn:base', 'arn:dev']) + expect(config[:components][:api][:notify]).to eq(['arn:root', 'arn:api', 'arn:dev']) + expect(config[:components][:'front-end'][:notify]).to eq(['arn:root', 'arn:base', 'arn:dev']) end it "notify option should be merged to environment context" do config = CfDeployer::ConfigLoader.new.load({:'config-file' => @config_file, :environment => 'uat'}) - config[:components][:base][:notify].should eq(['arn:root', 'arn:base']) - config[:components][:api][:notify].should eq(['arn:root', 'arn:api']) - config[:components][:'front-end'][:notify].should eq(['arn:root', 'arn:base']) + expect(config[:components][:base][:notify]).to eq(['arn:root', 'arn:base']) + expect(config[:components][:api][:notify]).to eq(['arn:root', 'arn:api']) + expect(config[:components][:'front-end'][:notify]).to eq(['arn:root', 'arn:base']) end it "tags option should be copied to component context" do config = CfDeployer::ConfigLoader.new.load({:'config-file' => @config_file, :environment => 'uat'}) - config[:components][:api][:tags].should eq({:version => 'v1.1'}) - config[:components][:base][:tags].should eq({:version => 'v1.1', :component => 'base'}) - config[:components][:'front-end'][:tags].should eq({:version => 'v1.1'}) + expect(config[:components][:api][:tags]).to eq({:version => 'v1.1'}) + expect(config[:components][:base][:tags]).to eq({:version => 'v1.1', :component => 'base'}) + expect(config[:components][:'front-end'][:tags]).to eq({:version => 'v1.1'}) end it "component's settings should be merged to common settings" do config = CfDeployer::ConfigLoader.new.load({:'config-file' => @config_file, :environment => 'uat'}) - config[:components][:api][:inputs][:'timeout'].should eq(90) - config[:components][:api][:inputs][:'require-basic-auth'].should eq(true) - config[:components][:api][:inputs][:'mail-server'].should eq('http://api.abc.com') + expect(config[:components][:api][:inputs][:'timeout']).to eq(90) + expect(config[:components][:api][:inputs][:'require-basic-auth']).to eq(true) + expect(config[:components][:api][:inputs][:'mail-server']).to eq('http://api.abc.com') end it "environment's settings should be merged to component settings" do config = CfDeployer::ConfigLoader.new.load({:'config-file' => @config_file, :environment => 'dev'}) - config[:components][:api][:inputs][:'timeout'].should eq(60) - config[:components][:api][:inputs][:'require-basic-auth'].should eq(true) - config[:components][:api][:inputs][:'mail-server'].should eq('http://dev.abc.com') + expect(config[:components][:api][:inputs][:'timeout']).to eq(60) + expect(config[:components][:api][:inputs][:'require-basic-auth']).to eq(true) + expect(config[:components][:api][:inputs][:'mail-server']).to eq('http://dev.abc.com') end it "should merge environment's components to component settings" do config = CfDeployer::ConfigLoader.new.load({:'config-file' => @config_file, :environment => 'production'}) - config[:components][:'front-end'][:inputs][:'cname'].should eq('prod-front-end.myserver.com') - config[:components][:api][:inputs][:'cname'].should eq('myserver.com') + expect(config[:components][:'front-end'][:inputs][:'cname']).to eq('prod-front-end.myserver.com') + expect(config[:components][:api][:inputs][:'cname']).to eq('myserver.com') end it "environment variables without prefix 'cfdeploy_settings_' should not be merged to components settings" do ENV['timeout'] = "180" config = CfDeployer::ConfigLoader.new.load({:'config-file' => @config_file, :environment => 'dev'}) - config[:components][:api][:inputs][:'timeout'].should eq(60) + expect(config[:components][:api][:inputs][:'timeout']).to eq(60) end it "should merge environment variables should be merged to components settings" do ENV['cfdeploy_inputs_timeout'] = "180" config = CfDeployer::ConfigLoader.new.load({:'config-file' => @config_file, :environment => 'dev'}) - config[:components][:api][:inputs][:'timeout'].should eq("180") + expect(config[:components][:api][:inputs][:'timeout']).to eq("180") end it "cli settings should be merged to components settings" do ENV['cfdeploy_settings_timeout'] = "180" config = CfDeployer::ConfigLoader.new.load({:'config-file' => @config_file, :environment => 'dev',:cli_overrides => {:settings => {:timeout => 45}}}) - config[:components][:api][:settings][:'timeout'].should eq(45) + expect(config[:components][:api][:settings][:'timeout']).to eq(45) end it "should set cloudFormation parameter names into each component" do config = CfDeployer::ConfigLoader.new.load({:'config-file' => @config_file}) - config[:components][:base][:defined_parameters].should eq({}) - config[:components][:api][:defined_parameters].should eq({:'require-basic-auth' => {:Default => "true"}}) - config[:components][:'front-end'][:defined_parameters].should eq({:'require-basic-auth' => {}, :'mail-server' => {}}) + expect(config[:components][:base][:defined_parameters]).to eq({}) + expect(config[:components][:api][:defined_parameters]).to eq({:'require-basic-auth' => {:Default => "true"}}) + expect(config[:components][:'front-end'][:defined_parameters]).to eq({:'require-basic-auth' => {}, :'mail-server' => {}}) end it "should set cloudFormation output names into each component" do config = CfDeployer::ConfigLoader.new.load({:'config-file' => @config_file}) - config[:components][:base][:defined_outputs].should eq({:'vpc-id' => {}, :'AutoScalingGroupName'=>{}, :'public-subnet-id'=>{}}) - config[:components][:api][:defined_outputs].should eq({}) - config[:components][:'front-end'][:defined_outputs].should eq({:'AutoScalingGroupName'=>{}, :'elb-cname' => {}}) + expect(config[:components][:base][:defined_outputs]).to eq({:'vpc-id' => {}, :'AutoScalingGroupName'=>{}, :'public-subnet-id'=>{}}) + expect(config[:components][:api][:defined_outputs]).to eq({}) + expect(config[:components][:'front-end'][:defined_outputs]).to eq({:'AutoScalingGroupName'=>{}, :'elb-cname' => {}}) end it "should remove common settings in order not to confuse us" do config = CfDeployer::ConfigLoader.new.load({:'config-file' => @config_file}) - config[:settings].should be_nil + expect(config[:settings]).to be_nil end it "should set default elb-name-output for cname-swap strategy" do config = CfDeployer::ConfigLoader.new.load({:'config-file' => @config_file}) - config[:components][:'front-end'][:settings][:'elb-name-output'].should eq('ELBName') + expect(config[:components][:'front-end'][:settings][:'elb-name-output']).to eq('ELBName') end it "should set default auto-scaling-group-name-output for cname-swap strategy" do config = CfDeployer::ConfigLoader.new.load({:'config-file' => @config_file}) - config[:components][:api][:settings][:'auto-scaling-group-name-output'].should eq([ CfDeployer::Defaults::AutoScalingGroupName ]) + expect(config[:components][:api][:settings][:'auto-scaling-group-name-output']).to eq([ CfDeployer::Defaults::AutoScalingGroupName ]) end it "should set auto-scaling-group-name-output to default if auto-scaling-group-name exists in output for create-or-update strategy" do config = CfDeployer::ConfigLoader.new.load({:'config-file' => @config_file}) - config[:components][:base][:settings][:'auto-scaling-group-name-output'].should eq([ CfDeployer::Defaults::AutoScalingGroupName ]) + expect(config[:components][:base][:settings][:'auto-scaling-group-name-output']).to eq([ CfDeployer::Defaults::AutoScalingGroupName ]) end it "should not set auto-scaling-group-name-output to default if auto-scaling-group-name does not exists in output for create-or-update strategy" do @@ -295,17 +295,17 @@ File.open(@base_json, 'w') {|f| f.write(base_json) } config = CfDeployer::ConfigLoader.new.load({:'config-file' => @config_file}) - config[:components][:'base'][:settings][:'auto-scaling-group-name-output'].should be_nil + expect(config[:components][:'base'][:settings][:'auto-scaling-group-name-output']).to be_nil end it "should set auto-scaling-group-name-output to default if auto-scaling-group-name exists in output for cname-swap strategy" do config = CfDeployer::ConfigLoader.new.load({:'config-file' => @config_file}) - config[:components][:'front-end'][:settings][:'auto-scaling-group-name-output'].should eq([ CfDeployer::Defaults::AutoScalingGroupName ]) + expect(config[:components][:'front-end'][:settings][:'auto-scaling-group-name-output']).to eq([ CfDeployer::Defaults::AutoScalingGroupName ]) end it "should set raise-error-for-unused-inputs to default" do config = CfDeployer::ConfigLoader.new.load({:'config-file' => @config_file}) - config[:components][:'front-end'][:settings][:'raise-error-for-unused-inputs'].should eq(CfDeployer::Defaults::RaiseErrorForUnusedInputs) + expect(config[:components][:'front-end'][:settings][:'raise-error-for-unused-inputs']).to eq(CfDeployer::Defaults::RaiseErrorForUnusedInputs) end it "should not set auto-scaling-group-name-output to default if auto-scaling-group-name does not exists in output for cname-swap strategy" do @@ -319,22 +319,22 @@ File.open(@front_end_json, 'w') {|f| f.write(front_end_json) } config = CfDeployer::ConfigLoader.new.load({:'config-file' => @config_file}) - config[:components][:'front-end'][:settings][:'auto-scaling-group-name-output'].should be_nil + expect(config[:components][:'front-end'][:settings][:'auto-scaling-group-name-output']).to be_nil end it "should ERB the config file and provide the environment in the binding" do config = CfDeployer::ConfigLoader.new.load(:'config-file' => @config_file, :environment => 'DrWho') - config[:components][:base][:inputs][:'foobar'].should eq('DrWho.IsGreat') + expect(config[:components][:base][:inputs][:'foobar']).to eq('DrWho.IsGreat') end it "should ERB the component JSON and make the parsed template available" do config = CfDeployer::ConfigLoader.new.load(:'config-file' => @config_file, :environment => 'DrWho') - CfDeployer::ConfigLoader.component_json('json-with-erb', config[:components][:'json-with-erb']).should include('DrWho') + expect(CfDeployer::ConfigLoader.component_json('json-with-erb', config[:components][:'json-with-erb'])).to include('DrWho') end it 'should use error_document to show the broken document when parsing broken ERB' do config = { :config_dir => File.dirname(@config_file) } - CfDeployer::ConfigLoader.any_instance.should_receive(:error_document) + expect_any_instance_of(CfDeployer::ConfigLoader).to receive(:error_document) expect { CfDeployer::ConfigLoader.component_json('broken_erb', config) }.to raise_error end @@ -347,35 +347,35 @@ :defined_parameters => {}, :defined_outputs => {} } - CfDeployer::ConfigLoader.any_instance.should_receive(:error_document) + expect_any_instance_of(CfDeployer::ConfigLoader).to receive(:error_document) expect { loader.send(:cf_template, 'broken_json') }.to raise_error end it 'should use error_document to show the broken document when parsing broken yaml' do - CfDeployer::ConfigLoader.any_instance.should_receive(:error_document) + expect_any_instance_of(CfDeployer::ConfigLoader).to receive(:error_document) expect { CfDeployer::ConfigLoader.new.send(:load_yaml, @broken_yaml) }.to raise_error end it 'should set default keep-previous-stack to true' do config = CfDeployer::ConfigLoader.new.load(:'config-file' => @config_file) - config[:components][:api][:settings][:'keep-previous-stack'].should eq(CfDeployer::Defaults::KeepPreviousStack) + expect(config[:components][:api][:settings][:'keep-previous-stack']).to eq(CfDeployer::Defaults::KeepPreviousStack) end it 'should keep keep-previous-stack setting' do config = CfDeployer::ConfigLoader.new.load(:'config-file' => @config_file) - config[:components][:'front-end'][:settings][:'keep-previous-stack'].should be_false + expect(config[:components][:'front-end'][:settings][:'keep-previous-stack']).to be_falsey end context 'targets' do it 'should use all components as targets if no targets are specified' do config = CfDeployer::ConfigLoader.new.load(:'config-file' => @config_file) - config[:targets].should eq(['base', 'api', 'front-end', 'very-simple', 'json-with-erb']) + expect(config[:targets]).to eq(['base', 'api', 'front-end', 'very-simple', 'json-with-erb']) end it 'should keep targets if targets are specified' do config = CfDeployer::ConfigLoader.new.load(:'config-file' => @config_file, :component => ['api', 'web']) - config[:targets].should eq(['api', 'web']) + expect(config[:targets]).to eq(['api', 'web']) end end @@ -418,7 +418,7 @@ File.open(@config_file, 'w') {|f| f.write(config) } config = CfDeployer::ConfigLoader.new.load({:'config-file' => @config_file}) - config[:components][:'api'][:defined_parameters].should eq({ db:'base::elb-cname', url:'http://abc.com'}) + expect(config[:components][:'api'][:defined_parameters]).to eq({ db:'base::elb-cname', url:'http://abc.com'}) end end diff --git a/spec/unit/deployment_strategy/auto_scaling_group_swap_spec.rb b/spec/unit/deployment_strategy/auto_scaling_group_swap_spec.rb index 9bd42a4..715bd4c 100644 --- a/spec/unit/deployment_strategy/auto_scaling_group_swap_spec.rb +++ b/spec/unit/deployment_strategy/auto_scaling_group_swap_spec.rb @@ -31,18 +31,18 @@ it 'no if no G and B stacks exist' do blue_stack.die! green_stack.die! - CfDeployer::DeploymentStrategy.create(app, env, component, context).exists?.should be_false + expect(CfDeployer::DeploymentStrategy.create(app, env, component, context).exists?).to be_falsey end it 'yes if B stacks exist' do blue_stack.live! green_stack.die! - CfDeployer::DeploymentStrategy.create(app, env, component, context).exists?.should be_true + expect(CfDeployer::DeploymentStrategy.create(app, env, component, context).exists?).to be_truthy end it 'yes if G stacks exist' do blue_stack.die! green_stack.live! - CfDeployer::DeploymentStrategy.create(app, env, component, context).exists?.should be_true + expect(CfDeployer::DeploymentStrategy.create(app, env, component, context).exists?).to be_truthy end end @@ -119,7 +119,7 @@ @log += "#{arg[:parameters][:name]} deleted." end CfDeployer::DeploymentStrategy.create(app, env, component, context).destroy - @log.should eq('green deleted.blue deleted.') + expect(@log).to eq('green deleted.blue deleted.') end end @@ -367,7 +367,7 @@ allow(green_asg_driver).to receive(:describe) {{desired: 0, min: 0, max: 0}} allow(blue_asg_driver).to receive(:describe) {{desired: 3, min: 1, max: 5}} asg_swap = CfDeployer::DeploymentStrategy.create(app, env, component, context) - asg_swap.output_value("AutoScalingGroupID").should eq("blueASG") + expect(asg_swap.output_value("AutoScalingGroupID")).to eq("blueASG") end it 'should get the information where the value comes from if the active stack does not exist' do @@ -378,7 +378,7 @@ allow(green_asg_driver).to receive(:describe) {{desired: 0, min: 0, max: 0}} allow(blue_asg_driver).to receive(:describe) {{desired: 0, min: 0, max: 0}} asg_swap = CfDeployer::DeploymentStrategy.create(app, env, component, context) - asg_swap.output_value(:a_key).should eq("The value will be referenced from the output a_key of undeployed component worker") + expect(asg_swap.output_value(:a_key)).to eq("The value will be referenced from the output a_key of undeployed component worker") end end @@ -410,7 +410,7 @@ :status => 'green deployed' } } - asg_swap.status.should eq(expected_result) + expect(asg_swap.status).to eq(expected_result) end it 'should get status for both green and blue stacks including resources info' do @@ -427,7 +427,7 @@ :resources => 'green resources' } } - asg_swap.status(true).should eq(expected_result) + expect(asg_swap.status(true)).to eq(expected_result) end end end diff --git a/spec/unit/deployment_strategy/base_spec.rb b/spec/unit/deployment_strategy/base_spec.rb index 4ffc280..182d886 100644 --- a/spec/unit/deployment_strategy/base_spec.rb +++ b/spec/unit/deployment_strategy/base_spec.rb @@ -57,11 +57,11 @@ it "should return nil if there is no active stack" do the_stack = double() - the_stack.should_receive(:exists?).and_return(false) - the_stack.should_not_receive(:template) + expect(the_stack).to receive(:exists?).and_return(false) + expect(the_stack).not_to receive(:template) strategy = CfDeployer::DeploymentStrategy.create('myApp', 'uat', 'web', @context[:components][:web]) - strategy.should_receive(:active_stack).and_return(the_stack) + expect(strategy).to receive(:active_stack).and_return(the_stack) # strategy.should_not_receive(:get_parameters_outputs) expect( strategy.active_template ).to eq(nil) @@ -71,11 +71,11 @@ the_template = double the_stack = double - the_stack.should_receive(:exists?).and_return(true) - the_stack.should_receive(:template).and_return(the_template) + expect(the_stack).to receive(:exists?).and_return(true) + expect(the_stack).to receive(:template).and_return(the_template) strategy = CfDeployer::DeploymentStrategy.create('myApp', 'uat', 'web', @context[:components][:web]) - strategy.should_receive(:active_stack).and_return(the_stack) + expect(strategy).to receive(:active_stack).and_return(the_stack) expect( strategy.active_template ).to eq(the_template) end @@ -96,8 +96,8 @@ it "should run the specified hook" do hook = double() - CfDeployer::Hook.should_receive(:new).and_return(hook) - hook.should_receive(:run) + expect(CfDeployer::Hook).to receive(:new).and_return(hook) + expect(hook).to receive(:run) strategy = CfDeployer::DeploymentStrategy.create('myApp', 'uat', 'web', @context[:components][:web]) strategy.instance_variable_set('@params_and_outputs_resolved', true) @@ -107,30 +107,30 @@ it "should not try to resolve parameters and outputs they're already initialized" do strategy = CfDeployer::DeploymentStrategy.create('myApp', 'uat', 'web', @context[:components][:web]) strategy.instance_variable_set('@params_and_outputs_resolved', true) - strategy.should_not_receive(:get_parameters_outputs) + expect(strategy).not_to receive(:get_parameters_outputs) strategy.run_hook(:some_hook) end it "should not try to resolve parameters and outputs if there's no running stack" do the_stack = double() - the_stack.should_receive(:exists?).and_return(false) - the_stack.should_receive(:name).and_return("thestack") + expect(the_stack).to receive(:exists?).and_return(false) + expect(the_stack).to receive(:name).and_return("thestack") strategy = CfDeployer::DeploymentStrategy.create('myApp', 'uat', 'web', @context[:components][:web]) - strategy.should_receive(:active_stack).and_return(the_stack) - strategy.should_not_receive(:get_parameters_outputs) + expect(strategy).to receive(:active_stack).and_return(the_stack) + expect(strategy).not_to receive(:get_parameters_outputs) strategy.run_hook(:some_hook) end it "should not try to run a hook if there's no running stack" do - CfDeployer::Hook.should_not_receive(:new) + expect(CfDeployer::Hook).not_to receive(:new) the_stack = double() - the_stack.should_receive(:exists?).and_return(false) - the_stack.should_receive(:name).and_return("thestack") + expect(the_stack).to receive(:exists?).and_return(false) + expect(the_stack).to receive(:name).and_return("thestack") strategy = CfDeployer::DeploymentStrategy.create('myApp', 'uat', 'web', @context[:components][:web]) - strategy.should_receive(:active_stack).and_return(the_stack) + expect(strategy).to receive(:active_stack).and_return(the_stack) strategy.run_hook(:some_hook) end end diff --git a/spec/unit/deployment_strategy/cname_swap_spec.rb b/spec/unit/deployment_strategy/cname_swap_spec.rb index a7b8ab4..6d8f78d 100644 --- a/spec/unit/deployment_strategy/cname_swap_spec.rb +++ b/spec/unit/deployment_strategy/cname_swap_spec.rb @@ -66,7 +66,7 @@ end expect(dns_driver).to receive(:delete_record_set).with('foobar.com', 'test.foobar.com') cname_swap.destroy - @log.should eq('green deleted.blue deleted.') + expect(@log).to eq('green deleted.blue deleted.') end end @@ -188,19 +188,19 @@ blue_stack.die! green_stack.die! cname_swap = CfDeployer::DeploymentStrategy.create('myapp', 'dev', 'web', @context) - cname_swap.exists?.should be_false + expect(cname_swap.exists?).to be_falsey end it 'yes, if green stack exists and blue stack does not' do blue_stack.die! cname_swap = CfDeployer::DeploymentStrategy.create('myapp', 'dev', 'web', @context) - cname_swap.exists?.should be_true + expect(cname_swap.exists?).to be_truthy end it 'yes, if blue stack exists and green stack does not' do green_stack.die! cname_swap = CfDeployer::DeploymentStrategy.create('myapp', 'dev', 'web', @context) - cname_swap.exists?.should be_true + expect(cname_swap.exists?).to be_truthy end end @@ -220,7 +220,7 @@ my_context.delete :dns_driver my_context[:settings][:'dns-driver'] = 'CfDeployer::Driver::Verisign' cname_swap = CfDeployer::DeploymentStrategy.create('myapp', 'dev', 'web', my_context) - cname_swap.send(:dns_driver).class.to_s.should eq(my_context[:settings][:'dns-driver']) + expect(cname_swap.send(:dns_driver).class.to_s).to eq(my_context[:settings][:'dns-driver']) end end @@ -284,13 +284,13 @@ it 'should get stack output if active stack exists' do allow(dns_driver).to receive(:find_alias_target).with('foobar.com', 'test.foobar.com'){ 'BLUE-elb.aws.amazon.com' } cname_swap = CfDeployer::DeploymentStrategy.create('myapp', 'dev', 'web', @context) - cname_swap.output_value("AutoScalingGroupID").should eq("blueASG") + expect(cname_swap.output_value("AutoScalingGroupID")).to eq("blueASG") end it 'should get the information where the value comes from if the active stack does not exist' do allow(dns_driver).to receive(:find_alias_target).with('foobar.com', 'test.foobar.com'){ '' } cname_swap = CfDeployer::DeploymentStrategy.create('myapp', 'dev', 'web', @context) - cname_swap.output_value(:a_key).should eq("The value will be referenced from the output a_key of undeployed component web") + expect(cname_swap.output_value(:a_key)).to eq("The value will be referenced from the output a_key of undeployed component web") end end end diff --git a/spec/unit/deployment_strategy/create_or_update_spec.rb b/spec/unit/deployment_strategy/create_or_update_spec.rb index 61793ac..d7e7b36 100644 --- a/spec/unit/deployment_strategy/create_or_update_spec.rb +++ b/spec/unit/deployment_strategy/create_or_update_spec.rb @@ -33,7 +33,7 @@ expect(@after_create_hook).to receive(:run) do |given_context| hook_context = given_context end - @stack.should_receive(:exists?).and_return(false) + expect(@stack).to receive(:exists?).and_return(false) expect(@stack).to receive(:deploy) @create_or_update.deploy expect(hook_context[:parameters]).to eq( {'vpc' => 'myvpc'} ) @@ -45,7 +45,7 @@ expect(@after_update_hook).to receive(:run) do |given_context| hook_context = given_context end - @stack.should_receive(:exists?).and_return(true) + expect(@stack).to receive(:exists?).and_return(true) expect(@stack).to receive(:deploy) @create_or_update.deploy expect(hook_context[:parameters]).to eq( {'vpc' => 'myvpc'} ) @@ -60,7 +60,7 @@ context = @context[:components][:base] context[:settings] = {} context[:settings][:'auto-scaling-group-name-output'] = ['AutoScalingGroupID'] - @stack.should_receive(:exists?).and_return(false) + expect(@stack).to receive(:exists?).and_return(false) allow(@stack).to receive(:output).with('AutoScalingGroupID') { 'asg_name' } allow(CfDeployer::Driver::AutoScalingGroup).to receive(:new).with('asg_name') { asg_driver } allow(asg_driver).to receive(:describe) { {desired:2, min:1, max:3} } @@ -74,19 +74,19 @@ it 'should tell if stack exists' do expect(@stack).to receive(:exists?){true} - @create_or_update.exists?.should eq(true) + expect(@create_or_update.exists?).to eq(true) end it 'should get stack output' do allow(@stack).to receive(:exists?){true} expect(@stack).to receive(:output).with(:a_key){ "output_value" } - @create_or_update.output_value(:a_key).should eq("output_value") + expect(@create_or_update.output_value(:a_key)).to eq("output_value") end it 'should get the information where the value comes from if the stack does not exist' do allow(@stack).to receive(:exists?){false} expect(@stack).not_to receive(:output).with(anything) - @create_or_update.output_value(:a_key).should eq("The value will be referenced from the output a_key of undeployed component base") + expect(@create_or_update.output_value(:a_key)).to eq("The value will be referenced from the output a_key of undeployed component base") end context '#destroy' do @@ -119,11 +119,11 @@ allow(@stack).to receive(:exists?) { true } end it 'should get status from stack' do - @create_or_update.status.should eq({ 'base-uat' => {status: 'deployed'}}) + expect(@create_or_update.status).to eq({ 'base-uat' => {status: 'deployed'}}) end it 'should get status from stack including resource info' do allow(@stack).to receive(:resource_statuses) { 'resource1' } - @create_or_update.status(true).should eq({ 'base-uat' => {status: 'deployed', resources: 'resource1'}}) + expect(@create_or_update.status(true)).to eq({ 'base-uat' => {status: 'deployed', resources: 'resource1'}}) end end end diff --git a/spec/unit/driver/auto_scaling_group_spec.rb b/spec/unit/driver/auto_scaling_group_spec.rb index c948280..4858d4b 100644 --- a/spec/unit/driver/auto_scaling_group_spec.rb +++ b/spec/unit/driver/auto_scaling_group_spec.rb @@ -22,7 +22,7 @@ end it 'should describe group' do - @driver.describe.should eq({ min: 1, max: 4, desired: 2}) + expect(@driver.describe).to eq({ min: 1, max: 4, desired: 2}) end describe '#warm_up' do diff --git a/spec/unit/driver/cloud_formation_spec.rb b/spec/unit/driver/cloud_formation_spec.rb index 33078cb..40ab4e4 100644 --- a/spec/unit/driver/cloud_formation_spec.rb +++ b/spec/unit/driver/cloud_formation_spec.rb @@ -18,11 +18,11 @@ end it 'should get outputs of stack' do - CfDeployer::Driver::CloudFormation.new('testStack').outputs.should eq({'key1' => 'value1', 'key2' => 'value2'}) + expect(CfDeployer::Driver::CloudFormation.new('testStack').outputs).to eq({'key1' => 'value1', 'key2' => 'value2'}) end it 'should get parameters of stack' do - CfDeployer::Driver::CloudFormation.new('testStack').parameters.should eq(parameters) + expect(CfDeployer::Driver::CloudFormation.new('testStack').parameters).to eq(parameters) end context 'resource_statuses' do diff --git a/spec/unit/driver/elb_spec.rb b/spec/unit/driver/elb_spec.rb index 3e2db14..b954581 100644 --- a/spec/unit/driver/elb_spec.rb +++ b/spec/unit/driver/elb_spec.rb @@ -6,6 +6,6 @@ aws = double('aws', :load_balancers => {'myelb' => elb}) elb_name = 'myelb' expect(AWS::ELB).to receive(:new){aws} - CfDeployer::Driver::Elb.new.find_dns_and_zone_id(elb_name).should eq({:dns_name => 'mydns', :canonical_hosted_zone_name_id => 'zone_id'}) + expect(CfDeployer::Driver::Elb.new.find_dns_and_zone_id(elb_name)).to eq({:dns_name => 'mydns', :canonical_hosted_zone_name_id => 'zone_id'}) end end diff --git a/spec/unit/driver/route53_spec.rb b/spec/unit/driver/route53_spec.rb index 8f4fe45..b98c7db 100644 --- a/spec/unit/driver/route53_spec.rb +++ b/spec/unit/driver/route53_spec.rb @@ -22,7 +22,7 @@ allow(AWS::Route53).to receive(:new) { route53 } allow(route53).to receive(:hosted_zones) { [zone] } - subject.find_alias_target('target.com', 'foo').should be_nil + expect(subject.find_alias_target('target.com', 'foo')).to be_nil end it "should get alias target" do @@ -31,7 +31,7 @@ route53 = double('route53', :hosted_zones => [zone]) allow(AWS::Route53).to receive(:new) { route53 } - subject.find_alias_target('Target.com', 'Foo.target.com').should eq('abc.com') + expect(subject.find_alias_target('Target.com', 'Foo.target.com')).to eq('abc.com') end it "should get a nil alias target when the record exists but has no alias target" do @@ -40,7 +40,7 @@ route53 = double('route53', :hosted_zones => [zone]) allow(AWS::Route53).to receive(:new) { route53 } - subject.find_alias_target('target.com', 'foo.target.com').should be_nil + expect(subject.find_alias_target('target.com', 'foo.target.com')).to be_nil end it "should get alias target when zone and host name having trailing dot" do @@ -49,7 +49,7 @@ route53 = double('route53', :hosted_zones => [zone]) allow(AWS::Route53).to receive(:new) { route53 } - subject.find_alias_target('target.com.', 'foo.target.com.').should eq('abc.com') + expect(subject.find_alias_target('target.com.', 'foo.target.com.')).to eq('abc.com') end end diff --git a/spec/unit/hook_spec.rb b/spec/unit/hook_spec.rb index ef44bd2..90360c1 100644 --- a/spec/unit/hook_spec.rb +++ b/spec/unit/hook_spec.rb @@ -67,7 +67,7 @@ it 'should catch SyntaxError during eval and show nicer output' do context = { app: 'myApp' } the_hook = CfDeployer::Hook.new('MyHook', "puts 'hello") - the_hook.should_receive :error_document + expect(the_hook).to receive :error_document expect { the_hook.run(context) }.to raise_error end diff --git a/spec/unit/stack_spec.rb b/spec/unit/stack_spec.rb index c97b3b9..ad9114c 100644 --- a/spec/unit/stack_spec.rb +++ b/spec/unit/stack_spec.rb @@ -80,7 +80,7 @@ it "should get output value" do expect(@cf_driver).to receive(:query_output).with('mykey'){ 'myvalue'} - @stack.output('mykey').should eq('myvalue') + expect(@stack.output('mykey')).to eq('myvalue') end end From b1e9a04e80c73579fa955b9c8a68d18ce7be2534 Mon Sep 17 00:00:00 2001 From: Ryan Rosenblum Date: Thu, 22 Oct 2015 21:44:55 -0400 Subject: [PATCH 2/4] Use .rspec file --- .rspec | 4 ++++ Rakefile | 5 ----- 2 files changed, 4 insertions(+), 5 deletions(-) create mode 100644 .rspec diff --git a/.rspec b/.rspec new file mode 100644 index 0000000..b9c358d --- /dev/null +++ b/.rspec @@ -0,0 +1,4 @@ +--color +--format documentation +--format html +--out spec_result.html diff --git a/Rakefile b/Rakefile index 523e9ca..d9f95c6 100644 --- a/Rakefile +++ b/Rakefile @@ -5,20 +5,15 @@ require 'bundler/gem_tasks' require 'rspec/core/rake_task' namespace :spec do - RSPEC_OPTS = ["--format", "documentation", "--format", "html", "--out", "spec_result.html", "--colour"] - RSpec::Core::RakeTask.new(:file) do |t| - t.rspec_opts = RSPEC_OPTS t.pattern = ENV['SPEC_FILE'] end RSpec::Core::RakeTask.new(:unit) do |t| - t.rspec_opts = RSPEC_OPTS t.pattern = 'spec/unit/**/*_spec.rb' end RSpec::Core::RakeTask.new(:functional) do |t| - t.rspec_opts = RSPEC_OPTS t.pattern = 'spec/functional/**/*_spec.rb' end From fb122c9590f05fcd70f6726b08322ac7da67af3e Mon Sep 17 00:00:00 2001 From: Ryan Rosenblum Date: Thu, 22 Oct 2015 21:52:02 -0400 Subject: [PATCH 3/4] Update Rspec configuration --- .gitignore | 1 + spec/spec_helper.rb | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/.gitignore b/.gitignore index 2208227..4e6dcb5 100644 --- a/.gitignore +++ b/.gitignore @@ -11,6 +11,7 @@ lib/bundler/man pkg rdoc spec/reports +spec/examples.txt test/tmp test/version_tmp /.rvmrc diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index da9e2ae..db2953e 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -7,3 +7,27 @@ def puts *args end +RSpec.configure do |config| + config.example_status_persistence_file_path = 'spec/examples.txt' + + config.expect_with :rspec do |expectations| + expectations.include_chain_clauses_in_custom_matcher_descriptions = true + expectations.syntax = :expect # Disable `should` + end + + config.filter_run :focus + + config.mock_with :rspec do |mocks| + mocks.syntax = :expect # Disable `should_receive` and `stub` + # Prevents you from mocking or stubbing a method that does not exist on + # a real object. This is generally recommended, and will default to + # `true` in RSpec 4. + # mocks.verify_partial_doubles = true # causing tests to fail in base_spec + end + + # config.order = :random # There are tests failing in random order + config.run_all_when_everything_filtered = true + # config.warnings = true # way too many warnings right now + + Kernel.srand config.seed +end From 49fe78f22d5448cf7b324fdc83ed2eef3afecd88 Mon Sep 17 00:00:00 2001 From: Ryan Rosenblum Date: Thu, 22 Oct 2015 22:19:15 -0400 Subject: [PATCH 4/4] Run tests in random order --- spec/spec_helper.rb | 2 +- spec/unit/config_loader_spec.rb | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index db2953e..bbfe02c 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -25,7 +25,7 @@ def puts *args # mocks.verify_partial_doubles = true # causing tests to fail in base_spec end - # config.order = :random # There are tests failing in random order + config.order = :random config.run_all_when_everything_filtered = true # config.warnings = true # way too many warnings right now diff --git a/spec/unit/config_loader_spec.rb b/spec/unit/config_loader_spec.rb index 723cd86..1368d13 100644 --- a/spec/unit/config_loader_spec.rb +++ b/spec/unit/config_loader_spec.rb @@ -140,8 +140,9 @@ end before :each do - ENV['timeout'] = nil - ENV['cfdeploy_settings_timeout'] = nil + ENV.delete('timeout') + ENV.delete('cfdeploy_settings_timeout') + ENV.delete('cfdeploy_inputs_timeout') end it "all the keys should be symbols in config" do