diff --git a/libraries/delivery_api_client.rb b/libraries/delivery_api_client.rb index 436e182..48c18a3 100644 --- a/libraries/delivery_api_client.rb +++ b/libraries/delivery_api_client.rb @@ -33,34 +33,32 @@ def self.blocked_projects(node) uri = URI.parse(change['delivery_api_url']) http_client = Net::HTTP.new(uri.host, uri.port) - if uri.scheme == "https" + if uri.scheme == 'https' http_client.use_ssl = true http_client.verify_mode = OpenSSL::SSL::VERIFY_NONE end result = http_client.get(request_url, get_headers(change['token'])) - case - when result.code == "404" + if result.code == '404' Chef::Log.info("HTTP 404 recieved from #{request_url}. Please upgrade your Delivery Server.") [] - when result.code.match(/20\d/) + elsif result.code.match(/20\d/) JSON.parse(result.body)['blocked_projects'] else # not success or 404 error_str = "Failed request to #{request_url} returned #{result.code}" Chef::Log.fatal(error_str) - raise BadApiResponse.new(error_str) + raise BadApiResponse, error_str end end def self.get_headers(token) - {"chef-delivery-token" => token, - "chef-delivery-user" => 'builder'} + { 'chef-delivery-token' => token, + 'chef-delivery-user' => 'builder' } end def self.get_change_hash(node) change_file = ::File.read(::File.expand_path('../../../../../../../change.json', node['delivery_builder']['workspace'])) change_hash = ::JSON.parse(change_file) end - end end diff --git a/libraries/delivery_truck_deploy.rb b/libraries/delivery_truck_deploy.rb index 0b5235e..804e822 100644 --- a/libraries/delivery_truck_deploy.rb +++ b/libraries/delivery_truck_deploy.rb @@ -47,7 +47,7 @@ def get_search search << " AND chef_environment:#{delivery_environment}" unless search =~ /chef_environment/ # We will search only on nodes that has push-jobs - search << " AND recipes:push-jobs*" + search << ' AND recipes:push-jobs*' end end end @@ -63,8 +63,8 @@ def dec_timeout(number) def deploy_ccr origin = timeout - ::Chef::Log.info("Will wait up to #{timeout/60} minutes for " + - "deployment to complete...") + ::Chef::Log.info("Will wait up to #{timeout / 60} minutes for " + + 'deployment to complete...') begin # Sleep unless this is our first time through the loop. @@ -76,7 +76,7 @@ def deploy_ccr if !nodes || nodes.empty? # We didn't find any node to deploy. Lets skip this phase! - ::Chef::Log.info("No dependency/app nodes found. Skipping phase!") + ::Chef::Log.info('No dependency/app nodes found. Skipping phase!') break end @@ -91,26 +91,26 @@ def deploy_ccr # Kick off command via push. ::Chef::Log.info("Triggering #{new_resource.command} on dependency nodes " + - "with Chef Push Jobs...") + 'with Chef Push Jobs...') req = { 'command' => new_resource.command, - 'nodes' => node_names + 'nodes' => node_names, } resp = chef_server_rest.post('/pushy/jobs', req) job_uri = resp['uri'] unless job_uri # We were not able to start the push job. - ::Chef::Log.info("Could not start push job. " + + ::Chef::Log.info('Could not start push job. ' + "Will try again in #{SLEEP_TIME} seconds...") next end - ::Chef::Log.info("Started push job with id: #{job_uri[-32,32]}") - previous_state = "initialized" + ::Chef::Log.info("Started push job with id: #{job_uri[-32, 32]}") + previous_state = 'initialized' begin - sleep(PUSH_SLEEP_TIME) unless previous_state == "initialized" + sleep(PUSH_SLEEP_TIME) unless previous_state == 'initialized' job = chef_server_rest.get_rest(job_uri) case job['status'] when 'new' @@ -146,15 +146,15 @@ def deploy_ccr ## Check for success if finished && job['nodes']['succeeded'] && job['nodes']['succeeded'].size == nodes.size - ::Chef::Log.info("Deployment complete in " + - "#{(origin-timeout)/60} minutes. " + - "Deploy Successful!") + ::Chef::Log.info('Deployment complete in ' + + "#{(origin - timeout) / 60} minutes. " + + 'Deploy Successful!') break elsif finished == true && job['nodes']['failed'] || job['nodes']['unavailable'] - ::Chef::Log.info("Deployment failed on the following nodes with status: ") + ::Chef::Log.info('Deployment failed on the following nodes with status: ') ::Chef::Log.info(" => Failed: #{job['nodes']['failed']}.") if job['nodes']['failed'] ::Chef::Log.info(" => Unavailable: #{job['nodes']['unavailable']}.") if job['nodes']['unavailable'] - raise "Deployment failed! Not all nodes were successful." + raise 'Deployment failed! Not all nodes were successful.' end dec_timeout(PUSH_SLEEP_TIME) @@ -165,9 +165,9 @@ def deploy_ccr ## If we make it here and we are past our timeout the job timed out ## waiting for the push job. if timeout <= 0 - ::Chef::Log.error("Timed out after #{origin/60} minutes waiting "+ - "for push job. Deploy Failed...") - raise "Timeout waiting for deploy..." + ::Chef::Log.error("Timed out after #{origin / 60} minutes waiting " + + 'for push job. Deploy Failed...') + raise 'Timeout waiting for deploy...' end dec_timeout(SLEEP_TIME) @@ -175,9 +175,9 @@ def deploy_ccr ## If we make it here and we are past our timeout the job timed out. if timeout <= 0 - ::Chef::Log.error("Timed out after #{origin/60} minutes waiting "+ - "for deployment to complete. Deploy Failed...") - raise "Timeout waiting for deploy..." + ::Chef::Log.error("Timed out after #{origin / 60} minutes waiting " + + 'for deployment to complete. Deploy Failed...') + raise 'Timeout waiting for deploy...' end # we survived @@ -194,12 +194,12 @@ class DeliveryTruckDeploy < Chef::Resource::LWRPBase default_action :run - attribute :command, :kind_of => String, :default => 'chef-client' - attribute :timeout, :kind_of => Integer, :default => 30 * 60 # 30 mins - attribute :search, :kind_of => String + attribute :command, kind_of: String, default: 'chef-client' + attribute :timeout, kind_of: Integer, default: 30 * 60 # 30 mins + attribute :search, kind_of: String self.resource_name = :delivery_truck_deploy - def initialize(name, run_context=nil) + def initialize(name, run_context = nil) super @provider = Chef::Provider::DeliveryTruckDeploy end diff --git a/libraries/dsl.rb b/libraries/dsl.rb index ee0af39..360cc17 100644 --- a/libraries/dsl.rb +++ b/libraries/dsl.rb @@ -24,6 +24,6 @@ require_relative 'helpers_deploy' # And these mix the DSL methods into the Chef infrastructure -Chef::Recipe.send(:include, DeliveryTruck::DSL) +Chef::DSL::Recipe.send(:include, DeliveryTruck::DSL) Chef::Resource.send(:include, DeliveryTruck::DSL) -Chef::Provider.send(:include, DeliveryTruck::DSL) +Chef::DSL::Recipe.send(:include, DeliveryTruck::DSL) diff --git a/libraries/helpers_lint.rb b/libraries/helpers_lint.rb index 0fde306..67dc2d0 100644 --- a/libraries/helpers_lint.rb +++ b/libraries/helpers_lint.rb @@ -26,37 +26,34 @@ module Lint # @param node [Chef::Node] Chef Node object # @return [String] def foodcritic_tags(node) - begin - config = node['delivery']['config']['delivery-truck']['lint']['foodcritic'] + config = node['delivery']['config']['delivery-truck']['lint']['foodcritic'] - # We ignore these two by default since they search for the presence of - # `issues_url` and `source_url` in the metadata.rb. Those fields will - # only be populated by cookbooks uploading to Supermarket. - default_ignore = "-t ~FC064 -t ~FC065" + # We ignore these two by default since they search for the presence of + # `issues_url` and `source_url` in the metadata.rb. Those fields will + # only be populated by cookbooks uploading to Supermarket. + default_ignore = '-t ~FC064 -t ~FC065' - # Do not ignore these rules if the cookbook will be share to Supermarket - if ::DeliveryTruck::Helpers::Publish.share_cookbook_to_supermarket?(node) - default_ignore = "" - end + # Do not ignore these rules if the cookbook will be share to Supermarket + if ::DeliveryTruck::Helpers::Publish.share_cookbook_to_supermarket?(node) + default_ignore = '' + end - case - when config.nil? - default_ignore - when config['only_rules'] && !config['only_rules'].empty? - "-t " + config['only_rules'].join(",") - when config['ignore_rules'].nil? - default_ignore - when config['ignore_rules'].empty? - # They can set ignore_rules to an empty Array to disable these defaults - "" - when config['ignore_rules'] && !config['ignore_rules'].empty? - "-t ~" + config['ignore_rules'].join(" -t ~") - else - "" - end - rescue - "" + if config.nil? + default_ignore + elsif config['only_rules'] && !config['only_rules'].empty? + '-t ' + config['only_rules'].join(',') + elsif config['ignore_rules'].nil? + default_ignore + elsif config['ignore_rules'].empty? + # They can set ignore_rules to an empty Array to disable these defaults + '' + elsif config['ignore_rules'] && !config['ignore_rules'].empty? + '-t ~' + config['ignore_rules'].join(' -t ~') + else + '' end + rescue + '' end # Based on the properties in the Delivery Config, create the --excludes @@ -65,17 +62,14 @@ def foodcritic_tags(node) # @param node [Chef::Node] Chef Node object # @return [String] def foodcritic_excludes(node) - begin - config = node['delivery']['config']['delivery-truck']['lint']['foodcritic'] - case - when config['excludes'] && !config['excludes'].empty? - "--exclude " + config['excludes'].join(" --exclude ") - else - "" - end - rescue - "" + config = node['delivery']['config']['delivery-truck']['lint']['foodcritic'] + if config['excludes'] && !config['excludes'].empty? + '--exclude ' + config['excludes'].join(' --exclude ') + else + '' end + rescue + '' end # Based on the properties in the Delivery Config, create the --epic_fail @@ -85,8 +79,7 @@ def foodcritic_excludes(node) # @return [String] def foodcritic_fail_tags(node) config = node['delivery']['config']['delivery-truck']['lint']['foodcritic'] - case - when config['fail_tags'] && !config['fail_tags'].empty? + if config['fail_tags'] && !config['fail_tags'].empty? '-f ' + config['fail_tags'].join(',') else '-f correctness' @@ -94,6 +87,7 @@ def foodcritic_fail_tags(node) rescue '-f correctness' end + # Read the Delivery Config to see if the user has indicated they want to # run cookstyle tests on their cookbook # @@ -104,12 +98,10 @@ def cookstyle_enabled?(node) rescue false end - end end module DSL - # Return the applicable tags for foodcritic runs def foodcritic_tags DeliveryTruck::Helpers::Lint.foodcritic_tags(node) diff --git a/libraries/helpers_provision.rb b/libraries/helpers_provision.rb index 93bfa37..6589c2d 100644 --- a/libraries/helpers_provision.rb +++ b/libraries/helpers_provision.rb @@ -64,7 +64,7 @@ def handle_acceptance_pinnings(node, acceptance_env_name, get_all_project_cookbo promote_cookbook_versions(union_env, acceptance_env) if acceptance_env.override_attributes && !acceptance_env.override_attributes.empty? && - acceptance_env.override_attributes['applications'] != nil + !acceptance_env.override_attributes['applications'].nil? union_apps = union_env.override_attributes['applications'] acceptance_env.override_attributes['applications'].merge!(union_apps) unless union_apps.nil? else @@ -173,7 +173,7 @@ def cleanup_union_changes(union_env, node) # so we promote all cookbook_versions, default_attributes, and # override_attributes (not just for the current project, but everything # in from_env). - def handle_delivered_pinnings(node) + def handle_delivered_pinnings(_node) to_env_name = 'delivered' from_env_name = 'rehearsal' @@ -211,7 +211,7 @@ def project_name(node) def fetch_or_create_environment(env_name) env = Chef::Environment.load(env_name) rescue Net::HTTPServerException => http_e - raise http_e unless http_e.response.code == "404" + raise http_e unless http_e.response.code == '404' chef_log.info("Creating Environment #{env_name}") env = Chef::Environment.new() env.name(env_name) @@ -324,11 +324,10 @@ def promote_project_cookbooks(node, promoted_from_env, promoted_on_env, project_ all_project_cookbooks.each do |pin| from_v = promoted_from_env.cookbook_versions[pin] to_v = promoted_on_env.cookbook_versions[pin] - if from_v - chef_log.info("Promoting #{pin} @ #{from_v} from #{promoted_from_env.name}" + - " to #{promoted_on_env.name} was @ #{to_v}.") - promoted_on_env.cookbook_versions[pin] = from_v - end + next unless from_v + chef_log.info("Promoting #{pin} @ #{from_v} from #{promoted_from_env.name}" + + " to #{promoted_on_env.name} was @ #{to_v}.") + promoted_on_env.cookbook_versions[pin] = from_v end end @@ -347,11 +346,10 @@ def promote_project_apps(node, promoted_from_env, promoted_on_env) node['delivery']['project_apps'].each do |app| from_v = promoted_from_env.override_attributes['applications'][app] to_v = promoted_on_env.override_attributes['applications'][app] - if from_v - chef_log.info("Promoting #{app} @ #{from_v} from #{promoted_from_env.name}" + - " to #{promoted_on_env.name} was @ #{to_v}.") - promoted_on_env.override_attributes['applications'][app] = from_v - end + next unless from_v + chef_log.info("Promoting #{app} @ #{from_v} from #{promoted_from_env.name}" + + " to #{promoted_on_env.name} was @ #{to_v}.") + promoted_on_env.override_attributes['applications'][app] = from_v end end @@ -377,7 +375,7 @@ def promote_unblocked_cookbooks_and_applications(promoted_from_env, promoted_on_ promoted_from_env.default_attributes['delivery']['project_artifacts'].each do |project_name, project_contents| if blocked.include?(project_name) chef_log.info("Project #{project_name} is currently blocked." + - "not promoting its cookbooks or applications") + 'not promoting its cookbooks or applications') else chef_log.info("Promoting cookbooks and applications for project #{project_name}") diff --git a/libraries/helpers_syntax.rb b/libraries/helpers_syntax.rb index 63f504d..af82e79 100644 --- a/libraries/helpers_syntax.rb +++ b/libraries/helpers_syntax.rb @@ -63,7 +63,7 @@ def bumped_version?(path, node) templates\/.* ).join('|') - clean_relative_dir = relative_dir == "." ? "" : Regexp.escape("#{relative_dir}/") + clean_relative_dir = relative_dir == '.' ? '' : Regexp.escape("#{relative_dir}/") if modified_files.any? { |f| /^#{clean_relative_dir}(#{files_to_check})/ =~ f } base = change.merge_sha.empty? ? "origin/#{change.pipeline}" : "#{change.merge_sha}~1" diff --git a/libraries/matchers.rb b/libraries/matchers.rb index 598f3d1..1978980 100644 --- a/libraries/matchers.rb +++ b/libraries/matchers.rb @@ -14,13 +14,3 @@ # See the License for the specific language governing permissions and # limitations under the License. # - -if defined?(ChefSpec) - def create_chef_environment(resource_name) - ChefSpec::Matchers::ResourceMatcher.new(:chef_environment, :create, resource_name) - end - - def run_delivery_truck_deploy(resource_name) - ChefSpec::Matchers::ResourceMatcher.new(:delivery_truck_deploy, :run, resource_name) - end -end diff --git a/recipes/default.rb b/recipes/default.rb index 4d3d87b..af58d59 100644 --- a/recipes/default.rb +++ b/recipes/default.rb @@ -28,7 +28,7 @@ compile_time false only_if do require 'chef-dk/version' - Gem::Version.new(::ChefDK::VERSION) < Gem::Version.new('0.14') + Gem::Version.new(::ChefCLI::VERSION) < Gem::Version.new('0.14') end only_if { share_cookbook_to_supermarket? } action :install diff --git a/recipes/publish.rb b/recipes/publish.rb index 2c628de..7887a04 100644 --- a/recipes/publish.rb +++ b/recipes/publish.rb @@ -28,12 +28,12 @@ if use_custom_supermarket_credentials? secrets = get_project_secrets if secrets['supermarket_user'].nil? || secrets['supermarket_user'].empty? - raise RuntimeError, 'If supermarket-custom-credentials is set to true, ' \ + raise 'If supermarket-custom-credentials is set to true, ' \ 'you must add supermarket_user to the secrets data bag.' end if secrets['supermarket_key'].nil? || secrets['supermarket_key'].nil? - raise RuntimeError, 'If supermarket-custom-credentials is set to true, ' \ + raise 'If supermarket-custom-credentials is set to true, ' \ 'you must add supermarket_key to the secrets data bag.' end end diff --git a/recipes/syntax.rb b/recipes/syntax.rb index 9076f65..c16c49d 100644 --- a/recipes/syntax.rb +++ b/recipes/syntax.rb @@ -19,8 +19,7 @@ # If we changed a cookbook but didn't bump the version than the build # phase will fail when trying to upload to the Chef Server. unless bumped_version?(cookbook.path) - raise RuntimeError, -%{The #{cookbook.name} cookbook was modified but the version was not updated in the metadata file. + raise %{The #{cookbook.name} cookbook was modified but the version was not updated in the metadata file. The version must be updated when any of the following files are modified: metadata.(rb|json) @@ -55,13 +54,12 @@ if ::File.exist?(berksfile) content = ::File.read(berksfile) %W(delivery-sugar delivery-truck).each do |build_cookbook| - if content.include?("chef-cookbooks/#{build_cookbook}") - log "warning_#{build_cookbook}_pull_from_github" do - message "Your build-cookbook depends on #{build_cookbook} that is being pulled " \ - 'from Github, please modify your Berksfile so that you consume it from ' \ - 'Supermarket instead.' - level :warn - end + next unless content.include?("chef-cookbooks/#{build_cookbook}") + log "warning_#{build_cookbook}_pull_from_github" do + message "Your build-cookbook depends on #{build_cookbook} that is being pulled " \ + 'from Github, please modify your Berksfile so that you consume it from ' \ + 'Supermarket instead.' + level :warn end end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 4cc361e..e2069c3 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,7 +1,7 @@ require 'chefspec' -TOPDIR = File.expand_path(File.join(File.dirname(__FILE__), "..")) -$: << File.expand_path(File.dirname(__FILE__)) +TOPDIR = File.expand_path(File.join(File.dirname(__FILE__), '..')) +$: << __dir__ # Require all our libraries Dir['libraries/*.rb'].each { |f| require File.expand_path(f) } @@ -71,36 +71,40 @@ def initialize(options = {}) module SharedLetDeclarations extend RSpec::SharedContext - let(:one_changed_cookbook) {[ - double( - 'delivery sugar cookbook', - :name => 'julia', - :path => '/tmp/repo/cookbooks/julia', - :version => '0.1.0' - ) - ]} - - let(:two_changed_cookbooks) {[ - double( - 'delivery sugar cookbook', - :name => 'julia', - :path => '/tmp/repo/cookbooks/julia', - :version => '0.1.0' - ), - double( - 'delivery sugar cookbook', - :name => 'gordon', - :path => '/tmp/repo/cookbooks/gordon', - :version => '0.2.0' - ) - ]} - - let(:no_changed_cookbooks) {[]} + let(:one_changed_cookbook) do + [ + double( + 'delivery sugar cookbook', + name: 'julia', + path: '/tmp/repo/cookbooks/julia', + version: '0.1.0' + ), + ] + end + + let(:two_changed_cookbooks) do + [ + double( + 'delivery sugar cookbook', + name: 'julia', + path: '/tmp/repo/cookbooks/julia', + version: '0.1.0' + ), + double( + 'delivery sugar cookbook', + name: 'gordon', + path: '/tmp/repo/cookbooks/gordon', + version: '0.2.0' + ), + ] + end + + let(:no_changed_cookbooks) { [] } end RSpec.configure do |config| config.include SharedLetDeclarations - config.filter_run_excluding :ignore => true + config.filter_run_excluding ignore: true config.filter_run focus: true config.run_all_when_everything_filtered = true diff --git a/spec/unit/libraries/delivery_api_client_specs.rb b/spec/unit/libraries/delivery_api_client_specs.rb index f0a902c..1a85b12 100644 --- a/spec/unit/libraries/delivery_api_client_specs.rb +++ b/spec/unit/libraries/delivery_api_client_specs.rb @@ -3,8 +3,8 @@ describe DeliveryTruck::DeliveryApiClient do let(:node) do { - 'delivery' => { 'change' => {'enterprise' => 'Example_Enterprise'} }, - 'delivery_builder' => { 'workspace' => '/var/opt/delivery/workspace' } + 'delivery' => { 'change' => { 'enterprise' => 'Example_Enterprise' } }, + 'delivery_builder' => { 'workspace' => '/var/opt/delivery/workspace' }, } end @@ -43,14 +43,14 @@ let(:api_port) { 80 } it 'does not set ssl settings' do - expect(Net::HTTP). - to receive(:new). - with(api_host, api_port). - and_return(http_client) - expect(http_client). - to receive(:get). - with(blocked_project_api, expected_headers). - and_return(OpenStruct.new({:code => "404"})) + expect(Net::HTTP) + .to receive(:new) + .with(api_host, api_port) + .and_return(http_client) + expect(http_client) + .to receive(:get) + .with(blocked_project_api, expected_headers) + .and_return(OpenStruct.new({ code: '404' })) result = DeliveryTruck::DeliveryApiClient.blocked_projects(node) expect(result).to eql([]) end @@ -58,20 +58,20 @@ context 'when api url is https' do it 'sets use ssl to true' do - expect(Net::HTTP). - to receive(:new). - with(api_host, api_port). - and_return(http_client) - expect(http_client). - to receive(:use_ssl=). - with(true) - expect(http_client). - to receive(:verify_mode=). - with(OpenSSL::SSL::VERIFY_NONE) - expect(http_client). - to receive(:get). - with(blocked_project_api, expected_headers). - and_return(OpenStruct.new({:code => "404"})) + expect(Net::HTTP) + .to receive(:new) + .with(api_host, api_port) + .and_return(http_client) + expect(http_client) + .to receive(:use_ssl=) + .with(true) + expect(http_client) + .to receive(:verify_mode=) + .with(OpenSSL::SSL::VERIFY_NONE) + expect(http_client) + .to receive(:get) + .with(blocked_project_api, expected_headers) + .and_return(OpenStruct.new({ code: '404' })) result = DeliveryTruck::DeliveryApiClient.blocked_projects(node) expect(result).to eql([]) end @@ -79,28 +79,28 @@ context 'responses' do before(:each) do - allow(Net::HTTP). - to receive(:new). - with(api_host, api_port). - and_return(http_client) - allow(http_client). - to receive(:use_ssl=). - with(true) - allow(http_client). - to receive(:verify_mode=). - with(OpenSSL::SSL::VERIFY_NONE) + allow(Net::HTTP) + .to receive(:new) + .with(api_host, api_port) + .and_return(http_client) + allow(http_client) + .to receive(:use_ssl=) + .with(true) + allow(http_client) + .to receive(:verify_mode=) + .with(OpenSSL::SSL::VERIFY_NONE) end context 'when server returns an error' do before do - expect(http_client). - to receive(:get). - with(blocked_project_api, expected_headers). - and_return(OpenStruct.new({:code => error_code})) + expect(http_client) + .to receive(:get) + .with(blocked_project_api, expected_headers) + .and_return(OpenStruct.new({ code: error_code })) end context 'status 404' do - let(:error_code) { "404" } + let(:error_code) { '404' } it 'returns empty array' do result = DeliveryTruck::DeliveryApiClient.blocked_projects(node) @@ -109,15 +109,15 @@ end context 'status not 404' do - let(:error_code) { "500" } + let(:error_code) { '500' } it 'logs and reraises' do # Swallow error reporting, to avoid cluttering test output - allow(Chef::Log). - to receive(:error) + allow(Chef::Log) + .to receive(:error) - expect{DeliveryTruck::DeliveryApiClient.blocked_projects(node)}. - to raise_exception(DeliveryTruck::DeliveryApiClient::BadApiResponse) + expect { DeliveryTruck::DeliveryApiClient.blocked_projects(node) } + .to raise_exception(DeliveryTruck::DeliveryApiClient::BadApiResponse) end end end @@ -126,26 +126,26 @@ let(:http_response) { double 'Net::HTTPOK' } let(:json_response) do JSON.generate({ - 'blocked_projects' => ['project_name_1', 'project_name_2'] + 'blocked_projects' => %w(project_name_1 project_name_2), }) end before do - expect(http_response). - to receive(:body). - and_return(json_response) - allow(http_response). - to receive(:code). - and_return("200") - expect(http_client). - to receive(:get). - with(blocked_project_api, expected_headers). - and_return(http_response) + expect(http_response) + .to receive(:body) + .and_return(json_response) + allow(http_response) + .to receive(:code) + .and_return('200') + expect(http_client) + .to receive(:get) + .with(blocked_project_api, expected_headers) + .and_return(http_response) end it 'returns deserialized list' do result = DeliveryTruck::DeliveryApiClient.blocked_projects(node) - expect(result).to eql(['project_name_1', 'project_name_2']) + expect(result).to eql(%w(project_name_1 project_name_2)) end end end diff --git a/spec/unit/libraries/helpers_deploy_spec.rb b/spec/unit/libraries/helpers_deploy_spec.rb index 0345c32..be1d64f 100644 --- a/spec/unit/libraries/helpers_deploy_spec.rb +++ b/spec/unit/libraries/helpers_deploy_spec.rb @@ -11,7 +11,7 @@ end context 'when config value is set' do - let(:custom_search){ 'cool:attributes OR awful:constraints' } + let(:custom_search) { 'cool:attributes OR awful:constraints' } it 'returns the custom search query' do node.default['delivery']['config']['delivery-truck']['deploy']['search'] = custom_search expect(described_class.deployment_search_query(node)).to eql(custom_search) diff --git a/spec/unit/libraries/helpers_functional_spec.rb b/spec/unit/libraries/helpers_functional_spec.rb index f3569f5..a96c62d 100644 --- a/spec/unit/libraries/helpers_functional_spec.rb +++ b/spec/unit/libraries/helpers_functional_spec.rb @@ -1,7 +1,6 @@ require 'spec_helper' describe DeliveryTruck::Helpers::Functional do - describe '.has_kitchen_tests?' do context 'when .kitchen.docker.yml file is present' do before do diff --git a/spec/unit/libraries/helpers_lint_spec.rb b/spec/unit/libraries/helpers_lint_spec.rb index eb55d7f..7831a66 100644 --- a/spec/unit/libraries/helpers_lint_spec.rb +++ b/spec/unit/libraries/helpers_lint_spec.rb @@ -10,7 +10,7 @@ end it 'ignores issues_url and source_url rules by default' do - expect(described_class.foodcritic_tags(node)).to eql "-t ~FC064 -t ~FC065" + expect(described_class.foodcritic_tags(node)).to eql '-t ~FC064 -t ~FC065' end end @@ -20,7 +20,7 @@ end it 'does not ignores issues_url and source_url rules' do - expect(described_class.foodcritic_tags(node)).to eql "" + expect(described_class.foodcritic_tags(node)).to eql '' end end @@ -30,7 +30,7 @@ end it 'ignores issues_url and source_url rules by default' do - expect(described_class.foodcritic_tags(node)).to eql "-t ~FC064 -t ~FC065" + expect(described_class.foodcritic_tags(node)).to eql '-t ~FC064 -t ~FC065' end end @@ -41,7 +41,7 @@ end it 'ignores issues_url and source_url rules by default' do - expect(described_class.foodcritic_tags(node)).to eql "-t ~FC064 -t ~FC065" + expect(described_class.foodcritic_tags(node)).to eql '-t ~FC064 -t ~FC065' end end @@ -51,17 +51,17 @@ end it 'returns a string with the one rule' do - expect(described_class.foodcritic_tags(node)).to eql "-t FC001" + expect(described_class.foodcritic_tags(node)).to eql '-t FC001' end end context 'with multiple rules' do before do - node.default['delivery']['config']['delivery-truck']['lint']['foodcritic']['only_rules'] = ['FC001', 'FC002'] + node.default['delivery']['config']['delivery-truck']['lint']['foodcritic']['only_rules'] = %w(FC001 FC002) end it 'returns a string with multiple rules' do - expect(described_class.foodcritic_tags(node)).to eql "-t FC001,FC002" + expect(described_class.foodcritic_tags(node)).to eql '-t FC001,FC002' end end end @@ -73,7 +73,7 @@ end it 'ignores issues_url and source_url rules by default' do - expect(described_class.foodcritic_tags(node)).to eql "" + expect(described_class.foodcritic_tags(node)).to eql '' end end @@ -83,17 +83,17 @@ end it 'returns a string with the one rule' do - expect(described_class.foodcritic_tags(node)).to eql "-t ~FC001" + expect(described_class.foodcritic_tags(node)).to eql '-t ~FC001' end end context 'with multiple rules' do before do - node.default['delivery']['config']['delivery-truck']['lint']['foodcritic']['ignore_rules'] = ['FC001', 'FC002'] + node.default['delivery']['config']['delivery-truck']['lint']['foodcritic']['ignore_rules'] = %w(FC001 FC002) end it 'returns a string with multiple rules' do - expect(described_class.foodcritic_tags(node)).to eql "-t ~FC001 -t ~FC002" + expect(described_class.foodcritic_tags(node)).to eql '-t ~FC001 -t ~FC002' end end end @@ -105,7 +105,7 @@ end it 'only `only_rules` values are honored' do - expect(described_class.foodcritic_tags(node)). to eql "-t FC001" + expect(described_class.foodcritic_tags(node)). to eql '-t FC001' end end @@ -116,7 +116,7 @@ end it 'returns an empty string' do - expect(described_class.foodcritic_excludes(node)).to eql "" + expect(described_class.foodcritic_excludes(node)).to eql '' end end @@ -126,17 +126,17 @@ end it 'returns a string with the one exclude' do - expect(described_class.foodcritic_excludes(node)).to eql "--exclude spec" + expect(described_class.foodcritic_excludes(node)).to eql '--exclude spec' end end context 'with multiple paths' do before do - node.default['delivery']['config']['delivery-truck']['lint']['foodcritic']['excludes'] = ['spec', 'test'] + node.default['delivery']['config']['delivery-truck']['lint']['foodcritic']['excludes'] = %w(spec test) end it 'returns a string with multiple excludes' do - expect(described_class.foodcritic_excludes(node)).to eql "--exclude spec --exclude test" + expect(described_class.foodcritic_excludes(node)).to eql '--exclude spec --exclude test' end end end @@ -164,11 +164,11 @@ context 'with multiple rules' do before do - node.default['delivery']['config']['delivery-truck']['lint']['foodcritic']['fail_tags'] = ['correctness', 'metadata'] + node.default['delivery']['config']['delivery-truck']['lint']['foodcritic']['fail_tags'] = %w(correctness metadata) end it 'returns a string with multiple rules' do - expect(described_class.foodcritic_fail_tags(node)).to eql "-f correctness,metadata" + expect(described_class.foodcritic_fail_tags(node)).to eql '-f correctness,metadata' end end end diff --git a/spec/unit/libraries/helpers_provision_spec.rb b/spec/unit/libraries/helpers_provision_spec.rb index fb83be8..d2fc6b0 100644 --- a/spec/unit/libraries/helpers_provision_spec.rb +++ b/spec/unit/libraries/helpers_provision_spec.rb @@ -17,9 +17,9 @@ 'delivery' => { 'change' => { 'project' => project_name, - 'change_id' => change_id - } - } + 'change_id' => change_id, + }, + }, } end @@ -75,7 +75,6 @@ subject.provision stage_name, node, acceptance_env_name, cookbooks end - end end @@ -84,7 +83,7 @@ { project_name => '= 0.3.0', 'cookbook-1' => '= 1.2.0', - 'cookbook-2' => '= 2.0.0' + 'cookbook-2' => '= 2.0.0', } end @@ -98,7 +97,7 @@ context 'when the project is a cookbook' do it 'returns the cookbook version pinning' do expected_cookbook_pinnings = { - project_name => '= 0.3.0' + project_name => '= 0.3.0', } cookbook_pinnings = described_class.project_cookbook_version_pins_from_env(node, env) @@ -108,14 +107,14 @@ describe 'when the repository contains multiple project cookbooks' do before(:each) do - node_attributes['delivery']['project_cookbooks'] = ['cookbook-1', - 'cookbook-2'] + node_attributes['delivery']['project_cookbooks'] = %w(cookbook-1 + cookbook-2) end it 'returns the version pinnings of the project cookbooks' do expected_cookbook_pinnings = { 'cookbook-1' => '= 1.2.0', - 'cookbook-2' => '= 2.0.0' + 'cookbook-2' => '= 2.0.0', } cookbook_pinnings = described_class.project_cookbook_version_pins_from_env(node, env) @@ -129,7 +128,7 @@ env = Chef::Environment.new env.name('test-env') env.override_attributes = { - 'applications' => application_versions + 'applications' => application_versions, } env end @@ -146,7 +145,7 @@ context 'when the project is an application' do let(:application_versions) do { - project_name => '0_3_562' + project_name => '0_3_562', } end @@ -154,7 +153,7 @@ ' application version pinning' do expect( described_class.project_application_version_pins_from_env(node, env) - ).to eq({project_name => '0_3_562'}) + ).to eq({ project_name => '0_3_562' }) end end end @@ -163,12 +162,12 @@ let(:application_versions) do { 'app-1' => '0_3_562', - 'app-2' => '5_0_102' + 'app-2' => '5_0_102', } end before(:each) do - node_attributes['delivery']['project_apps'] = [ 'app-1', 'app-2' ] + node_attributes['delivery']['project_apps'] = %w(app-1 app-2) end it 'sets the applications as the project applications and returns' \ @@ -177,7 +176,7 @@ described_class.project_application_version_pins_from_env(node, env) ).to eq({ 'app-1' => '0_3_562', - 'app-2' => '5_0_102' + 'app-2' => '5_0_102', }) end end @@ -194,7 +193,7 @@ env.name(acceptance_env_name) env.cookbook_versions(acceptance_cookbook_versions) env.override_attributes = { - 'applications' => acceptance_application_versions + 'applications' => acceptance_application_versions, } env end @@ -204,27 +203,27 @@ env.name('union') env.cookbook_versions(union_cookbook_versions) env.override_attributes = { - 'applications' => union_application_versions + 'applications' => union_application_versions, } env end before do - expect(described_class). - to receive(:fetch_or_create_environment). - with(acceptance_env_name). - and_return(acceptance_env) - expect(described_class). - to receive(:fetch_or_create_environment). - with('union'). - and_return(union_env) + expect(described_class) + .to receive(:fetch_or_create_environment) + .with(acceptance_env_name) + .and_return(acceptance_env) + expect(described_class) + .to receive(:fetch_or_create_environment) + .with('union') + .and_return(union_env) expect(acceptance_env).to receive(:save) end context 'when the project is a cookbook' do let(:acceptance_cookbook_versions) do { - project_name => project_version + project_name => project_version, } end @@ -234,13 +233,13 @@ { project_name => project_version_in_union, 'cookbook-1' => '= 1.2.0', - 'cookbook-2' => '= 2.0.0' + 'cookbook-2' => '= 2.0.0', } end let(:union_application_versions) do { - 'delivery-app' => '0_3_562' + 'delivery-app' => '0_3_562', } end @@ -261,17 +260,17 @@ expected_cookbook_versions = { project_name => project_version, 'cookbook-1' => '= 1.2.0', - 'cookbook-2' => '= 2.0.0' + 'cookbook-2' => '= 2.0.0', } expected_application_versions = { - 'delivery-app' => '0_3_562' + 'delivery-app' => '0_3_562', } acceptance_env_result = described_class.handle_acceptance_pinnings(node, acceptance_env_name, get_all_project_cookbooks) - expect(acceptance_env_result.cookbook_versions). - to eq(expected_cookbook_versions) - expect(acceptance_env_result.override_attributes['applications']). - to eq(expected_application_versions) + expect(acceptance_env_result.cookbook_versions) + .to eq(expected_cookbook_versions) + expect(acceptance_env_result.override_attributes['applications']) + .to eq(expected_application_versions) end end @@ -280,21 +279,21 @@ let(:acceptance_application_versions) do { - project_name => project_version + project_name => project_version, } end let(:union_cookbook_versions) do { 'cookbook-1' => '= 1.2.0', - 'cookbook-2' => '= 2.0.0' + 'cookbook-2' => '= 2.0.0', } end let(:union_application_versions) do { project_name => project_version_in_union, - 'delivery-app' => '0_3_562' + 'delivery-app' => '0_3_562', } end @@ -311,18 +310,18 @@ ' version pinning in the acceptance environment' do expected_cookbook_versions = { 'cookbook-1' => '= 1.2.0', - 'cookbook-2' => '= 2.0.0' + 'cookbook-2' => '= 2.0.0', } expected_application_versions = { project_name => project_version, - 'delivery-app' => '0_3_562' + 'delivery-app' => '0_3_562', } acceptance_env_result = described_class.handle_acceptance_pinnings(node, acceptance_env_name, get_all_project_cookbooks) - expect(acceptance_env_result.cookbook_versions). - to eq(expected_cookbook_versions) - expect(acceptance_env_result.override_attributes['applications']). - to eq(expected_application_versions) + expect(acceptance_env_result.cookbook_versions) + .to eq(expected_cookbook_versions) + expect(acceptance_env_result.override_attributes['applications']) + .to eq(expected_application_versions) end end @@ -337,13 +336,13 @@ let(:acceptance_cookbook_versions) do { - project_cookbook_name => project_cookbook_version + project_cookbook_name => project_cookbook_version, } end let(:acceptance_application_versions) do { - project_app_name => project_app_version + project_app_name => project_app_version, } end @@ -351,14 +350,14 @@ { project_cookbook_name => project_cookbook_version_in_union, 'cookbook-1' => '= 1.2.0', - 'cookbook-2' => '= 2.0.0' + 'cookbook-2' => '= 2.0.0', } end let(:union_application_versions) do { project_app_name => project_app_version_in_union, - 'delivery-app' => '0_3_562' + 'delivery-app' => '0_3_562', } end @@ -381,18 +380,18 @@ expected_cookbook_versions = { project_cookbook_name => project_cookbook_version, 'cookbook-1' => '= 1.2.0', - 'cookbook-2' => '= 2.0.0' + 'cookbook-2' => '= 2.0.0', } expected_application_versions = { project_app_name => project_app_version, - 'delivery-app' => '0_3_562' + 'delivery-app' => '0_3_562', } acceptance_env_result = described_class.handle_acceptance_pinnings(node, acceptance_env_name, get_all_project_cookbooks) - expect(acceptance_env_result.cookbook_versions). - to eq(expected_cookbook_versions) - expect(acceptance_env_result.override_attributes['applications']). - to eq(expected_application_versions) + expect(acceptance_env_result.cookbook_versions) + .to eq(expected_cookbook_versions) + expect(acceptance_env_result.override_attributes['applications']) + .to eq(expected_application_versions) end end end @@ -408,7 +407,7 @@ env.name(acceptance_env_name) env.cookbook_versions(acceptance_cookbook_versions) env.override_attributes = { - 'applications' => acceptance_application_versions + 'applications' => acceptance_application_versions, } env end @@ -418,22 +417,22 @@ env.name('union') env.cookbook_versions(union_cookbook_versions) env.override_attributes = { - 'applications' => union_application_versions + 'applications' => union_application_versions, } env end before(:each) do - expect(Chef::Environment). - to receive(:load). - with(acceptance_env_name). - and_return(acceptance_env) - expect(Chef::Environment). - to receive(:load). - with('union'). - and_return(union_env) - expect(union_env). - to receive(:save) + expect(Chef::Environment) + .to receive(:load) + .with(acceptance_env_name) + .and_return(acceptance_env) + expect(Chef::Environment) + .to receive(:load) + .with('union') + .and_return(union_env) + expect(union_env) + .to receive(:save) end let(:passed_in_project_cookbooks) { [] } @@ -443,13 +442,13 @@ let(:acceptance_cookbook_versions) do { - project_name => project_version_in_acceptance } + project_name => project_version_in_acceptance } end let(:union_application_versions) do { 'an_application' => '= 3.2.0', - 'another_application' => '= 2.2.4' + 'another_application' => '= 2.2.4', } end @@ -457,18 +456,18 @@ { project_name => project_version, 'an_cookbook' => '= 0.3.1', - 'another_cookbook' => '= 2.0.0' + 'another_cookbook' => '= 2.0.0', } end context 'when project cookbooks are detected' do - let(:project_cookbook_name) { "changed_cookbook_that_is_not_in_project_cookbook_attributes" } - let(:project_cookbook_version) { "= 0.1.0" } + let(:project_cookbook_name) { 'changed_cookbook_that_is_not_in_project_cookbook_attributes' } + let(:project_cookbook_version) { '= 0.1.0' } let(:acceptance_cookbook_versions) do { project_name => project_version_in_acceptance, - project_cookbook_name => project_cookbook_version + project_cookbook_name => project_cookbook_version, } end @@ -491,10 +490,10 @@ union_env_result = described_class.handle_union_pinnings(node, acceptance_env_name, [project_cookbook]) - expect(union_env_result.cookbook_versions). - to eq(expected_union_cookbook_versions) - expect(union_env_result.override_attributes['applications']). - to eq(union_application_versions) + expect(union_env_result.cookbook_versions) + .to eq(expected_union_cookbook_versions) + expect(union_env_result.override_attributes['applications']) + .to eq(union_application_versions) end it 'does not update pinnings if change id has already been updated' do @@ -506,14 +505,14 @@ modified_acceptance_env.cookbook_versions( acceptance_cookbook_versions.merge(new_cookbook: '1.1.1')) - expect(described_class). - to receive(:fetch_or_create_environment). - with(acceptance_env_name). - and_return(modified_acceptance_env) - expect(described_class). - to receive(:fetch_or_create_environment). - with('union'). - and_return(first_union_env_result) + expect(described_class) + .to receive(:fetch_or_create_environment) + .with(acceptance_env_name) + .and_return(modified_acceptance_env) + expect(described_class) + .to receive(:fetch_or_create_environment) + .with('union') + .and_return(first_union_env_result) seccond_union_env_result = described_class.handle_union_pinnings(node, acceptance_env_name, [project_cookbook]) @@ -532,15 +531,15 @@ # You only populate if acceptance_env.override_attributes['applications'] # actually contains an application named `project_name`, which is # not the case in this test. - 'applications' => [] - } + 'applications' => [], + }, } union_env_result = described_class.handle_union_pinnings(node, acceptance_env_name, passed_in_project_cookbooks) - expect(union_env_result.default_attributes['delivery']['project_artifacts']). - to eq(expected_project_metadata) + expect(union_env_result.default_attributes['delivery']['project_artifacts']) + .to eq(expected_project_metadata) end end @@ -549,18 +548,18 @@ { 'project-foo' => { 'cookbooks' => [], - 'applications' => ['project-foo-app'] + 'applications' => ['project-foo-app'], }, 'project-bar' => { - 'cookbooks' => ['project-bar-1', 'project-bar-1'], - 'applications' => ['project-bar-app'] - } + 'cookbooks' => %w(project-bar-1 project-bar-1), + 'applications' => ['project-bar-app'], + }, } end before(:each) do union_env.default_attributes = { - 'delivery' => { 'project_artifacts' => projects_metadata } + 'delivery' => { 'project_artifacts' => projects_metadata }, } end @@ -568,14 +567,14 @@ expected_projects_metadata = projects_metadata.dup expected_projects_metadata[project_name] = { 'cookbooks' => [project_name], - 'applications' => [] + 'applications' => [], } union_env_result = described_class.handle_union_pinnings(node, acceptance_env_name, passed_in_project_cookbooks) - expect(union_env_result.default_attributes['delivery']['project_artifacts']). - to eq(expected_projects_metadata) + expect(union_env_result.default_attributes['delivery']['project_artifacts']) + .to eq(expected_projects_metadata) end end @@ -584,14 +583,14 @@ { project_name => { 'cookbooks' => ["#{project_name}-1", "#{project_name}-2"], - 'applications' => [] - } + 'applications' => [], + }, } end before(:each) do union_env.default_attributes = { - 'delivery' => { 'project_artifacts' => projects_metadata } + 'delivery' => { 'project_artifacts' => projects_metadata }, } end @@ -599,14 +598,14 @@ expected_projects_metadata = projects_metadata.dup expected_projects_metadata[project_name] = { 'cookbooks' => [project_name], - 'applications' => [] + 'applications' => [], } union_env_result = described_class.handle_union_pinnings(node, acceptance_env_name, passed_in_project_cookbooks) - expect(union_env_result.default_attributes['delivery']['project_artifacts']). - to eq(expected_projects_metadata) + expect(union_env_result.default_attributes['delivery']['project_artifacts']) + .to eq(expected_projects_metadata) end end end @@ -615,13 +614,13 @@ context 'when the project is an application' do let(:acceptance_application_versions) do { - project_name => project_version_in_acceptance + project_name => project_version_in_acceptance, } end let(:acceptance_cookbook_versions) do { - project_name => project_version + project_name => project_version, } end @@ -629,14 +628,14 @@ { project_name => project_version, 'an_application' => '= 3.2.0', - 'another_application' => '= 2.2.4' + 'another_application' => '= 2.2.4', } end let(:union_cookbook_versions) do { 'an_cookbook' => '= 0.3.1', - 'another_cookbook' => '= 2.0.0' + 'another_cookbook' => '= 2.0.0', } end @@ -644,7 +643,7 @@ node.default['delivery']['project_cookbooks'] = nil end - context "cached project metadata" do + context 'cached project metadata' do let(:acceptance_env) do env = Chef::Environment.new() env.name(acceptance_env_name) @@ -653,29 +652,29 @@ 'applications' => { 'app1' => '= 1.0.0', 'app2' => '= 1.0.0', - 'app3' => '= 1.0.0' - } + 'app3' => '= 1.0.0', + }, } env end - it "saved all app names for the current project that have valid values" \ - "in the acceptance env" do - app_names = ["app1", "app2", "app3"] + it 'saved all app names for the current project that have valid values' \ + 'in the acceptance env' do + app_names = %w(app1 app2 app3) node.default['delivery']['project_apps'] = app_names expected_project_metadata = { project_name => { 'cookbooks' => [project_name], - 'applications' => app_names - } + 'applications' => app_names, + }, } union_env_result = described_class.handle_union_pinnings(node, acceptance_env_name, passed_in_project_cookbooks) - expect(union_env_result.default_attributes['delivery']['project_artifacts']). - to eq(expected_project_metadata) + expect(union_env_result.default_attributes['delivery']['project_artifacts']) + .to eq(expected_project_metadata) end end @@ -689,10 +688,10 @@ described_class.handle_union_pinnings(node, acceptance_env_name, passed_in_project_cookbooks) expect(node['delivery']['project_apps']).to eq([project_name]) - expect(union_env_result.cookbook_versions). - to eq(union_cookbook_versions) - expect(union_env_result.override_attributes['applications']). - to eq(expected_union_application_versions) + expect(union_env_result.cookbook_versions) + .to eq(union_cookbook_versions) + expect(union_env_result.override_attributes['applications']) + .to eq(expected_union_application_versions) end end @@ -701,13 +700,13 @@ let(:project_app_version) { '0_3_562' } let(:project_app_version_in_acceptance) { '0_3_563' } - let(:project_cookbook_names) { ['delivery-cookbook-1', 'delivery-cookbook-2'] } + let(:project_cookbook_names) { %w(delivery-cookbook-1 delivery-cookbook-2) } let(:project_cookbook_versions) { ['= 0.3.0', '= 1.0.2'] } let(:project_cookbook_versions_in_acceptance) { ['= 0.3.2', '= 1.0.4'] } let(:acceptance_application_versions) do { - project_app_name => project_app_version_in_acceptance + project_app_name => project_app_version_in_acceptance, } end @@ -722,7 +721,7 @@ { project_app_name => project_app_version, 'an_application' => '= 3.2.0', - 'another_application' => '= 2.2.4' + 'another_application' => '= 2.2.4', } end @@ -731,7 +730,7 @@ project_cookbook_names[0] => project_cookbook_versions[0], project_cookbook_names[1] => project_cookbook_versions[1], 'an_cookbook' => '= 0.3.1', - 'another_cookbook' => '= 2.0.0' + 'another_cookbook' => '= 2.0.0', } end @@ -740,20 +739,20 @@ node.default['delivery']['project_apps'] = [project_app_name] end - describe "cached project metadata" do - it "saved all apps and cookbooks for the current project" do - expected_project_metadata = { - project_name => { - 'cookbooks' => project_cookbook_names, - 'applications' => [project_app_name] - } - } + describe 'cached project metadata' do + it 'saved all apps and cookbooks for the current project' do + expected_project_metadata = { + project_name => { + 'cookbooks' => project_cookbook_names, + 'applications' => [project_app_name], + }, + } - union_env_result = - described_class.handle_union_pinnings(node, acceptance_env_name, passed_in_project_cookbooks) + union_env_result = + described_class.handle_union_pinnings(node, acceptance_env_name, passed_in_project_cookbooks) - expect(union_env_result.default_attributes['delivery']['project_artifacts']). - to eq(expected_project_metadata) + expect(union_env_result.default_attributes['delivery']['project_artifacts']) + .to eq(expected_project_metadata) end end @@ -772,10 +771,10 @@ union_env_result = described_class.handle_union_pinnings(node, acceptance_env_name, []) - expect(union_env_result.cookbook_versions). - to eq(union_cookbook_versions) - expect(union_env_result.override_attributes['applications']). - to eq(expected_union_application_versions) + expect(union_env_result.cookbook_versions) + .to eq(union_cookbook_versions) + expect(union_env_result.override_attributes['applications']) + .to eq(expected_union_application_versions) end end end @@ -785,7 +784,7 @@ { 'app_1' => '0_3_562', 'app_2' => '1_0_205', - 'no_longer_supported_app' => '0_0_50' + 'no_longer_supported_app' => '0_0_50', } end @@ -793,13 +792,13 @@ { 'cookbook_1' => '= 1.2.2', 'cookbook_2' => '= 0.0.9', - 'no_longer_supported_cookbook' => '= 2.3.0' + 'no_longer_supported_cookbook' => '= 2.3.0', } end let(:rehearsal_default_attributes) do { - 'delivery' => { 'project_artifacts' => {} } + 'delivery' => { 'project_artifacts' => {} }, } end @@ -807,7 +806,7 @@ { 'app_1' => '0_3_563', 'app_2' => '1_0_206', - 'new_app' => '0_0_1' + 'new_app' => '0_0_1', } end @@ -815,7 +814,7 @@ { 'cookbook_1' => '= 1.2.3', 'cookbook_2' => '= 0.1.0', - 'new_cookbook' => '= 0.1.0' + 'new_cookbook' => '= 0.1.0', } end @@ -823,35 +822,35 @@ { 'delivery' => { 'union_changes' => [ - change_id + change_id, ], 'project_artifacts' => { 'other_project_1' => { 'cookbooks' => [ - 'cookbook_1' + 'cookbook_1', ], 'applications' => [ - 'app_1' - ] + 'app_1', + ], }, 'other_project_2' => { 'cookbooks' => [ - 'cookbook_2' + 'cookbook_2', ], 'applications' => [ - 'app_2' - ] + 'app_2', + ], }, 'new_project' => { 'cookbooks' => [ - 'new_cookbook' + 'new_cookbook', ], 'applications' => [ - 'new_app' - ] - } - } - } + 'new_app', + ], + }, + }, + }, } end @@ -861,7 +860,7 @@ env.cookbook_versions(rehearsal_cookbook_versions) env.default_attributes = rehearsal_default_attributes env.override_attributes = { - 'applications' => rehearsal_applications + 'applications' => rehearsal_applications, } env end @@ -872,45 +871,45 @@ env.cookbook_versions(union_cookbook_versions) env.default_attributes = union_default_attributes env.override_attributes = { - 'applications' => union_applications + 'applications' => union_applications, } env end before(:each) do - expect(Chef::Environment). - to receive(:load). - with('union'). - and_return(union_env) - expect(Chef::Environment). - to receive(:load). - with('rehearsal'). - and_return(rehearsal_env) - expect(rehearsal_env). - to receive(:save) + expect(Chef::Environment) + .to receive(:load) + .with('union') + .and_return(union_env) + expect(Chef::Environment) + .to receive(:load) + .with('rehearsal') + .and_return(rehearsal_env) + expect(rehearsal_env) + .to receive(:save) expect(union_env).to receive(:save) end it 'removes the change from the union environment change list' do - expect(DeliveryTruck::DeliveryApiClient). - to receive(:blocked_projects). - with(node). - and_return([]) + expect(DeliveryTruck::DeliveryApiClient) + .to receive(:blocked_projects) + .with(node) + .and_return([]) described_class.handle_rehearsal_pinnings(node) expect(union_env.default_attributes['delivery']['union_changes']).to eql([]) end context 'a project with a single cookbook' do - let(:project_version_in_rehearsal) { "= 2.2.0" } - let(:project_version_in_union) { "= 2.2.2" } + let(:project_version_in_rehearsal) { '= 2.2.0' } + let(:project_version_in_union) { '= 2.2.2' } let(:rehearsal_applications) { {} } let(:rehearsal_cookbook_versions) do { project_name => project_version_in_rehearsal, 'cookbook_1' => '= 0.3.0', - 'cookbook_2' => '= 1.4.1' + 'cookbook_2' => '= 1.4.1', } end @@ -919,7 +918,7 @@ { project_name => project_version_in_union, 'cookbook_1' => '= 0.3.1', - 'cookbook_2' => '= 1.4.1' + 'cookbook_2' => '= 1.4.1', } end let(:rehearsal_default_attributes) do @@ -929,25 +928,25 @@ project_name => { 'cookbooks' => [ project_name, - 'vestigal_cookbook' + 'vestigal_cookbook', ], - 'applications' => [] + 'applications' => [], }, 'other_project_1' => { - 'cookbooks' => [ - 'cookbook_1', - 'outdated_cookbook' - ], - 'applications' => [] + 'cookbooks' => %w( + cookbook_1 + outdated_cookbook + ), + 'applications' => [], }, 'other_project_2' => { 'cookbooks' => [ - 'cookbook_2' + 'cookbook_2', ], - 'applications' => [] - } - } - } + 'applications' => [], + }, + }, + }, } end @@ -957,33 +956,33 @@ 'project_artifacts' => { project_name => { 'cookbooks' => [ - project_name + project_name, ], - 'applications' => [] + 'applications' => [], }, 'other_project_1' => { 'cookbooks' => [ - 'cookbook_1' + 'cookbook_1', ], - 'applications' => [] + 'applications' => [], }, 'other_project_2' => { 'cookbooks' => [ - 'cookbook_2' + 'cookbook_2', ], - 'applications' => [] - } - } - } + 'applications' => [], + }, + }, + }, } end context 'when the project is blocked' do before(:each) do - expect(DeliveryTruck::DeliveryApiClient). - to receive(:blocked_projects). - with(node). - and_return([project_name]) + expect(DeliveryTruck::DeliveryApiClient) + .to receive(:blocked_projects) + .with(node) + .and_return([project_name]) end it 'does not update the version pinning for the cookbook in the' \ @@ -991,7 +990,7 @@ expected_cookbook_versions = { project_name => project_version_in_rehearsal, 'cookbook_1' => '= 0.3.1', - 'cookbook_2' => '= 1.4.1' + 'cookbook_2' => '= 1.4.1', } expected_applications = rehearsal_applications.dup @@ -1001,34 +1000,34 @@ project_name => { 'cookbooks' => [ project_name, - 'vestigal_cookbook' + 'vestigal_cookbook', ], - 'applications' => [] + 'applications' => [], }, 'other_project_1' => { 'cookbooks' => [ - 'cookbook_1' + 'cookbook_1', ], - 'applications' => [] + 'applications' => [], }, 'other_project_2' => { 'cookbooks' => [ - 'cookbook_2' + 'cookbook_2', ], - 'applications' => [] - } - } - } + 'applications' => [], + }, + }, + }, } rehearsal_env_result = described_class.handle_rehearsal_pinnings(node) - expect(rehearsal_env_result.cookbook_versions). - to eq(expected_cookbook_versions) - expect(rehearsal_env_result.default_attributes). - to eq(expected_default_attributes) - expect(rehearsal_env_result.override_attributes['applications']). - to eq(expected_applications) + expect(rehearsal_env_result.cookbook_versions) + .to eq(expected_cookbook_versions) + expect(rehearsal_env_result.default_attributes) + .to eq(expected_default_attributes) + expect(rehearsal_env_result.override_attributes['applications']) + .to eq(expected_applications) end # maybe we want to test when node['delivery']['project_cookbooks'] is set @@ -1038,10 +1037,10 @@ context 'when the project is not blocked' do let(:blocked_projects) { [] } before(:each) do - expect(DeliveryTruck::DeliveryApiClient). - to receive(:blocked_projects). - with(node). - and_return(blocked_projects) + expect(DeliveryTruck::DeliveryApiClient) + .to receive(:blocked_projects) + .with(node) + .and_return(blocked_projects) end context 'nothing is blocked' do @@ -1049,18 +1048,18 @@ let(:union_applications) do { - "unknown_application" => "1.1.1", - "other_application" => "0.0.1" + 'unknown_application' => '1.1.1', + 'other_application' => '0.0.1', } end let(:union_cookbook_versions) do - { - project_name => project_version_in_union, - 'cookbook_1' => '= 0.3.1', - 'cookbook_2' => '= 1.4.1', - 'unknown_cookbook' => '= 110.100.100' - } + { + project_name => project_version_in_union, + 'cookbook_1' => '= 0.3.1', + 'cookbook_2' => '= 1.4.1', + 'unknown_cookbook' => '= 110.100.100', + } end it 'moves all version pinnings from union to rehersal' do @@ -1070,12 +1069,12 @@ rehearsal_env_result = described_class.handle_rehearsal_pinnings(node) - expect(rehearsal_env_result.cookbook_versions). - to eq(expected_cookbook_versions) - expect(rehearsal_env_result.default_attributes). - to eq(expected_default_attributes) - expect(rehearsal_env_result.override_attributes['applications']). - to eq(expected_applications) + expect(rehearsal_env_result.cookbook_versions) + .to eq(expected_cookbook_versions) + expect(rehearsal_env_result.default_attributes) + .to eq(expected_default_attributes) + expect(rehearsal_env_result.override_attributes['applications']) + .to eq(expected_applications) end end @@ -1088,68 +1087,68 @@ 'project_artifacts' => { project_name => { 'cookbooks' => [ - project_name + project_name, ], - 'applications' => [] + 'applications' => [], }, 'other_project_1' => { 'cookbooks' => [ - 'cookbook_1' + 'cookbook_1', ], - 'applications' => [] + 'applications' => [], }, 'other_project_2' => { 'cookbooks' => [ - 'cookbook_2' + 'cookbook_2', ], - 'applications' => [] - } - } - } + 'applications' => [], + }, + }, + }, } end it 'does not update the version pinning for the impacted cookbook in' \ ' the rehearsal environment' do - expected_cookbook_versions = { - project_name => project_version_in_union, - 'cookbook_1' => '= 0.3.0', - 'cookbook_2' => '= 1.4.1' } - expected_applications = union_applications.dup - expected_default_attributes = { - 'delivery' => { - 'project_artifacts' => { - project_name => { - 'cookbooks' => [ - project_name - ], - 'applications' => [] - }, - 'other_project_1' => { - 'cookbooks' => [ - 'cookbook_1', - 'outdated_cookbook' - ], - 'applications' => [] - }, - 'other_project_2' => { - 'cookbooks' => [ - 'cookbook_2' - ], - 'applications' => [] - } - } - } - } - - rehearsal_env_result = described_class.handle_rehearsal_pinnings(node) - - expect(rehearsal_env_result.cookbook_versions). - to eq(expected_cookbook_versions) - expect(rehearsal_env_result.default_attributes). - to eq(expected_default_attributes) - expect(rehearsal_env_result.override_attributes['applications']). - to eq(expected_applications) + expected_cookbook_versions = { + project_name => project_version_in_union, + 'cookbook_1' => '= 0.3.0', + 'cookbook_2' => '= 1.4.1' } + expected_applications = union_applications.dup + expected_default_attributes = { + 'delivery' => { + 'project_artifacts' => { + project_name => { + 'cookbooks' => [ + project_name, + ], + 'applications' => [], + }, + 'other_project_1' => { + 'cookbooks' => %w( + cookbook_1 + outdated_cookbook + ), + 'applications' => [], + }, + 'other_project_2' => { + 'cookbooks' => [ + 'cookbook_2', + ], + 'applications' => [], + }, + }, + }, + } + + rehearsal_env_result = described_class.handle_rehearsal_pinnings(node) + + expect(rehearsal_env_result.cookbook_versions) + .to eq(expected_cookbook_versions) + expect(rehearsal_env_result.default_attributes) + .to eq(expected_default_attributes) + expect(rehearsal_env_result.override_attributes['applications']) + .to eq(expected_applications) end end end @@ -1162,12 +1161,14 @@ 'delivery_1' => '= 0.0.0', 'delivery_2' => '= 1.0.0', 'cookbook_1' => '= 0.3.0', - 'cookbook_2' => '= 1.4.1' + 'cookbook_2' => '= 1.4.1', } end - let(:rehearsal_default_attributes) { { - 'delivery' => { 'project_artifacts' => {} } - } } + let(:rehearsal_default_attributes) do + { + 'delivery' => { 'project_artifacts' => {} }, + } + end let(:union_applications) { {} } let(:union_cookbook_versions) do @@ -1175,7 +1176,7 @@ 'delivery_1' => '= 0.0.1', 'delivery_2' => '= 1.0.1', 'cookbook_1' => '= 0.3.1', - 'cookbook_2' => '= 1.4.1' + 'cookbook_2' => '= 1.4.1', } end @@ -1184,26 +1185,26 @@ 'delivery' => { 'project_artifacts' => { project_name => { - 'cookbooks' => [ - 'delivery_1', - 'delivery_2' - ], - 'applications' => [] + 'cookbooks' => %w( + delivery_1 + delivery_2 + ), + 'applications' => [], }, 'other_project_1' => { 'cookbooks' => [ - 'cookbook_1' + 'cookbook_1', ], - 'applications' => [] + 'applications' => [], }, 'other_project_2' => { 'cookbooks' => [ - 'cookbook_2' + 'cookbook_2', ], - 'applications' => [] - } - } - } + 'applications' => [], + }, + }, + }, } end @@ -1212,17 +1213,17 @@ { 'delivery' => { 'change' => { - 'project' => project_name + 'project' => project_name, }, - 'project_cookbooks' => ['delivery_1', 'delivery_2'] - } + 'project_cookbooks' => %w(delivery_1 delivery_2), + }, } end before(:each) do - expect(DeliveryTruck::DeliveryApiClient). - to receive(:blocked_projects). - with(node). - and_return(blocked_projects) + expect(DeliveryTruck::DeliveryApiClient) + .to receive(:blocked_projects) + .with(node) + .and_return(blocked_projects) end context 'nothing is blocked' do @@ -1230,19 +1231,18 @@ it 'updates the version pinning for the cookbook in the rehearsal' \ ' environment' do + expected_cookbook_versions = union_cookbook_versions.dup + expected_applications = union_applications.dup + expected_default_attributes = union_default_attributes.dup - expected_cookbook_versions = union_cookbook_versions.dup - expected_applications = union_applications.dup - expected_default_attributes = union_default_attributes.dup - - rehearsal_env_result = described_class.handle_rehearsal_pinnings(node) + rehearsal_env_result = described_class.handle_rehearsal_pinnings(node) - expect(rehearsal_env_result.cookbook_versions). - to eq(expected_cookbook_versions) - expect(rehearsal_env_result.default_attributes). - to eq(expected_default_attributes) - expect(rehearsal_env_result.override_attributes['applications']). - to eq(expected_applications) + expect(rehearsal_env_result.cookbook_versions) + .to eq(expected_cookbook_versions) + expect(rehearsal_env_result.default_attributes) + .to eq(expected_default_attributes) + expect(rehearsal_env_result.override_attributes['applications']) + .to eq(expected_applications) end context 'when the rehersal delivery attribute has not been initialized' do @@ -1255,12 +1255,12 @@ rehearsal_env_result = described_class.handle_rehearsal_pinnings(node) - expect(rehearsal_env_result.cookbook_versions). - to eq(expected_cookbook_versions) - expect(rehearsal_env_result.default_attributes). - to eq(expected_default_attributes) - expect(rehearsal_env_result.override_attributes['applications']). - to eq(expected_applications) + expect(rehearsal_env_result.cookbook_versions) + .to eq(expected_cookbook_versions) + expect(rehearsal_env_result.default_attributes) + .to eq(expected_default_attributes) + expect(rehearsal_env_result.override_attributes['applications']) + .to eq(expected_applications) end end end @@ -1268,22 +1268,22 @@ context 'the project is blocked' do let(:blocked_projects) { [project_name] } it "does not update this project's project cookbooks but does update" \ - "other cookbooks" do - expected_cookbook_versions = union_cookbook_versions.dup - expected_cookbook_versions['delivery_1']= '= 0.0.0' - expected_cookbook_versions['delivery_2']= '= 1.0.0' - - expected_applications = union_applications.dup - expected_default_attributes = rehearsal_default_attributes.dup - - rehearsal_env_result = described_class.handle_rehearsal_pinnings(node) - - expect(rehearsal_env_result.cookbook_versions). - to eq(expected_cookbook_versions) - expect(rehearsal_env_result.default_attributes). - to eq(expected_default_attributes) - expect(rehearsal_env_result.override_attributes['applications']). - to eq(expected_applications) + 'other cookbooks' do + expected_cookbook_versions = union_cookbook_versions.dup + expected_cookbook_versions['delivery_1'] = '= 0.0.0' + expected_cookbook_versions['delivery_2'] = '= 1.0.0' + + expected_applications = union_applications.dup + expected_default_attributes = rehearsal_default_attributes.dup + + rehearsal_env_result = described_class.handle_rehearsal_pinnings(node) + + expect(rehearsal_env_result.cookbook_versions) + .to eq(expected_cookbook_versions) + expect(rehearsal_env_result.default_attributes) + .to eq(expected_default_attributes) + expect(rehearsal_env_result.override_attributes['applications']) + .to eq(expected_applications) end end end @@ -1294,7 +1294,7 @@ 'our_app_1' => '= 2.0.0', 'our_app_2' => '= 3.0.0', 'app_1' => '= 0.3.0', - 'app_2' => '= 1.4.1' + 'app_2' => '= 1.4.1', } end let(:rehearsal_cookbook_versions) do @@ -1302,7 +1302,7 @@ 'our_cookbook_1' => '= 0.0.0', 'our_cookbook_2' => '= 1.0.0', 'cookbook_1' => '= 0.3.0', - 'cookbook_2' => '= 1.4.1' + 'cookbook_2' => '= 1.4.1', } end @@ -1311,7 +1311,7 @@ 'our_app_1' => '= 2.0.1', 'our_app_2' => '= 3.0.1', 'app_1' => '= 0.3.1', - 'app_2' => '= 1.4.2' + 'app_2' => '= 1.4.2', } end let(:union_cookbook_versions) do @@ -1319,7 +1319,7 @@ 'our_cookbook_1' => '= 0.0.1', 'our_cookbook_2' => '= 1.0.1', 'cookbook_1' => '= 0.3.1', - 'cookbook_2' => '= 1.4.1' + 'cookbook_2' => '= 1.4.1', } end @@ -1328,29 +1328,29 @@ 'delivery' => { 'project_artifacts' => { project_name => { - 'cookbooks' => [ - 'our_cookbook_1', - 'our_cookbook_2' - ], - 'applications' => [ - 'our_app_1', - 'our_app_2', - ] + 'cookbooks' => %w( + our_cookbook_1 + our_cookbook_2 + ), + 'applications' => %w( + our_app_1 + our_app_2 + ), }, 'other_project_1' => { 'cookbooks' => [ 'cookbook_1', ], - 'applications' => [ 'app_1' ] + 'applications' => [ 'app_1' ], }, 'other_project_2' => { 'cookbooks' => [ - 'cookbook_2' + 'cookbook_2', ], - 'applications' => [ 'app_2' ] - } - } - } + 'applications' => [ 'app_2' ], + }, + }, + }, } end @@ -1360,10 +1360,10 @@ context 'when the project is blocked' do before(:each) do - expect(DeliveryTruck::DeliveryApiClient). - to receive(:blocked_projects). - with(node). - and_return([project_name]) + expect(DeliveryTruck::DeliveryApiClient) + .to receive(:blocked_projects) + .with(node) + .and_return([project_name]) end it 'does not update the version pinning for the cookbook or apps in the' \ @@ -1372,22 +1372,22 @@ 'our_cookbook_1' => '= 0.0.0', 'our_cookbook_2' => '= 1.0.0', 'cookbook_1' => '= 0.3.1', - 'cookbook_2' => '= 1.4.1' + 'cookbook_2' => '= 1.4.1', } expected_applications = { 'our_app_1' => '= 2.0.0', 'our_app_2' => '= 3.0.0', 'app_1' => '= 0.3.1', - 'app_2' => '= 1.4.2' + 'app_2' => '= 1.4.2', } rehearsal_env_result = described_class.handle_rehearsal_pinnings(node) - expect(rehearsal_env_result.cookbook_versions). - to eq(expected_cookbook_versions) - expect(rehearsal_env_result.override_attributes['applications']). - to eq(expected_applications) + expect(rehearsal_env_result.cookbook_versions) + .to eq(expected_cookbook_versions) + expect(rehearsal_env_result.override_attributes['applications']) + .to eq(expected_applications) end # maybe we want to test when node['delivery']['project_cookbooks'] is set @@ -1396,10 +1396,10 @@ context 'when a different project is blocked' do before(:each) do - expect(DeliveryTruck::DeliveryApiClient). - to receive(:blocked_projects). - with(node). - and_return(['other_project_1']) + expect(DeliveryTruck::DeliveryApiClient) + .to receive(:blocked_projects) + .with(node) + .and_return(['other_project_1']) end it 'does not update the version pinning for the cookbook or apps in the' \ @@ -1408,28 +1408,27 @@ 'our_cookbook_1' => '= 0.0.1', 'our_cookbook_2' => '= 1.0.1', 'cookbook_1' => '= 0.3.0', - 'cookbook_2' => '= 1.4.1' + 'cookbook_2' => '= 1.4.1', } expected_applications = { 'our_app_1' => '= 2.0.1', 'our_app_2' => '= 3.0.1', 'app_1' => '= 0.3.0', - 'app_2' => '= 1.4.2' + 'app_2' => '= 1.4.2', } rehearsal_env_result = described_class.handle_rehearsal_pinnings(node) - expect(rehearsal_env_result.cookbook_versions). - to eq(expected_cookbook_versions) - expect(rehearsal_env_result.override_attributes['applications']). - to eq(expected_applications) + expect(rehearsal_env_result.cookbook_versions) + .to eq(expected_cookbook_versions) + expect(rehearsal_env_result.override_attributes['applications']) + .to eq(expected_applications) end # maybe we want to test when node['delivery']['project_cookbooks'] is set # context 'when the project ships multiple cookbooks' do end - end end @@ -1440,7 +1439,7 @@ { 'app_1' => '0_3_563', 'app_2' => '1_0_206', - 'new_app' => '0_0_1' + 'new_app' => '0_0_1', } end @@ -1448,13 +1447,13 @@ { 'cookbook_1' => '= 1.2.3', 'cookbook_2' => '= 0.1.0', - 'new_cookbook' => '= 0.1.0' + 'new_cookbook' => '= 0.1.0', } end let(:previous_stage_default_attributes) do { - 'foo' => 'bar' + 'foo' => 'bar', } end @@ -1464,7 +1463,7 @@ env.cookbook_versions(previous_stage_cookbook_versions) env.default_attributes = previous_stage_default_attributes env.override_attributes = { - 'applications' => previous_stage_applications + 'applications' => previous_stage_applications, } env end @@ -1475,7 +1474,7 @@ { 'app_1' => '0_3_562', 'app_2' => '1_0_205', - 'no_longer_supported_app' => '0_0_50' + 'no_longer_supported_app' => '0_0_50', } end @@ -1483,13 +1482,13 @@ { 'cookbook_1' => '= 1.2.2', 'cookbook_2' => '= 0.0.9', - 'no_longer_supported_cookbook' => '= 2.3.0' + 'no_longer_supported_cookbook' => '= 2.3.0', } end let(:current_stage_default_attributes) do { - 'foo' => 'baz' + 'foo' => 'baz', } end @@ -1499,22 +1498,22 @@ env.cookbook_versions(current_stage_cookbook_versions) env.default_attributes = current_stage_default_attributes env.override_attributes = { - 'applications' => current_stage_applications + 'applications' => current_stage_applications, } env end before(:each) do - expect(Chef::Environment). - to receive(:load). - with(previous_stage_env_name). - and_return(previous_stage_env) - expect(Chef::Environment). - to receive(:load). - with(current_stage_env_name). - and_return(current_stage_env) - expect(current_stage_env). - to receive(:save) + expect(Chef::Environment) + .to receive(:load) + .with(previous_stage_env_name) + .and_return(previous_stage_env) + expect(Chef::Environment) + .to receive(:load) + .with(current_stage_env_name) + .and_return(current_stage_env) + expect(current_stage_env) + .to receive(:save) end it 'merges all cookbook and application version pinnings from the previous' \ @@ -1528,13 +1527,12 @@ current_stage_env_result = described_class.handle_delivered_pinnings(node) - expect(current_stage_env_result.cookbook_versions). - to eq(expected_cookbook_versions) - expect(current_stage_env_result.default_attributes). - to eq(expected_default_attributes) - expect(current_stage_env_result.override_attributes['applications']). - to eq(expected_applications) + expect(current_stage_env_result.cookbook_versions) + .to eq(expected_cookbook_versions) + expect(current_stage_env_result.default_attributes) + .to eq(expected_default_attributes) + expect(current_stage_env_result.override_attributes['applications']) + .to eq(expected_applications) end end - end diff --git a/spec/unit/libraries/helpers_syntax_spec.rb b/spec/unit/libraries/helpers_syntax_spec.rb index 02f8dc8..3798e77 100644 --- a/spec/unit/libraries/helpers_syntax_spec.rb +++ b/spec/unit/libraries/helpers_syntax_spec.rb @@ -6,9 +6,8 @@ class Change end describe DeliveryTruck::Helpers::Syntax do - describe '.bumped_version?' do - let(:node) { double("node") } + let(:node) { double('node') } let(:workspace) { '/tmp/repo' } let(:pipeline) { 'master' } let(:relative_path) { '.' } @@ -19,11 +18,13 @@ class Change let(:current_version) { '0.0.1' } let(:current_metadata) { double('metadata', name: 'julia', version: current_version) } - let(:sugar_change) { double('delivery sugar change', + let(:sugar_change) do + double('delivery sugar change', workspace_repo: workspace, changed_files: changed_files, pipeline: pipeline, - merge_sha: merge_sha) } + merge_sha: merge_sha) + end before do allow(DeliverySugar::Change).to receive(:new).and_return(sugar_change) @@ -54,7 +55,7 @@ class Change let(:current_version) { '0.0.2' } it 'returns true' do - expect(described_class.bumped_version?(workspace, node)).to eql true + expect(described_class.bumped_version?(workspace, node)).to eql true end end end @@ -121,7 +122,7 @@ class Change let(:current_version) { '0.0.2' } it 'returns true' do - expect(described_class.bumped_version?(workspace, node)).to eql true + expect(described_class.bumped_version?(workspace, node)).to eql true end end end diff --git a/spec/unit/recipes/default_spec.rb b/spec/unit/recipes/default_spec.rb index 357357d..927794d 100644 --- a/spec/unit/recipes/default_spec.rb +++ b/spec/unit/recipes/default_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe "delivery-truck::default", :ignore => true do +describe 'delivery-truck::default', ignore: true do let(:chef_run) { ChefSpec::SoloRunner.converge(described_recipe) } it 'should install chefspec' do diff --git a/spec/unit/recipes/deploy_spec.rb b/spec/unit/recipes/deploy_spec.rb index 938702c..c3e3f8d 100644 --- a/spec/unit/recipes/deploy_spec.rb +++ b/spec/unit/recipes/deploy_spec.rb @@ -9,7 +9,7 @@ def initialize(name) end end -describe "delivery-truck::deploy" do +describe 'delivery-truck::deploy' do let(:chef_run) do ChefSpec::SoloRunner.new do |node| node.default['delivery']['workspace']['root'] = '/tmp' @@ -34,12 +34,12 @@ def initialize(name) let(:search_query) do "(#{recipe_list}) AND chef_environment:union AND recipes:*push-jobs*" end - let(:node_list) { [MyFakeNode.new("node1"), MyFakeNode.new("node2")] } + let(:node_list) { [MyFakeNode.new('node1'), MyFakeNode.new('node2')] } let(:delivery_knife_rb) do - "/var/opt/delivery/workspace/.chef/knife.rb" + '/var/opt/delivery/workspace/.chef/knife.rb' end - context "when a single cookbook has been modified" do + context 'when a single cookbook has been modified' do before do allow_any_instance_of(Chef::Recipe).to receive(:get_all_project_cookbooks).and_return(one_changed_cookbook) allow_any_instance_of(Chef::Recipe).to receive(:get_cookbook_version).and_return('1.0.0') @@ -47,15 +47,15 @@ def initialize(name) let(:recipe_list) { 'recipes:julia*' } - it "deploy only that cookbook" do + it 'deploy only that cookbook' do expect(DeliveryTruck::Helpers::Deploy).to receive(:delivery_chef_server_search).with(:node, search_query, delivery_knife_rb).and_return(node_list) - expect(chef_run).to dispatch_delivery_push_job("deploy_Secret").with( - :command => 'chef-client', - :nodes => node_list + expect(chef_run).to dispatch_delivery_push_job('deploy_Secret').with( + command: 'chef-client', + nodes: node_list ) end - context "and the user sets a different search query" do + context 'and the user sets a different search query' do before do allow(DeliveryTruck::Helpers::Deploy).to receive(:deployment_search_query) .and_return('recipes:my_cool_push_jobs_cookbook AND more:constraints') @@ -63,19 +63,19 @@ def initialize(name) let(:search_query) do "(#{recipe_list}) AND chef_environment:union AND recipes:my_cool_push_jobs_cookbook AND more:constraints" end - it "deploy only that cookbook with the special search query" do + it 'deploy only that cookbook with the special search query' do expect(DeliveryTruck::Helpers::Deploy).to receive(:delivery_chef_server_search) .with(:node, search_query, delivery_knife_rb) .and_return(node_list) - expect(chef_run).to dispatch_delivery_push_job("deploy_Secret").with( - :command => 'chef-client', - :nodes => node_list + expect(chef_run).to dispatch_delivery_push_job('deploy_Secret').with( + command: 'chef-client', + nodes: node_list ) end end end - context "when multiple cookbooks have been modified" do + context 'when multiple cookbooks have been modified' do before do allow_any_instance_of(Chef::Recipe).to receive(:get_all_project_cookbooks).and_return(two_changed_cookbooks) allow_any_instance_of(Chef::Recipe).to receive(:get_cookbook_version).and_return('1.0.0') @@ -83,23 +83,23 @@ def initialize(name) let(:recipe_list) { 'recipes:julia* OR recipes:gordon*' } - it "deploy only those cookbooks" do + it 'deploy only those cookbooks' do allow_any_instance_of(Chef::Recipe).to receive(:delivery_chef_server_search).with(:node, search_query).and_return(node_list) - expect(chef_run).to dispatch_delivery_push_job("deploy_Secret").with( - :command => 'chef-client', - :nodes => node_list + expect(chef_run).to dispatch_delivery_push_job('deploy_Secret').with( + command: 'chef-client', + nodes: node_list ) end end - context "when no cookbooks have been modified" do + context 'when no cookbooks have been modified' do before do allow_any_instance_of(Chef::Recipe).to receive(:get_all_project_cookbooks).and_return(no_changed_cookbooks) allow_any_instance_of(Chef::Recipe).to receive(:get_cookbook_version).and_return('1.0.0') end - it "does not deploy any cookbooks" do - expect(chef_run).not_to dispatch_delivery_push_job("deploy_Secret") + it 'does not deploy any cookbooks' do + expect(chef_run).not_to dispatch_delivery_push_job('deploy_Secret') end end end diff --git a/spec/unit/recipes/functional_spec.rb b/spec/unit/recipes/functional_spec.rb index 10e2c78..2b2f665 100644 --- a/spec/unit/recipes/functional_spec.rb +++ b/spec/unit/recipes/functional_spec.rb @@ -1,17 +1,17 @@ require 'spec_helper' -RSpec.shared_examples "cleanup docker" do - it "cleans up Docker" do +RSpec.shared_examples 'cleanup docker' do + it 'cleans up Docker' do expect(chef_run).to run_execute('stop_all_docker_containers') - .with(command: 'docker stop $(docker ps --quiet --filter "status=running")', + .with(command: 'docker stop $(docker ps --quiet --filter "status=running")', ignore_failure: true) expect(chef_run).to run_execute('kill_all_docker_containers') - .with(command: 'docker rm $(docker ps --all --quiet)', + .with(command: 'docker rm $(docker ps --all --quiet)', ignore_failure: true) end end -describe "delivery-truck::functional", :ignore => true do +describe 'delivery-truck::functional', ignore: true do let(:chef_run) { ChefSpec::SoloRunner.converge(described_recipe) } before do @@ -19,26 +19,26 @@ allow_any_instance_of(Chef::Recipe).to receive(:repo_path).and_return('/tmp') end - context "when a single cookbook has been modified" do + context 'when a single cookbook has been modified' do before do allow_any_instance_of(Chef::Recipe).to receive(:current_stage).and_return('acceptance') allow_any_instance_of(Chef::Recipe).to receive(:changed_cookbooks).and_return(one_changed_cookbook) allow(DeliveryTruck::Helpers::Functional).to receive(:has_kitchen_tests?).with('/tmp/cookbooks/julia').and_return(true) end - include_examples "cleanup docker" + include_examples 'cleanup docker' - it "runs test-kitchen against only that cookbook" do - expect(chef_run).to run_delivery_truck_exec("functional_kitchen_julia").with( - :cwd => "/tmp/cookbooks/julia", - :command => "KITCHEN_YAML=/tmp/cookbooks/julia/.kitchen.docker.yml kitchen test" + it 'runs test-kitchen against only that cookbook' do + expect(chef_run).to run_delivery_truck_exec('functional_kitchen_julia').with( + cwd: '/tmp/cookbooks/julia', + command: 'KITCHEN_YAML=/tmp/cookbooks/julia/.kitchen.docker.yml kitchen test' ) - expect(chef_run).not_to run_delivery_truck_exec("functional_kitchen_gordon") - expect(chef_run).not_to run_delivery_truck_exec("functional_kitchen_emeril") + expect(chef_run).not_to run_delivery_truck_exec('functional_kitchen_gordon') + expect(chef_run).not_to run_delivery_truck_exec('functional_kitchen_emeril') end end - context "when multiple cookbooks have been modified" do + context 'when multiple cookbooks have been modified' do before do allow_any_instance_of(Chef::Recipe).to receive(:current_stage).and_return('acceptance') allow_any_instance_of(Chef::Recipe).to receive(:changed_cookbooks).and_return(two_changed_cookbooks) @@ -46,48 +46,48 @@ allow(DeliveryTruck::Helpers::Functional).to receive(:has_kitchen_tests?).with('/tmp/cookbooks/gordon').and_return(true) end - include_examples "cleanup docker" + include_examples 'cleanup docker' - it "runs test-kitchen against only those cookbooks" do - expect(chef_run).to run_delivery_truck_exec("functional_kitchen_julia").with( - :cwd => "/tmp/cookbooks/julia", - :command => "KITCHEN_YAML=/tmp/cookbooks/julia/.kitchen.docker.yml kitchen test" + it 'runs test-kitchen against only those cookbooks' do + expect(chef_run).to run_delivery_truck_exec('functional_kitchen_julia').with( + cwd: '/tmp/cookbooks/julia', + command: 'KITCHEN_YAML=/tmp/cookbooks/julia/.kitchen.docker.yml kitchen test' ) - expect(chef_run).to run_delivery_truck_exec("functional_kitchen_gordon").with( - :cwd => "/tmp/cookbooks/gordon", - :command => "KITCHEN_YAML=/tmp/cookbooks/gordon/.kitchen.docker.yml kitchen test" + expect(chef_run).to run_delivery_truck_exec('functional_kitchen_gordon').with( + cwd: '/tmp/cookbooks/gordon', + command: 'KITCHEN_YAML=/tmp/cookbooks/gordon/.kitchen.docker.yml kitchen test' ) - expect(chef_run).not_to run_delivery_truck_exec("functional_kitchen_emeril") + expect(chef_run).not_to run_delivery_truck_exec('functional_kitchen_emeril') end - context "but a cookbook has no tests" do + context 'but a cookbook has no tests' do before do allow(DeliveryTruck::Helpers::Functional).to receive(:has_kitchen_tests?).with('/tmp/cookbooks/gordon').and_return(false) end - include_examples "cleanup docker" + include_examples 'cleanup docker' - it "skips that cookbook" do - expect(chef_run).to run_delivery_truck_exec("functional_kitchen_julia").with( - :cwd => "/tmp/cookbooks/julia", - :command => "KITCHEN_YAML=/tmp/cookbooks/julia/.kitchen.docker.yml kitchen test" + it 'skips that cookbook' do + expect(chef_run).to run_delivery_truck_exec('functional_kitchen_julia').with( + cwd: '/tmp/cookbooks/julia', + command: 'KITCHEN_YAML=/tmp/cookbooks/julia/.kitchen.docker.yml kitchen test' ) - expect(chef_run).not_to run_delivery_truck_exec("functional_kitchen_gordon") - expect(chef_run).not_to run_delivery_truck_exec("functional_kitchen_emeril") + expect(chef_run).not_to run_delivery_truck_exec('functional_kitchen_gordon') + expect(chef_run).not_to run_delivery_truck_exec('functional_kitchen_emeril') end end end - context "when no cookbooks have been modified" do + context 'when no cookbooks have been modified' do before do allow_any_instance_of(Chef::Recipe).to receive(:current_stage).and_return('acceptance') allow_any_instance_of(Chef::Recipe).to receive(:changed_cookbooks).and_return(no_changed_cookbooks) end - it "does not run test-kitchen against any cookbooks" do - expect(chef_run).not_to run_delivery_truck_exec("functional_kitchen_julia") - expect(chef_run).not_to run_delivery_truck_exec("functional_kitchen_gordon") - expect(chef_run).not_to run_delivery_truck_exec("functional_kitchen_emeril") + it 'does not run test-kitchen against any cookbooks' do + expect(chef_run).not_to run_delivery_truck_exec('functional_kitchen_julia') + expect(chef_run).not_to run_delivery_truck_exec('functional_kitchen_gordon') + expect(chef_run).not_to run_delivery_truck_exec('functional_kitchen_emeril') end end @@ -99,9 +99,9 @@ it 'does nothing' do expect(chef_run).not_to run_execute('stop_all_docker_containers') expect(chef_run).not_to run_execute('kill_all_docker_containers') - expect(chef_run).not_to run_delivery_truck_exec("functional_kitchen_julia") - expect(chef_run).not_to run_delivery_truck_exec("functional_kitchen_gordon") - expect(chef_run).not_to run_delivery_truck_exec("functional_kitchen_emeril") + expect(chef_run).not_to run_delivery_truck_exec('functional_kitchen_julia') + expect(chef_run).not_to run_delivery_truck_exec('functional_kitchen_gordon') + expect(chef_run).not_to run_delivery_truck_exec('functional_kitchen_emeril') end end end diff --git a/spec/unit/recipes/lint_spec.rb b/spec/unit/recipes/lint_spec.rb index aaf97cd..468e7c7 100644 --- a/spec/unit/recipes/lint_spec.rb +++ b/spec/unit/recipes/lint_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe "delivery-truck::lint" do +describe 'delivery-truck::lint' do let(:chef_run) do ChefSpec::SoloRunner.new do |node| node.default['delivery']['workspace']['root'] = '/tmp' @@ -22,70 +22,70 @@ end.converge(described_recipe) end - context "when a single cookbook has been modified" do + context 'when a single cookbook has been modified' do before do - allow(DeliveryTruck::Helpers::Lint).to receive(:foodcritic_epic_fail).and_return("-f correctness") - allow(DeliveryTruck::Helpers::Lint).to receive(:foodcritic_tags).and_return("-t FC001") - allow(DeliveryTruck::Helpers::Lint).to receive(:foodcritic_excludes).and_return("--exclude spec") + allow(DeliveryTruck::Helpers::Lint).to receive(:foodcritic_epic_fail).and_return('-f correctness') + allow(DeliveryTruck::Helpers::Lint).to receive(:foodcritic_tags).and_return('-t FC001') + allow(DeliveryTruck::Helpers::Lint).to receive(:foodcritic_excludes).and_return('--exclude spec') allow_any_instance_of(Chef::Recipe).to receive(:changed_cookbooks).and_return(one_changed_cookbook) end - it "runs test-kitchen against only that cookbook" do - expect(chef_run).to run_execute("lint_foodcritic_julia").with( - :command => "foodcritic -f correctness -t FC001 --exclude spec /tmp/repo/cookbooks/julia" + it 'runs test-kitchen against only that cookbook' do + expect(chef_run).to run_execute('lint_foodcritic_julia').with( + command: 'foodcritic -f correctness -t FC001 --exclude spec /tmp/repo/cookbooks/julia' ) - expect(chef_run).not_to run_execute("lint_foodcritic_gordon") - expect(chef_run).not_to run_execute("lint_foodcritic_emeril") + expect(chef_run).not_to run_execute('lint_foodcritic_gordon') + expect(chef_run).not_to run_execute('lint_foodcritic_emeril') end end - context "when multiple cookbooks have been modified" do + context 'when multiple cookbooks have been modified' do before do - allow(DeliveryTruck::Helpers::Lint).to receive(:foodcritic_epic_fail).and_return("-f correctness") - allow(DeliveryTruck::Helpers::Lint).to receive(:foodcritic_tags).and_return("-t ~FC002") - allow(DeliveryTruck::Helpers::Lint).to receive(:foodcritic_excludes).and_return("--exclude test") + allow(DeliveryTruck::Helpers::Lint).to receive(:foodcritic_epic_fail).and_return('-f correctness') + allow(DeliveryTruck::Helpers::Lint).to receive(:foodcritic_tags).and_return('-t ~FC002') + allow(DeliveryTruck::Helpers::Lint).to receive(:foodcritic_excludes).and_return('--exclude test') allow_any_instance_of(Chef::Recipe).to receive(:changed_cookbooks).and_return(two_changed_cookbooks) end - it "runs test-kitchen against only those cookbooks" do - expect(chef_run).to run_execute("lint_foodcritic_julia").with( - :command => "foodcritic -f correctness -t ~FC002 --exclude test /tmp/repo/cookbooks/julia" + it 'runs test-kitchen against only those cookbooks' do + expect(chef_run).to run_execute('lint_foodcritic_julia').with( + command: 'foodcritic -f correctness -t ~FC002 --exclude test /tmp/repo/cookbooks/julia' ) - expect(chef_run).to run_execute("lint_foodcritic_gordon").with( - :command => "foodcritic -f correctness -t ~FC002 --exclude test /tmp/repo/cookbooks/gordon" + expect(chef_run).to run_execute('lint_foodcritic_gordon').with( + command: 'foodcritic -f correctness -t ~FC002 --exclude test /tmp/repo/cookbooks/gordon' ) - expect(chef_run).not_to run_execute("lint_foodcritic_emeril") + expect(chef_run).not_to run_execute('lint_foodcritic_emeril') end end - context "when no cookbooks have been modified" do + context 'when no cookbooks have been modified' do before do - allow(DeliveryTruck::Helpers::Lint).to receive(:foodcritic_tags).and_return("") + allow(DeliveryTruck::Helpers::Lint).to receive(:foodcritic_tags).and_return('') allow_any_instance_of(Chef::Recipe).to receive(:changed_cookbooks).and_return(no_changed_cookbooks) end - it "does not run test-kitchen against any cookbooks" do - expect(chef_run).not_to run_execute("lint_foodcritic_julia") - expect(chef_run).not_to run_execute("lint_foodcritic_gordon") - expect(chef_run).not_to run_execute("lint_foodcritic_emeril") + it 'does not run test-kitchen against any cookbooks' do + expect(chef_run).not_to run_execute('lint_foodcritic_julia') + expect(chef_run).not_to run_execute('lint_foodcritic_gordon') + expect(chef_run).not_to run_execute('lint_foodcritic_emeril') end end - context "when a .rubocop.yml is present" do + context 'when a .rubocop.yml is present' do before do - allow(DeliveryTruck::Helpers::Lint).to receive(:foodcritic_epic_fail).and_return("-f correctness") - allow(DeliveryTruck::Helpers::Lint).to receive(:foodcritic_tags).and_return("") + allow(DeliveryTruck::Helpers::Lint).to receive(:foodcritic_epic_fail).and_return('-f correctness') + allow(DeliveryTruck::Helpers::Lint).to receive(:foodcritic_tags).and_return('') allow_any_instance_of(Chef::Recipe).to receive(:changed_cookbooks).and_return(one_changed_cookbook) allow(File).to receive(:exist?).and_call_original - allow(File).to receive(:exist?).with("/tmp/repo/cookbooks/julia/.rubocop.yml").and_return(true) + allow(File).to receive(:exist?).with('/tmp/repo/cookbooks/julia/.rubocop.yml').and_return(true) end - it "runs Rubocop" do - expect(chef_run).to run_execute("lint_rubocop_julia").with( - :command => "rubocop /tmp/repo/cookbooks/julia" + it 'runs Rubocop' do + expect(chef_run).to run_execute('lint_rubocop_julia').with( + command: 'rubocop /tmp/repo/cookbooks/julia' ) - expect(chef_run).not_to run_execute("lint_rubocop_gordon") - expect(chef_run).not_to run_execute("lint_rubocop_emeril") + expect(chef_run).not_to run_execute('lint_rubocop_gordon') + expect(chef_run).not_to run_execute('lint_rubocop_emeril') end end end diff --git a/spec/unit/recipes/provision_spec.rb b/spec/unit/recipes/provision_spec.rb index 407e6c4..25439e3 100644 --- a/spec/unit/recipes/provision_spec.rb +++ b/spec/unit/recipes/provision_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe "delivery-truck::provision" do +describe 'delivery-truck::provision' do let(:chef_run) do @node = nil ChefSpec::SoloRunner.new do |node| diff --git a/spec/unit/recipes/publish_spec.rb b/spec/unit/recipes/publish_spec.rb index 19e7769..39edbc8 100644 --- a/spec/unit/recipes/publish_spec.rb +++ b/spec/unit/recipes/publish_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe "delivery-truck::publish" do +describe 'delivery-truck::publish' do let(:chef_run) do ChefSpec::SoloRunner.new do |node| node.default['delivery']['workspace']['root'] = '/tmp' @@ -27,8 +27,8 @@ chef_server_url: 'http://myserver.chef', options: { client_name: 'spec', - signing_key_filename: '/tmp/keys/spec.pem' - } + signing_key_filename: '/tmp/keys/spec.pem', + }, } end @@ -45,9 +45,9 @@ end it 'deletes and recreates cookbook staging directory' do - expect(chef_run).to delete_directory("/tmp/cache/cookbook-upload") + expect(chef_run).to delete_directory('/tmp/cache/cookbook-upload') .with(recursive: true) - expect(chef_run).to create_directory("/tmp/cache/cookbook-upload") + expect(chef_run).to create_directory('/tmp/cache/cookbook-upload') end end @@ -159,7 +159,7 @@ before do file = instance_double('File') allow(File).to receive(:new).with(supermarket_tmp_path, 'w+') - .and_return(file) + .and_return(file) allow(file).to receive(:write).with('test-key') allow(file).to receive(:close) end @@ -200,27 +200,25 @@ context 'when supermarket_user is not specified in secrets' do let(:secrets) do { - 'supermarket_key' => 'test-key' + 'supermarket_key' => 'test-key', } end it 'rasies an error' do expect { chef_run.converge(described_recipe) }.to raise_error(RuntimeError) end - end context 'when supermarket_user is not specified in secrets' do let(:secrets) do { - 'supermarket_user' => 'test-user' + 'supermarket_user' => 'test-user', } end it 'rasies an error' do expect { chef_run.converge(described_recipe) }.to raise_error(RuntimeError) end - end end end @@ -238,9 +236,9 @@ expect(chef_run).not_to create_link('/tmp/cache/cookbook-upload/gordon') expect(chef_run).not_to create_link('/tmp/cache/cookbook-upload/emeril') - expect(chef_run).not_to run_execute("upload_cookbook_julia") - expect(chef_run).not_to run_execute("upload_cookbook_gordon") - expect(chef_run).not_to run_execute("upload_cookbook_emeril") + expect(chef_run).not_to run_execute('upload_cookbook_julia') + expect(chef_run).not_to run_execute('upload_cookbook_gordon') + expect(chef_run).not_to run_execute('upload_cookbook_emeril') end end @@ -263,9 +261,9 @@ expect(chef_run).not_to create_link('/tmp/cache/cookbook-upload/gordon') expect(chef_run).not_to create_link('/tmp/cache/cookbook-upload/emeril') - expect(chef_run).not_to run_execute("upload_cookbook_julia") - expect(chef_run).not_to run_execute("upload_cookbook_gordon") - expect(chef_run).not_to run_execute("upload_cookbook_emeril") + expect(chef_run).not_to run_execute('upload_cookbook_julia') + expect(chef_run).not_to run_execute('upload_cookbook_gordon') + expect(chef_run).not_to run_execute('upload_cookbook_emeril') end end @@ -278,17 +276,17 @@ it 'uploads only that cookbook' do expect(chef_run).to create_link('/tmp/cache/cookbook-upload/julia') - .with(to: '/tmp/repo/cookbooks/julia') + .with(to: '/tmp/repo/cookbooks/julia') expect(chef_run).not_to create_link('/tmp/cache/cookbook-upload/gordon') expect(chef_run).not_to create_link('/tmp/cache/cookbook-upload/emeril') - expect(chef_run).to run_execute("upload_cookbook_julia") - .with(command: 'knife cookbook upload julia ' \ + expect(chef_run).to run_execute('upload_cookbook_julia') + .with(command: 'knife cookbook upload julia ' \ '--freeze --all --force ' \ '--config /var/opt/delivery/workspace/.chef/knife.rb ' \ '--cookbook-path /tmp/cache/cookbook-upload') - expect(chef_run).not_to run_execute("upload_cookbook_gordon") - expect(chef_run).not_to run_execute("upload_cookbook_emeril") + expect(chef_run).not_to run_execute('upload_cookbook_gordon') + expect(chef_run).not_to run_execute('upload_cookbook_emeril') end end @@ -301,22 +299,22 @@ it 'uploads only those cookbook' do expect(chef_run).to create_link('/tmp/cache/cookbook-upload/julia') - .with(to: '/tmp/repo/cookbooks/julia') + .with(to: '/tmp/repo/cookbooks/julia') expect(chef_run).to create_link('/tmp/cache/cookbook-upload/gordon') - .with(to: '/tmp/repo/cookbooks/gordon') + .with(to: '/tmp/repo/cookbooks/gordon') expect(chef_run).not_to create_link('/tmp/cache/cookbook-upload/emeril') - expect(chef_run).to run_execute("upload_cookbook_julia") - .with(command: 'knife cookbook upload julia ' \ + expect(chef_run).to run_execute('upload_cookbook_julia') + .with(command: 'knife cookbook upload julia ' \ '--freeze --all --force ' \ '--config /var/opt/delivery/workspace/.chef/knife.rb ' \ '--cookbook-path /tmp/cache/cookbook-upload') - expect(chef_run).to run_execute("upload_cookbook_gordon") - .with(command: 'knife cookbook upload gordon ' \ + expect(chef_run).to run_execute('upload_cookbook_gordon') + .with(command: 'knife cookbook upload gordon ' \ '--freeze --all --force ' \ '--config /var/opt/delivery/workspace/.chef/knife.rb ' \ '--cookbook-path /tmp/cache/cookbook-upload') - expect(chef_run).not_to run_execute("upload_cookbook_emeril") + expect(chef_run).not_to run_execute('upload_cookbook_emeril') end end @@ -324,20 +322,19 @@ before do allow(File).to receive(:exist?).and_call_original allow(File).to receive(:exist?).with('/tmp/repo/cookbooks/julia/Berksfile') - .and_return(true) + .and_return(true) allow_any_instance_of(Chef::Recipe).to receive(:changed_cookbooks) .and_return(one_changed_cookbook) chef_run.converge(described_recipe) end it 'vendors all dependencies with Berkshelf' do + expect(chef_run).to run_execute('berks_vendor_cookbook_julia') + .with(command: 'berks vendor /tmp/cache/cookbook-upload') + .with(cwd: '/tmp/repo/cookbooks/julia') - expect(chef_run).to run_execute("berks_vendor_cookbook_julia") - .with(command: 'berks vendor /tmp/cache/cookbook-upload') - .with(cwd: '/tmp/repo/cookbooks/julia') - - expect(chef_run).to run_execute("upload_cookbook_julia") - .with(command: 'knife cookbook upload julia ' \ + expect(chef_run).to run_execute('upload_cookbook_julia') + .with(command: 'knife cookbook upload julia ' \ '--freeze --all --force ' \ '--config /var/opt/delivery/workspace/.chef/knife.rb ' \ '--cookbook-path /tmp/cache/cookbook-upload') @@ -349,29 +346,29 @@ before do allow(DeliveryTruck::Helpers::Publish).to receive(:push_repo_to_github?) .and_return(false) - stub_command("git remote --verbose | grep ^github").and_return(false) + stub_command('git remote --verbose | grep ^github').and_return(false) chef_run.converge(described_recipe) end it 'does not push to github' do - expect(chef_run).not_to run_execute("push_to_github") + expect(chef_run).not_to run_execute('push_to_github') end end context 'when they wish to push to github' do - let(:secrets) {{'github' => 'SECRET'}} + let(:secrets) { { 'github' => 'SECRET' } } before do allow_any_instance_of(Chef::Recipe).to receive(:get_project_secrets) .and_return(secrets) - stub_command("git remote --verbose | grep ^github").and_return(false) + stub_command('git remote --verbose | grep ^github').and_return(false) chef_run.node.default['delivery']['config']['delivery-truck']['publish']['github'] = 'spec/spec' chef_run.converge(described_recipe) end it 'pushes to github' do expect(chef_run).to push_delivery_github('spec/spec') - .with(deploy_key: 'SECRET', + .with(deploy_key: 'SECRET', branch: 'master', remote_url: 'git@github.com:spec/spec.git', repo_path: '/tmp/repo', @@ -388,12 +385,12 @@ end it 'does not push to git' do - expect(chef_run).not_to run_execute("push_to_git") + expect(chef_run).not_to run_execute('push_to_git') end end context 'when they wish to push to git' do - let(:secrets) {{'git' => 'SECRET'}} + let(:secrets) { { 'git' => 'SECRET' } } before do allow_any_instance_of(Chef::Recipe).to receive(:get_project_secrets) @@ -404,7 +401,7 @@ it 'pushes to git' do expect(chef_run).to push_delivery_github('ssh://git@stash:2222/spec/spec.git') - .with(deploy_key: 'SECRET', + .with(deploy_key: 'SECRET', branch: 'master', remote_url: 'ssh://git@stash:2222/spec/spec.git', repo_path: '/tmp/repo', @@ -412,5 +409,4 @@ action: [:push]) end end - end diff --git a/spec/unit/recipes/syntax_spec.rb b/spec/unit/recipes/syntax_spec.rb index 03c06b3..c406db9 100644 --- a/spec/unit/recipes/syntax_spec.rb +++ b/spec/unit/recipes/syntax_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe "delivery-truck::syntax" do +describe 'delivery-truck::syntax' do let(:chef_run) do ChefSpec::ServerRunner.new do |node| node.default['delivery']['workspace']['root'] = '/tmp' @@ -27,45 +27,45 @@ allow(DeliveryTruck::Helpers::Syntax).to receive(:bumped_version?).and_return(true) end - context "when a single cookbook has been modified" do + context 'when a single cookbook has been modified' do before do allow_any_instance_of(Chef::Recipe).to receive(:changed_cookbooks).and_return(one_changed_cookbook) end - it "runs `knife cookbook test` against only that cookbook" do - expect(chef_run).to run_execute("syntax_check_julia").with( - :command => "knife cookbook test -o /tmp/repo/cookbooks/julia -a" + it 'runs `knife cookbook test` against only that cookbook' do + expect(chef_run).to run_execute('syntax_check_julia').with( + command: 'knife cookbook test -o /tmp/repo/cookbooks/julia -a' ) - expect(chef_run).not_to run_execute("syntax_check_gordon") - expect(chef_run).not_to run_execute("syntax_check_emeril") + expect(chef_run).not_to run_execute('syntax_check_gordon') + expect(chef_run).not_to run_execute('syntax_check_emeril') end end - context "when multiple cookbooks have been modified" do + context 'when multiple cookbooks have been modified' do before do allow_any_instance_of(Chef::Recipe).to receive(:changed_cookbooks).and_return(two_changed_cookbooks) end - it "runs `knife cookbook test` against only those cookbooks" do - expect(chef_run).to run_execute("syntax_check_julia").with( - :command => "knife cookbook test -o /tmp/repo/cookbooks/julia -a" + it 'runs `knife cookbook test` against only those cookbooks' do + expect(chef_run).to run_execute('syntax_check_julia').with( + command: 'knife cookbook test -o /tmp/repo/cookbooks/julia -a' ) - expect(chef_run).to run_execute("syntax_check_gordon").with( - :command => "knife cookbook test -o /tmp/repo/cookbooks/gordon -a" + expect(chef_run).to run_execute('syntax_check_gordon').with( + command: 'knife cookbook test -o /tmp/repo/cookbooks/gordon -a' ) - expect(chef_run).not_to run_execute("syntax_check_emeril") + expect(chef_run).not_to run_execute('syntax_check_emeril') end end - context "when no cookbooks have been modified" do + context 'when no cookbooks have been modified' do before do allow_any_instance_of(Chef::Recipe).to receive(:changed_cookbooks).and_return(no_changed_cookbooks) end - it "does not run `knife cookbook test` against any cookbooks" do - expect(chef_run).not_to run_execute("syntax_check_julia") - expect(chef_run).not_to run_execute("syntax_check_gordon") - expect(chef_run).not_to run_execute("syntax_check_emeril") + it 'does not run `knife cookbook test` against any cookbooks' do + expect(chef_run).not_to run_execute('syntax_check_julia') + expect(chef_run).not_to run_execute('syntax_check_gordon') + expect(chef_run).not_to run_execute('syntax_check_emeril') end end end diff --git a/spec/unit/recipes/unit_spec.rb b/spec/unit/recipes/unit_spec.rb index 8a82531..15038e3 100644 --- a/spec/unit/recipes/unit_spec.rb +++ b/spec/unit/recipes/unit_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe "delivery-truck::unit" do +describe 'delivery-truck::unit' do let(:chef_run) do ChefSpec::SoloRunner.new do |node| node.default['delivery']['workspace']['root'] = '/tmp' @@ -22,51 +22,51 @@ end.converge(described_recipe) end - context "when a single cookbook has been modified" do + context 'when a single cookbook has been modified' do before do allow_any_instance_of(Chef::Recipe).to receive(:changed_cookbooks).and_return(one_changed_cookbook) allow(DeliveryTruck::Helpers::Unit).to receive(:has_spec_tests?).with('/tmp/repo/cookbooks/julia').and_return(true) end - it "runs test-kitchen against only that cookbook" do - expect(chef_run).to run_execute("unit_rspec_julia").with( - :cwd => "/tmp/repo/cookbooks/julia", - :command => "rspec --format documentation --color" + it 'runs test-kitchen against only that cookbook' do + expect(chef_run).to run_execute('unit_rspec_julia').with( + cwd: '/tmp/repo/cookbooks/julia', + command: 'rspec --format documentation --color' ) - expect(chef_run).not_to run_execute("unit_rspec_gordon") - expect(chef_run).not_to run_execute("unit_rspec_emeril") + expect(chef_run).not_to run_execute('unit_rspec_gordon') + expect(chef_run).not_to run_execute('unit_rspec_emeril') end end - context "when multiple cookbooks have been modified" do + context 'when multiple cookbooks have been modified' do before do allow_any_instance_of(Chef::Recipe).to receive(:changed_cookbooks).and_return(two_changed_cookbooks) allow(DeliveryTruck::Helpers::Unit).to receive(:has_spec_tests?).with('/tmp/repo/cookbooks/julia').and_return(true) allow(DeliveryTruck::Helpers::Unit).to receive(:has_spec_tests?).with('/tmp/repo/cookbooks/gordon').and_return(true) end - it "runs test-kitchen against only those cookbooks" do - expect(chef_run).to run_execute("unit_rspec_julia").with( - :cwd => "/tmp/repo/cookbooks/julia", - :command => "rspec --format documentation --color" + it 'runs test-kitchen against only those cookbooks' do + expect(chef_run).to run_execute('unit_rspec_julia').with( + cwd: '/tmp/repo/cookbooks/julia', + command: 'rspec --format documentation --color' ) - expect(chef_run).to run_execute("unit_rspec_gordon").with( - :cwd => "/tmp/repo/cookbooks/gordon", - :command => "rspec --format documentation --color" + expect(chef_run).to run_execute('unit_rspec_gordon').with( + cwd: '/tmp/repo/cookbooks/gordon', + command: 'rspec --format documentation --color' ) - expect(chef_run).not_to run_execute("unit_rspec_emeril") + expect(chef_run).not_to run_execute('unit_rspec_emeril') end end - context "when no cookbooks have been modified" do + context 'when no cookbooks have been modified' do before do allow_any_instance_of(Chef::Recipe).to receive(:changed_cookbooks).and_return(no_changed_cookbooks) end - it "does not run test-kitchen against any cookbooks" do - expect(chef_run).not_to run_execute("unit_rspec_julia") - expect(chef_run).not_to run_execute("unit_rspec_gordon") - expect(chef_run).not_to run_execute("unit_rspec_emeril") + it 'does not run test-kitchen against any cookbooks' do + expect(chef_run).not_to run_execute('unit_rspec_julia') + expect(chef_run).not_to run_execute('unit_rspec_gordon') + expect(chef_run).not_to run_execute('unit_rspec_emeril') end end end