summaryrefslogtreecommitdiff
path: root/spec/unit/knife/core
diff options
context:
space:
mode:
Diffstat (limited to 'spec/unit/knife/core')
-rw-r--r--spec/unit/knife/core/bootstrap_context_spec.rb26
-rw-r--r--spec/unit/knife/core/cookbook_scm_repo_spec.rb48
-rw-r--r--spec/unit/knife/core/custom_manifest_loader_spec.rb4
-rw-r--r--spec/unit/knife/core/gem_glob_loader_spec.rb28
-rw-r--r--spec/unit/knife/core/hashed_command_loader_spec.rb4
-rw-r--r--spec/unit/knife/core/node_editor_spec.rb130
-rw-r--r--spec/unit/knife/core/object_loader_spec.rb20
-rw-r--r--spec/unit/knife/core/subcommand_loader_spec.rb18
-rw-r--r--spec/unit/knife/core/ui_spec.rb48
9 files changed, 163 insertions, 163 deletions
diff --git a/spec/unit/knife/core/bootstrap_context_spec.rb b/spec/unit/knife/core/bootstrap_context_spec.rb
index 1d93f64e32..7ecade338a 100644
--- a/spec/unit/knife/core/bootstrap_context_spec.rb
+++ b/spec/unit/knife/core/bootstrap_context_spec.rb
@@ -16,17 +16,17 @@
# limitations under the License.
#
-require 'spec_helper'
-require 'chef/knife/core/bootstrap_context'
+require "spec_helper"
+require "chef/knife/core/bootstrap_context"
describe Chef::Knife::Core::BootstrapContext do
let(:config) { {:foo => :bar, :color => true} }
- let(:run_list) { Chef::RunList.new('recipe[tmux]', 'role[base]') }
+ let(:run_list) { Chef::RunList.new("recipe[tmux]", "role[base]") }
let(:chef_config) do
{
- :validation_key => File.join(CHEF_SPEC_DATA, 'ssl', 'private_key.pem'),
- :chef_server_url => 'http://chef.example.com:4444',
- :validation_client_name => 'chef-validator-testing',
+ :validation_key => File.join(CHEF_SPEC_DATA, "ssl", "private_key.pem"),
+ :chef_server_url => "http://chef.example.com:4444",
+ :validation_client_name => "chef-validator-testing",
}
end
@@ -57,7 +57,7 @@ describe Chef::Knife::Core::BootstrapContext do
end
it "reads the validation key" do
- expect(bootstrap_context.validation_key).to eq IO.read(File.join(CHEF_SPEC_DATA, 'ssl', 'private_key.pem'))
+ expect(bootstrap_context.validation_key).to eq IO.read(File.join(CHEF_SPEC_DATA, "ssl", "private_key.pem"))
end
it "generates the config file data" do
@@ -75,23 +75,23 @@ EXPECTED
end
describe "alternate chef-client path" do
- let(:chef_config){ {:chef_client_path => '/usr/local/bin/chef-client'} }
+ let(:chef_config){ {:chef_client_path => "/usr/local/bin/chef-client"} }
it "runs chef-client from another path when specified" do
expect(bootstrap_context.start_chef).to eq "/usr/local/bin/chef-client -j /etc/chef/first-boot.json"
end
end
describe "validation key path that contains a ~" do
- let(:chef_config){ {:validation_key => '~/my.key'} }
+ let(:chef_config){ {:validation_key => "~/my.key"} }
it "reads the validation key when it contains a ~" do
- expect(File).to receive(:exist?).with(File.expand_path("my.key", ENV['HOME'])).and_return(true)
- expect(IO).to receive(:read).with(File.expand_path("my.key", ENV['HOME']))
+ expect(File).to receive(:exist?).with(File.expand_path("my.key", ENV["HOME"])).and_return(true)
+ expect(IO).to receive(:read).with(File.expand_path("my.key", ENV["HOME"]))
bootstrap_context.validation_key
end
end
describe "when an explicit node name is given" do
- let(:config){ {:chef_node_name => 'foobar.example.com' }}
+ let(:config){ {:chef_node_name => "foobar.example.com" }}
it "sets the node name in the client.rb" do
expect(bootstrap_context.config_content).to match(/node_name "foobar\.example\.com"/)
end
@@ -100,7 +100,7 @@ EXPECTED
describe "when bootstrapping into a specific environment" do
let(:config){ {:environment => "prodtastic", :color => true} }
it "starts chef in the configured environment" do
- expect(bootstrap_context.start_chef).to eq('chef-client -j /etc/chef/first-boot.json -E prodtastic')
+ expect(bootstrap_context.start_chef).to eq("chef-client -j /etc/chef/first-boot.json -E prodtastic")
end
end
diff --git a/spec/unit/knife/core/cookbook_scm_repo_spec.rb b/spec/unit/knife/core/cookbook_scm_repo_spec.rb
index 2d66df31c1..b29091188e 100644
--- a/spec/unit/knife/core/cookbook_scm_repo_spec.rb
+++ b/spec/unit/knife/core/cookbook_scm_repo_spec.rb
@@ -16,15 +16,15 @@
# limitations under the License.
#
-require 'spec_helper'
-require 'chef/knife/core/cookbook_scm_repo'
+require "spec_helper"
+require "chef/knife/core/cookbook_scm_repo"
describe Chef::Knife::CookbookSCMRepo do
before do
- @repo_path = File.join(CHEF_SPEC_DATA, 'cookbooks')
+ @repo_path = File.join(CHEF_SPEC_DATA, "cookbooks")
@stdout, @stderr, @stdin = StringIO.new, StringIO.new, StringIO.new
@ui = Chef::Knife::UI.new(@stdout, @stderr, @stdin, {})
- @cookbook_repo = Chef::Knife::CookbookSCMRepo.new(@repo_path, @ui, :default_branch => 'master')
+ @cookbook_repo = Chef::Knife::CookbookSCMRepo.new(@repo_path, @ui, :default_branch => "master")
@branch_list = Mixlib::ShellOut.new
@branch_list.stdout.replace(<<-BRANCHES)
@@ -43,7 +43,7 @@ BRANCHES
end
it "has a default branch" do
- expect(@cookbook_repo.default_branch).to eq('master')
+ expect(@cookbook_repo.default_branch).to eq("master")
end
describe "when sanity checking the repo" do
@@ -64,12 +64,12 @@ BRANCHES
describe "and the repo is a git repo" do
before do
- allow(::File).to receive(:directory?).with(File.join(@repo_path, '.git')).and_return(true)
+ allow(::File).to receive(:directory?).with(File.join(@repo_path, ".git")).and_return(true)
end
it "exits when the default branch doesn't exist" do
@nobranches = Mixlib::ShellOut.new.tap {|s|s.stdout.replace "\n"}
- expect(@cookbook_repo).to receive(:shell_out!).with('git branch --no-color', :cwd => @repo_path).and_return(@nobranches)
+ expect(@cookbook_repo).to receive(:shell_out!).with("git branch --no-color", :cwd => @repo_path).and_return(@nobranches)
expect {@cookbook_repo.sanity_check}.to raise_error(SystemExit)
end
@@ -85,14 +85,14 @@ BRANCHES
@dirty_status.stdout.replace(<<-DIRTY)
M chef/lib/chef/knife/cookbook_site_vendor.rb
DIRTY
- expect(@cookbook_repo).to receive(:shell_out!).with('git status --porcelain', :cwd => @repo_path).and_return(@dirty_status)
+ expect(@cookbook_repo).to receive(:shell_out!).with("git status --porcelain", :cwd => @repo_path).and_return(@dirty_status)
expect {@cookbook_repo.sanity_check}.to raise_error(SystemExit)
end
describe "and the repo is clean" do
before do
@clean_status = Mixlib::ShellOut.new.tap {|s| s.stdout.replace("\n")}
- allow(@cookbook_repo).to receive(:shell_out!).with('git status --porcelain', :cwd => @repo_path).and_return(@clean_status)
+ allow(@cookbook_repo).to receive(:shell_out!).with("git status --porcelain", :cwd => @repo_path).and_return(@clean_status)
end
it "passes the sanity check" do
@@ -106,35 +106,35 @@ DIRTY
end
it "resets to default state by checking out the default branch" do
- expect(@cookbook_repo).to receive(:shell_out!).with('git checkout master', :cwd => @repo_path)
+ expect(@cookbook_repo).to receive(:shell_out!).with("git checkout master", :cwd => @repo_path)
@cookbook_repo.reset_to_default_state
end
it "determines if a the pristine copy branch exists" do
- expect(@cookbook_repo).to receive(:shell_out!).with('git branch --no-color', :cwd => @repo_path).and_return(@branch_list)
+ expect(@cookbook_repo).to receive(:shell_out!).with("git branch --no-color", :cwd => @repo_path).and_return(@branch_list)
expect(@cookbook_repo.branch_exists?("chef-vendor-apache2")).to be_truthy
- expect(@cookbook_repo).to receive(:shell_out!).with('git branch --no-color', :cwd => @repo_path).and_return(@branch_list)
+ expect(@cookbook_repo).to receive(:shell_out!).with("git branch --no-color", :cwd => @repo_path).and_return(@branch_list)
expect(@cookbook_repo.branch_exists?("chef-vendor-nginx")).to be_falsey
end
it "determines if a the branch not exists correctly without substring search" do
- expect(@cookbook_repo).to receive(:shell_out!).twice.with('git branch --no-color', :cwd => @repo_path).and_return(@branch_list)
+ expect(@cookbook_repo).to receive(:shell_out!).twice.with("git branch --no-color", :cwd => @repo_path).and_return(@branch_list)
expect(@cookbook_repo).not_to be_branch_exists("chef-vendor-absent")
expect(@cookbook_repo).to be_branch_exists("chef-vendor-absent-new")
end
describe "when the pristine copy branch does not exist" do
it "prepares for import by creating the pristine copy branch" do
- expect(@cookbook_repo).to receive(:shell_out!).with('git branch --no-color', :cwd => @repo_path).and_return(@branch_list)
- expect(@cookbook_repo).to receive(:shell_out!).with('git checkout -b chef-vendor-nginx', :cwd => @repo_path)
+ expect(@cookbook_repo).to receive(:shell_out!).with("git branch --no-color", :cwd => @repo_path).and_return(@branch_list)
+ expect(@cookbook_repo).to receive(:shell_out!).with("git checkout -b chef-vendor-nginx", :cwd => @repo_path)
@cookbook_repo.prepare_to_import("nginx")
end
end
describe "when the pristine copy branch does exist" do
it "prepares for import by checking out the pristine copy branch" do
- expect(@cookbook_repo).to receive(:shell_out!).with('git branch --no-color', :cwd => @repo_path).and_return(@branch_list)
- expect(@cookbook_repo).to receive(:shell_out!).with('git checkout chef-vendor-apache2', :cwd => @repo_path)
+ expect(@cookbook_repo).to receive(:shell_out!).with("git branch --no-color", :cwd => @repo_path).and_return(@branch_list)
+ expect(@cookbook_repo).to receive(:shell_out!).with("git checkout chef-vendor-apache2", :cwd => @repo_path)
@cookbook_repo.prepare_to_import("apache2")
end
end
@@ -143,15 +143,15 @@ DIRTY
before do
@updates = Mixlib::ShellOut.new
@updates.stdout.replace("\n")
- allow(@cookbook_repo).to receive(:shell_out!).with('git status --porcelain -- apache2', :cwd => @repo_path).and_return(@updates)
+ allow(@cookbook_repo).to receive(:shell_out!).with("git status --porcelain -- apache2", :cwd => @repo_path).and_return(@updates)
end
it "shows no changes in the pristine copy" do
- expect(@cookbook_repo.updated?('apache2')).to be_falsey
+ expect(@cookbook_repo.updated?("apache2")).to be_falsey
end
it "does nothing to finalize the updates" do
- expect(@cookbook_repo.finalize_updates_to('apache2', '1.2.3')).to be_falsey
+ expect(@cookbook_repo.finalize_updates_to("apache2", "1.2.3")).to be_falsey
end
end
@@ -159,11 +159,11 @@ DIRTY
before do
@updates = Mixlib::ShellOut.new
@updates.stdout.replace(" M cookbooks/apache2/recipes/default.rb\n")
- allow(@cookbook_repo).to receive(:shell_out!).with('git status --porcelain -- apache2', :cwd => @repo_path).and_return(@updates)
+ allow(@cookbook_repo).to receive(:shell_out!).with("git status --porcelain -- apache2", :cwd => @repo_path).and_return(@updates)
end
it "shows changes in the pristine copy" do
- expect(@cookbook_repo.updated?('apache2')).to be_truthy
+ expect(@cookbook_repo.updated?("apache2")).to be_truthy
end
it "commits the changes to the repo and tags the commit" do
@@ -176,11 +176,11 @@ DIRTY
describe "when a custom default branch is specified" do
before do
- @cookbook_repo = Chef::Knife::CookbookSCMRepo.new(@repo_path, @ui, :default_branch => 'develop')
+ @cookbook_repo = Chef::Knife::CookbookSCMRepo.new(@repo_path, @ui, :default_branch => "develop")
end
it "resets to default state by checking out the default branch" do
- expect(@cookbook_repo).to receive(:shell_out!).with('git checkout develop', :cwd => @repo_path)
+ expect(@cookbook_repo).to receive(:shell_out!).with("git checkout develop", :cwd => @repo_path)
@cookbook_repo.reset_to_default_state
end
end
diff --git a/spec/unit/knife/core/custom_manifest_loader_spec.rb b/spec/unit/knife/core/custom_manifest_loader_spec.rb
index 1edbedd3c8..f15710274c 100644
--- a/spec/unit/knife/core/custom_manifest_loader_spec.rb
+++ b/spec/unit/knife/core/custom_manifest_loader_spec.rb
@@ -15,7 +15,7 @@
# limitations under the License.
#
-require 'spec_helper'
+require "spec_helper"
describe Chef::Knife::SubcommandLoader::CustomManifestLoader do
let(:ec2_server_create_plugin) { "/usr/lib/ruby/gems/knife-ec2-0.5.12/lib/chef/knife/ec2_server_create.rb" }
@@ -30,7 +30,7 @@ describe Chef::Knife::SubcommandLoader::CustomManifestLoader do
}
end
let(:loader) do
- Chef::Knife::SubcommandLoader::CustomManifestLoader.new(File.join(CHEF_SPEC_DATA, 'knife-site-subcommands'),
+ Chef::Knife::SubcommandLoader::CustomManifestLoader.new(File.join(CHEF_SPEC_DATA, "knife-site-subcommands"),
manifest_content)
end
diff --git a/spec/unit/knife/core/gem_glob_loader_spec.rb b/spec/unit/knife/core/gem_glob_loader_spec.rb
index 89de9f98e4..671fabf695 100644
--- a/spec/unit/knife/core/gem_glob_loader_spec.rb
+++ b/spec/unit/knife/core/gem_glob_loader_spec.rb
@@ -15,12 +15,12 @@
# limitations under the License.
#
-require 'spec_helper'
+require "spec_helper"
describe Chef::Knife::SubcommandLoader::GemGlobLoader do
- let(:loader) { Chef::Knife::SubcommandLoader::GemGlobLoader.new(File.join(CHEF_SPEC_DATA, 'knife-site-subcommands')) }
- let(:home) { File.join(CHEF_SPEC_DATA, 'knife-home') }
- let(:plugin_dir) { File.join(home, '.chef', 'plugins', 'knife') }
+ let(:loader) { Chef::Knife::SubcommandLoader::GemGlobLoader.new(File.join(CHEF_SPEC_DATA, "knife-site-subcommands")) }
+ let(:home) { File.join(CHEF_SPEC_DATA, "knife-home") }
+ let(:plugin_dir) { File.join(home, ".chef", "plugins", "knife") }
before do
allow(ChefConfig).to receive(:windows?) { false }
@@ -39,15 +39,15 @@ describe Chef::Knife::SubcommandLoader::GemGlobLoader do
end
it "finds files installed via rubygems" do
- expect(loader.find_subcommands_via_rubygems).to include('chef/knife/node_create')
+ expect(loader.find_subcommands_via_rubygems).to include("chef/knife/node_create")
loader.find_subcommands_via_rubygems.each {|rel_path, abs_path| expect(abs_path).to match(%r[chef/knife/.+])}
end
it "finds files from latest version of installed gems" do
- gems = [ double('knife-ec2-0.5.12') ]
+ gems = [ double("knife-ec2-0.5.12") ]
gem_files = [
- '/usr/lib/ruby/gems/knife-ec2-0.5.12/lib/chef/knife/ec2_base.rb',
- '/usr/lib/ruby/gems/knife-ec2-0.5.12/lib/chef/knife/ec2_otherstuff.rb',
+ "/usr/lib/ruby/gems/knife-ec2-0.5.12/lib/chef/knife/ec2_base.rb",
+ "/usr/lib/ruby/gems/knife-ec2-0.5.12/lib/chef/knife/ec2_otherstuff.rb",
]
expect($LOAD_PATH).to receive(:map).and_return([])
if Gem::Specification.respond_to? :latest_specs
@@ -55,26 +55,26 @@ describe Chef::Knife::SubcommandLoader::GemGlobLoader do
expect(gems[0]).to receive(:matches_for_glob).with(/chef\/knife\/\*\.rb\{(.*),\.rb,(.*)\}/).and_return(gem_files)
else
expect(Gem.source_index).to receive(:latest_specs).with(true).and_return(gems)
- expect(gems[0]).to receive(:require_paths).twice.and_return(['lib'])
- expect(gems[0]).to receive(:full_gem_path).and_return('/usr/lib/ruby/gems/knife-ec2-0.5.12')
- expect(Dir).to receive(:[]).with('/usr/lib/ruby/gems/knife-ec2-0.5.12/lib/chef/knife/*.rb').and_return(gem_files)
+ expect(gems[0]).to receive(:require_paths).twice.and_return(["lib"])
+ expect(gems[0]).to receive(:full_gem_path).and_return("/usr/lib/ruby/gems/knife-ec2-0.5.12")
+ expect(Dir).to receive(:[]).with("/usr/lib/ruby/gems/knife-ec2-0.5.12/lib/chef/knife/*.rb").and_return(gem_files)
end
expect(loader).to receive(:find_subcommands_via_dirglob).and_return({})
expect(loader.subcommand_files.select { |file| file =~ /knife-ec2/ }.sort).to eq(gem_files)
end
it "finds files using a dirglob when rubygems is not available" do
- expect(loader.find_subcommands_via_dirglob).to include('chef/knife/node_create')
+ expect(loader.find_subcommands_via_dirglob).to include("chef/knife/node_create")
loader.find_subcommands_via_dirglob.each {|rel_path, abs_path| expect(abs_path).to match(%r[chef/knife/.+])}
end
it "finds user-specific subcommands in the user's ~/.chef directory" do
- expected_command = File.join(home, '.chef', 'plugins', 'knife', 'example_home_subcommand.rb')
+ expected_command = File.join(home, ".chef", "plugins", "knife", "example_home_subcommand.rb")
expect(loader.site_subcommands).to include(expected_command)
end
it "finds repo specific subcommands by searching for a .chef directory" do
- expected_command = File.join(CHEF_SPEC_DATA, 'knife-site-subcommands', 'plugins', 'knife', 'example_subcommand.rb')
+ expected_command = File.join(CHEF_SPEC_DATA, "knife-site-subcommands", "plugins", "knife", "example_subcommand.rb")
expect(loader.site_subcommands).to include(expected_command)
end
diff --git a/spec/unit/knife/core/hashed_command_loader_spec.rb b/spec/unit/knife/core/hashed_command_loader_spec.rb
index 1a6c2f42b7..45ee377ac6 100644
--- a/spec/unit/knife/core/hashed_command_loader_spec.rb
+++ b/spec/unit/knife/core/hashed_command_loader_spec.rb
@@ -15,7 +15,7 @@
# limitations under the License.
#
-require 'spec_helper'
+require "spec_helper"
describe Chef::Knife::SubcommandLoader::HashedCommandLoader do
before do
@@ -42,7 +42,7 @@ describe Chef::Knife::SubcommandLoader::HashedCommandLoader do
}
let(:loader) { Chef::Knife::SubcommandLoader::HashedCommandLoader.new(
- File.join(CHEF_SPEC_DATA, 'knife-site-subcommands'),
+ File.join(CHEF_SPEC_DATA, "knife-site-subcommands"),
plugin_manifest)}
describe "#list_commands" do
diff --git a/spec/unit/knife/core/node_editor_spec.rb b/spec/unit/knife/core/node_editor_spec.rb
index 52e3aeadd5..2c1beb6ccb 100644
--- a/spec/unit/knife/core/node_editor_spec.rb
+++ b/spec/unit/knife/core/node_editor_spec.rb
@@ -16,34 +16,34 @@
# limitations under the License.
#
-require 'spec_helper'
-require 'chef/knife/core/node_editor'
+require "spec_helper"
+require "chef/knife/core/node_editor"
describe Chef::Knife::NodeEditor do
let(:node_data) do
- { 'name' => 'test_node',
- 'chef_environment' => 'production',
- 'automatic' => { 'foo' => 'bar' },
- 'default' => { 'alpha' => { 'bravo' => 'charlie', 'delta' => 'echo' } },
- 'normal' => { 'alpha' => { 'bravo' => 'hotel' }, 'tags' => [] },
- 'override' => { 'alpha' => { 'bravo' => 'foxtrot', 'delta' => 'golf' } },
- 'policy_name' => nil,
- 'policy_group' => nil,
- 'run_list' => %w(role[comedy] role[drama] recipe[mystery])
+ { "name" => "test_node",
+ "chef_environment" => "production",
+ "automatic" => { "foo" => "bar" },
+ "default" => { "alpha" => { "bravo" => "charlie", "delta" => "echo" } },
+ "normal" => { "alpha" => { "bravo" => "hotel" }, "tags" => [] },
+ "override" => { "alpha" => { "bravo" => "foxtrot", "delta" => "golf" } },
+ "policy_name" => nil,
+ "policy_group" => nil,
+ "run_list" => %w(role[comedy] role[drama] recipe[mystery]),
}
end
let(:node) { Chef::Node.from_hash(node_data) }
- let(:ui) { double 'ui' }
- let(:base_config) { { editor: 'cat' } }
+ let(:ui) { double "ui" }
+ let(:base_config) { { editor: "cat" } }
let(:config) { base_config.merge(all_attributes: false) }
subject { described_class.new(node, ui, config) }
describe '#view' do
- it 'returns a Hash with only the name, chef_environment, normal, ' +
- 'policy_name, policy_group, and run_list properties' do
+ it "returns a Hash with only the name, chef_environment, normal, " +
+ "policy_name, policy_group, and run_list properties" do
expected = node_data.select do |key,|
%w[ name chef_environment normal
policy_name policy_group run_list ].include?(key)
@@ -52,7 +52,7 @@ describe Chef::Knife::NodeEditor do
expect(subject.view).to eq(expected)
end
- context 'when config[:all_attributes] == true' do
+ context "when config[:all_attributes] == true" do
let(:config) { base_config.merge(all_attributes: true) }
it 'returns a Hash with all of the node\'s properties' do
@@ -62,49 +62,49 @@ describe Chef::Knife::NodeEditor do
end
describe '#apply_updates' do
- context 'when the node name is changed' do
+ context "when the node name is changed" do
before(:each) do
allow(ui).to receive(:warn)
allow(ui).to receive(:confirm).and_return(true)
end
- it 'emits a warning and prompts for confirmation' do
- data = subject.view.merge('name' => 'foo_new_name_node')
+ it "emits a warning and prompts for confirmation" do
+ data = subject.view.merge("name" => "foo_new_name_node")
updated_node = subject.apply_updates(data)
expect(ui).to have_received(:warn)
- .with 'Changing the name of a node results in a new node being ' +
- 'created, test_node will not be modified or removed.'
+ .with "Changing the name of a node results in a new node being " +
+ "created, test_node will not be modified or removed."
expect(ui).to have_received(:confirm)
- .with('Proceed with creation of new node')
+ .with("Proceed with creation of new node")
expect(updated_node).to be_a(Chef::Node)
end
end
- context 'when config[:all_attributes] == false' do
+ context "when config[:all_attributes] == false" do
let(:config) { base_config.merge(all_attributes: false) }
let(:updated_data) do
subject.view.merge(
- 'normal' => { 'alpha' => { 'bravo' => 'hotel2' }, 'tags' => [ 'xyz' ] },
- 'policy_name' => 'mypolicy',
- 'policy_group' => 'prod',
- 'run_list' => %w(role[drama] recipe[mystery])
+ "normal" => { "alpha" => { "bravo" => "hotel2" }, "tags" => [ "xyz" ] },
+ "policy_name" => "mypolicy",
+ "policy_group" => "prod",
+ "run_list" => %w(role[drama] recipe[mystery]),
)
end
- it 'returns a node with run_list and normal_attrs changed' do
+ it "returns a node with run_list and normal_attrs changed" do
updated_node = subject.apply_updates(updated_data)
expect(updated_node).to be_a(Chef::Node)
# Expected to have been changed
- expect(updated_node.chef_environment).to eql(updated_data['chef_environment'])
- expect(updated_node.normal_attrs).to eql(updated_data['normal'])
- expect(updated_node.policy_name).to eql(updated_data['policy_name'])
- expect(updated_node.policy_group).to eql(updated_data['policy_group'])
- expect(updated_node.run_list.map(&:to_s)).to eql(updated_data['run_list'])
+ expect(updated_node.chef_environment).to eql(updated_data["chef_environment"])
+ expect(updated_node.normal_attrs).to eql(updated_data["normal"])
+ expect(updated_node.policy_name).to eql(updated_data["policy_name"])
+ expect(updated_node.policy_group).to eql(updated_data["policy_group"])
+ expect(updated_node.run_list.map(&:to_s)).to eql(updated_data["run_list"])
# Expected not to have changed
expect(updated_node.default_attrs).to eql(node.default_attrs)
@@ -113,57 +113,57 @@ describe Chef::Knife::NodeEditor do
end
end
- context 'when config[:all_attributes] == true' do
+ context "when config[:all_attributes] == true" do
let(:config) { base_config.merge(all_attributes: true) }
let(:updated_data) do
subject.view.merge(
- 'default' => { 'alpha' => { 'bravo' => 'charlie2', 'delta' => 'echo2' } },
- 'normal' => { 'alpha' => { 'bravo' => 'hotel2' }, 'tags' => [ 'xyz' ] },
- 'override' => { 'alpha' => { 'bravo' => 'foxtrot2', 'delta' => 'golf2' } },
- 'policy_name' => 'mypolicy',
- 'policy_group' => 'prod',
- 'run_list' => %w(role[drama] recipe[mystery])
+ "default" => { "alpha" => { "bravo" => "charlie2", "delta" => "echo2" } },
+ "normal" => { "alpha" => { "bravo" => "hotel2" }, "tags" => [ "xyz" ] },
+ "override" => { "alpha" => { "bravo" => "foxtrot2", "delta" => "golf2" } },
+ "policy_name" => "mypolicy",
+ "policy_group" => "prod",
+ "run_list" => %w(role[drama] recipe[mystery]),
)
end
- it 'returns a node with all editable properties changed' do
+ it "returns a node with all editable properties changed" do
updated_node = subject.apply_updates(updated_data)
expect(updated_node).to be_a(Chef::Node)
- expect(updated_node.chef_environment).to eql(updated_data['chef_environment'])
- expect(updated_node.automatic_attrs).to eql(updated_data['automatic'])
- expect(updated_node.normal_attrs).to eql(updated_data['normal'])
- expect(updated_node.default_attrs).to eql(updated_data['default'])
- expect(updated_node.override_attrs).to eql(updated_data['override'])
- expect(updated_node.policy_name).to eql(updated_data['policy_name'])
- expect(updated_node.policy_group).to eql(updated_data['policy_group'])
- expect(updated_node.run_list.map(&:to_s)).to eql(updated_data['run_list'])
+ expect(updated_node.chef_environment).to eql(updated_data["chef_environment"])
+ expect(updated_node.automatic_attrs).to eql(updated_data["automatic"])
+ expect(updated_node.normal_attrs).to eql(updated_data["normal"])
+ expect(updated_node.default_attrs).to eql(updated_data["default"])
+ expect(updated_node.override_attrs).to eql(updated_data["override"])
+ expect(updated_node.policy_name).to eql(updated_data["policy_name"])
+ expect(updated_node.policy_group).to eql(updated_data["policy_group"])
+ expect(updated_node.run_list.map(&:to_s)).to eql(updated_data["run_list"])
end
end
end
describe '#updated?' do
- context 'before the node has been edited' do
- it 'returns false' do
+ context "before the node has been edited" do
+ it "returns false" do
expect(subject.updated?).to be false
end
end
- context 'after the node has been edited' do
- context 'and changes were made' do
+ context "after the node has been edited" do
+ context "and changes were made" do
let(:updated_data) do
subject.view.merge(
- 'default' => { 'alpha' => { 'bravo' => 'charlie2', 'delta' => 'echo2' } },
- 'normal' => { 'alpha' => { 'bravo' => 'hotel2' }, 'tags' => [ 'xyz' ] },
- 'override' => { 'alpha' => { 'bravo' => 'foxtrot2', 'delta' => 'golf2' } },
- 'policy_name' => 'mypolicy',
- 'policy_group' => 'prod',
- 'run_list' => %w(role[drama] recipe[mystery])
+ "default" => { "alpha" => { "bravo" => "charlie2", "delta" => "echo2" } },
+ "normal" => { "alpha" => { "bravo" => "hotel2" }, "tags" => [ "xyz" ] },
+ "override" => { "alpha" => { "bravo" => "foxtrot2", "delta" => "golf2" } },
+ "policy_name" => "mypolicy",
+ "policy_group" => "prod",
+ "run_list" => %w(role[drama] recipe[mystery]),
)
end
- context 'and changes affect only editable properties' do
+ context "and changes affect only editable properties" do
before(:each) do
allow(ui).to receive(:edit_data)
.with(subject.view)
@@ -172,14 +172,14 @@ describe Chef::Knife::NodeEditor do
subject.edit_node
end
- it 'returns an array of the changed property names' do
+ it "returns an array of the changed property names" do
expect(subject.updated?).to eql %w[ normal policy_name policy_group run_list ]
end
end
- context 'and the changes include non-editable properties' do
+ context "and the changes include non-editable properties" do
before(:each) do
- data = updated_data.merge('bad_property' => 'bad_value')
+ data = updated_data.merge("bad_property" => "bad_value")
allow(ui).to receive(:edit_data)
.with(subject.view)
@@ -189,13 +189,13 @@ describe Chef::Knife::NodeEditor do
end
it 'returns an array of property names that doesn\'t include ' +
- 'the non-editable properties' do
+ "the non-editable properties" do
expect(subject.updated?).to eql %w[ normal policy_name policy_group run_list ]
end
end
end
- context 'and changes were not made' do
+ context "and changes were not made" do
before(:each) do
allow(ui).to receive(:edit_data)
.with(subject.view)
diff --git a/spec/unit/knife/core/object_loader_spec.rb b/spec/unit/knife/core/object_loader_spec.rb
index 0b572cc1f0..50f358379e 100644
--- a/spec/unit/knife/core/object_loader_spec.rb
+++ b/spec/unit/knife/core/object_loader_spec.rb
@@ -17,15 +17,15 @@
# limitations under the License.
#
-require 'spec_helper'
-require 'chef/knife/core/object_loader'
+require "spec_helper"
+require "chef/knife/core/object_loader"
describe Chef::Knife::Core::ObjectLoader do
before(:each) do
@knife = Chef::Knife.new
@stdout = StringIO.new
allow(@knife.ui).to receive(:stdout).and_return(@stdout)
- Dir.chdir(File.join(CHEF_SPEC_DATA, 'object_loader'))
+ Dir.chdir(File.join(CHEF_SPEC_DATA, "object_loader"))
end
shared_examples_for "Chef object" do |chef_class|
@@ -34,14 +34,14 @@ describe Chef::Knife::Core::ObjectLoader do
end
it "should has a attribute 'name'" do
- expect(@object.name).to eql('test')
+ expect(@object.name).to eql("test")
end
end
{
- 'nodes' => Chef::Node,
- 'roles' => Chef::Role,
- 'environments' => Chef::Environment,
+ "nodes" => Chef::Node,
+ "roles" => Chef::Role,
+ "environments" => Chef::Environment,
}.each do |repo_location, chef_class|
describe "when the file is a #{chef_class}" do
@@ -51,7 +51,7 @@ describe Chef::Knife::Core::ObjectLoader do
describe "when the file is a Ruby" do
before do
- @object = @loader.load_from(repo_location, 'test.rb')
+ @object = @loader.load_from(repo_location, "test.rb")
end
it_behaves_like "Chef object", chef_class
@@ -61,7 +61,7 @@ describe Chef::Knife::Core::ObjectLoader do
describe "when the file is a JSON" do
describe "and it has defined 'json_class'" do
before do
- @object = @loader.load_from(repo_location, 'test_json_class.json')
+ @object = @loader.load_from(repo_location, "test_json_class.json")
end
it_behaves_like "Chef object", chef_class
@@ -69,7 +69,7 @@ describe Chef::Knife::Core::ObjectLoader do
describe "and it has not defined 'json_class'" do
before do
- @object = @loader.load_from(repo_location, 'test.json')
+ @object = @loader.load_from(repo_location, "test.json")
end
it_behaves_like "Chef object", chef_class
diff --git a/spec/unit/knife/core/subcommand_loader_spec.rb b/spec/unit/knife/core/subcommand_loader_spec.rb
index 2386465c75..c1712c297e 100644
--- a/spec/unit/knife/core/subcommand_loader_spec.rb
+++ b/spec/unit/knife/core/subcommand_loader_spec.rb
@@ -15,12 +15,12 @@
# limitations under the License.
#
-require 'spec_helper'
+require "spec_helper"
describe Chef::Knife::SubcommandLoader do
- let(:loader) { Chef::Knife::SubcommandLoader.new(File.join(CHEF_SPEC_DATA, 'knife-site-subcommands')) }
- let(:home) { File.join(CHEF_SPEC_DATA, 'knife-home') }
- let(:plugin_dir) { File.join(home, '.chef', 'plugins', 'knife') }
+ let(:loader) { Chef::Knife::SubcommandLoader.new(File.join(CHEF_SPEC_DATA, "knife-site-subcommands")) }
+ let(:home) { File.join(CHEF_SPEC_DATA, "knife-home") }
+ let(:plugin_dir) { File.join(home, ".chef", "plugins", "knife") }
before do
allow(ChefConfig).to receive(:windows?) { false }
@@ -31,29 +31,29 @@ describe Chef::Knife::SubcommandLoader do
Chef::Util::PathHelper.class_variable_set(:@@home_dir, nil)
end
- let(:config_dir) { File.join(CHEF_SPEC_DATA, 'knife-site-subcommands') }
+ let(:config_dir) { File.join(CHEF_SPEC_DATA, "knife-site-subcommands") }
describe "#for_config" do
context "when ~/.chef/plugin_manifest.json exists" do
before do
- allow(File).to receive(:exist?).with(File.join(home, '.chef', 'plugin_manifest.json')).and_return(true)
+ allow(File).to receive(:exist?).with(File.join(home, ".chef", "plugin_manifest.json")).and_return(true)
end
it "creates a HashedCommandLoader with the manifest has _autogenerated_command_paths" do
- allow(File).to receive(:read).with(File.join(home, '.chef', 'plugin_manifest.json')).and_return("{ \"_autogenerated_command_paths\": {}}")
+ allow(File).to receive(:read).with(File.join(home, ".chef", "plugin_manifest.json")).and_return("{ \"_autogenerated_command_paths\": {}}")
expect(Chef::Knife::SubcommandLoader.for_config(config_dir)).to be_a Chef::Knife::SubcommandLoader::HashedCommandLoader
end
it "creates a CustomManifestLoader with then manifest has a key other than _autogenerated_command_paths" do
Chef::Config[:treat_deprecation_warnings_as_errors] = false
- allow(File).to receive(:read).with(File.join(home, '.chef', 'plugin_manifest.json')).and_return("{ \"plugins\": {}}")
+ allow(File).to receive(:read).with(File.join(home, ".chef", "plugin_manifest.json")).and_return("{ \"plugins\": {}}")
expect(Chef::Knife::SubcommandLoader.for_config(config_dir)).to be_a Chef::Knife::SubcommandLoader::CustomManifestLoader
end
end
context "when ~/.chef/plugin_manifest.json does not exist" do
before do
- allow(File).to receive(:exist?).with(File.join(home, '.chef', 'plugin_manifest.json')).and_return(false)
+ allow(File).to receive(:exist?).with(File.join(home, ".chef", "plugin_manifest.json")).and_return(false)
end
it "creates a GemGlobLoader" do
diff --git a/spec/unit/knife/core/ui_spec.rb b/spec/unit/knife/core/ui_spec.rb
index 2c3b067e4f..b5b6a0a179 100644
--- a/spec/unit/knife/core/ui_spec.rb
+++ b/spec/unit/knife/core/ui_spec.rb
@@ -19,7 +19,7 @@
# limitations under the License.
#
-require 'spec_helper'
+require "spec_helper"
describe Chef::Knife::UI do
before do
@@ -33,10 +33,10 @@ describe Chef::Knife::UI do
end
describe "edit" do
- ruby_for_json = { 'foo' => 'bar' }
+ ruby_for_json = { "foo" => "bar" }
json_from_ruby = "{\n \"foo\": \"bar\"\n}"
json_from_editor = "{\n \"bar\": \"foo\"\n}"
- ruby_from_editor = { 'bar' => 'foo' }
+ ruby_from_editor = { "bar" => "foo" }
my_editor = "veeeye"
temp_path = "/tmp/bar/baz"
@@ -66,12 +66,12 @@ describe Chef::Knife::UI do
before do
@ui.config[:disable_editing] = false
@ui.config[:editor] = my_editor
- @mock = double('Tempfile')
+ @mock = double("Tempfile")
expect(@mock).to receive(:sync=).with(true)
expect(@mock).to receive(:puts).with(json_from_ruby)
expect(@mock).to receive(:close)
expect(@mock).to receive(:path).at_least(:once).and_return(temp_path)
- expect(Tempfile).to receive(:open).with([ 'knife-edit-', '.json' ]).and_yield(@mock)
+ expect(Tempfile).to receive(:open).with([ "knife-edit-", ".json" ]).and_yield(@mock)
end
context "and the editor works" do
before do
@@ -114,8 +114,8 @@ describe Chef::Knife::UI do
before do
@ui.config[:disable_editing] = false
@ui.config[:editor] = my_editor
- @tempfile = Tempfile.new([ 'knife-edit-', '.json' ])
- expect(Tempfile).to receive(:open).with([ 'knife-edit-', '.json' ]).and_yield(@tempfile)
+ @tempfile = Tempfile.new([ "knife-edit-", ".json" ])
+ expect(Tempfile).to receive(:open).with([ "knife-edit-", ".json" ]).and_yield(@tempfile)
end
context "and the editor works" do
@@ -192,7 +192,7 @@ describe Chef::Knife::UI do
end
it "formats hashes appropriately" do
- @ui.output({'hi' => 'a', 'lo' => 'b' })
+ @ui.output({"hi" => "a", "lo" => "b" })
expect(@out.string).to eq <<EOM
hi: a
lo: b
@@ -205,7 +205,7 @@ EOM
end
it "formats arrays appropriately" do
- @ui.output([ 'a', 'b' ])
+ @ui.output([ "a", "b" ])
expect(@out.string).to eq <<EOM
a
b
@@ -218,17 +218,17 @@ EOM
end
it "formats single-member arrays appropriately" do
- @ui.output([ 'a' ])
+ @ui.output([ "a" ])
expect(@out.string).to eq("a\n")
end
it "formats nested single-member arrays appropriately" do
- @ui.output([ [ 'a' ] ])
+ @ui.output([ [ "a" ] ])
expect(@out.string).to eq("a\n")
end
it "formats nested arrays appropriately" do
- @ui.output([ [ 'a', 'b' ], [ 'c', 'd' ]])
+ @ui.output([ [ "a", "b" ], [ "c", "d" ]])
expect(@out.string).to eq <<EOM
a
b
@@ -239,7 +239,7 @@ EOM
end
it "formats nested arrays with single- and empty subarrays appropriately" do
- @ui.output([ [ 'a', 'b' ], [ 'c' ], [], [ 'd', 'e' ]])
+ @ui.output([ [ "a", "b" ], [ "c" ], [], [ "d", "e" ]])
expect(@out.string).to eq <<EOM
a
b
@@ -253,7 +253,7 @@ EOM
end
it "formats arrays of hashes with extra lines in between for readability" do
- @ui.output([ { 'a' => 'b', 'c' => 'd' }, { 'x' => 'y' }, { 'm' => 'n', 'o' => 'p' }])
+ @ui.output([ { "a" => "b", "c" => "d" }, { "x" => "y" }, { "m" => "n", "o" => "p" }])
expect(@out.string).to eq <<EOM
a: b
c: d
@@ -266,7 +266,7 @@ EOM
end
it "formats hashes with empty array members appropriately" do
- @ui.output({ 'a' => [], 'b' => 'c' })
+ @ui.output({ "a" => [], "b" => "c" })
expect(@out.string).to eq <<EOM
a:
b: c
@@ -274,7 +274,7 @@ EOM
end
it "formats hashes with single-member array values appropriately" do
- @ui.output({ 'a' => [ 'foo' ], 'b' => 'c' })
+ @ui.output({ "a" => [ "foo" ], "b" => "c" })
expect(@out.string).to eq <<EOM
a: foo
b: c
@@ -282,7 +282,7 @@ EOM
end
it "formats hashes with array members appropriately" do
- @ui.output({ 'a' => [ 'foo', 'bar' ], 'b' => 'c' })
+ @ui.output({ "a" => [ "foo", "bar" ], "b" => "c" })
expect(@out.string).to eq <<EOM
a:
foo
@@ -292,7 +292,7 @@ EOM
end
it "formats hashes with single-member nested array values appropriately" do
- @ui.output({ 'a' => [ [ 'foo' ] ], 'b' => 'c' })
+ @ui.output({ "a" => [ [ "foo" ] ], "b" => "c" })
expect(@out.string).to eq <<EOM
a:
foo
@@ -301,14 +301,14 @@ EOM
end
it "formats hashes with nested array values appropriately" do
- @ui.output({ 'a' => [ [ 'foo', 'bar' ], [ 'baz', 'bjork' ] ], 'b' => 'c' })
+ @ui.output({ "a" => [ [ "foo", "bar" ], [ "baz", "bjork" ] ], "b" => "c" })
# XXX: using a HEREDOC at this point results in a line with required spaces which auto-whitespace removal settings
# on editors will remove and will break this test.
expect(@out.string).to eq("a:\n foo\n bar\n \n baz\n bjork\nb: c\n")
end
it "formats hashes with hash values appropriately" do
- @ui.output({ 'a' => { 'aa' => 'bb', 'cc' => 'dd' }, 'b' => 'c' })
+ @ui.output({ "a" => { "aa" => "bb", "cc" => "dd" }, "b" => "c" })
expect(@out.string).to eq <<EOM
a:
aa: bb
@@ -318,7 +318,7 @@ EOM
end
it "formats hashes with empty hash values appropriately" do
- @ui.output({ 'a' => { }, 'b' => 'c' })
+ @ui.output({ "a" => { }, "b" => "c" })
expect(@out.string).to eq <<EOM
a:
b: c
@@ -432,7 +432,7 @@ EOM
context "when running on Windows" do
before(:each) do
- stdout = double('StringIO', :tty? => true)
+ stdout = double("StringIO", :tty? => true)
allow(@ui).to receive(:stdout).and_return(stdout)
allow(ChefConfig).to receive(:windows?) { true }
Chef::Config.reset
@@ -464,7 +464,7 @@ EOM
let(:output) {stdout.string}
let(:question) { "monkeys rule" }
- let(:answer) { 'y' }
+ let(:answer) { "y" }
let(:default_choice) { nil }
let(:append_instructions) { true }
@@ -583,7 +583,7 @@ EOM
out = StringIO.new
allow(@ui).to receive(:stdout).and_return(out)
allow(@ui).to receive(:stdin).and_return(StringIO.new(" \n"))
- expect(@ui.ask_question("your chef server URL? ", :default => 'http://localhost:4000')).to eq("http://localhost:4000")
+ expect(@ui.ask_question("your chef server URL? ", :default => "http://localhost:4000")).to eq("http://localhost:4000")
expect(out.string).to eq("your chef server URL? [http://localhost:4000] ")
end
end