diff options
author | Lamont Granquist <lamont@scriptkiddie.org> | 2013-10-23 15:05:54 -0700 |
---|---|---|
committer | Lamont Granquist <lamont@scriptkiddie.org> | 2013-10-23 17:15:11 -0700 |
commit | cc2720bbe3bec1f86f564466e093539f80b2887f (patch) | |
tree | 3bad5a10c0935a79bbe519434366391ef77406a6 /spec/unit/knife/node_edit_spec.rb | |
parent | 48bcedb011bbd1d033c43e54c601adf0ab2d26c0 (diff) | |
download | chef-cc2720bbe3bec1f86f564466e093539f80b2887f.tar.gz |
port node_editor to use ui.edit_data()
- easier to change the code and reduce the code dupliation than to
write the specs for this object.
Diffstat (limited to 'spec/unit/knife/node_edit_spec.rb')
-rw-r--r-- | spec/unit/knife/node_edit_spec.rb | 39 |
1 files changed, 33 insertions, 6 deletions
diff --git a/spec/unit/knife/node_edit_spec.rb b/spec/unit/knife/node_edit_spec.rb index e8f6937a31..7fbd8192d1 100644 --- a/spec/unit/knife/node_edit_spec.rb +++ b/spec/unit/knife/node_edit_spec.rb @@ -20,6 +20,12 @@ require 'spec_helper' Chef::Knife::NodeEdit.load_deps describe Chef::Knife::NodeEdit do + + # helper to convert the view from Chef objects into Ruby objects representing JSON + def deserialized_json_view + actual = Chef::JSONCompat.from_json(Chef::JSONCompat.to_json_pretty(@knife.node_editor.send(:view))) + end + before(:each) do Chef::Config[:node_name] = "webmonkey.example.com" @knife = Chef::Knife::NodeEdit.new @@ -49,7 +55,7 @@ describe Chef::Knife::NodeEdit do end it "creates a view of the node without attributes from roles or ohai" do - actual = Chef::JSONCompat.from_json(@knife.node_editor.view) + actual = deserialized_json_view actual.should_not have_key("automatic") actual.should_not have_key("override") actual.should_not have_key("default") @@ -61,7 +67,7 @@ describe Chef::Knife::NodeEdit do it "shows the extra attributes when given the --all option" do @knife.config[:all_attributes] = true - actual = Chef::JSONCompat.from_json(@knife.node_editor.view) + actual = deserialized_json_view actual["automatic"].should == {"go" => "away"} actual["override"].should == {"dont" => "show"} actual["default"].should == {"hide" => "me"} @@ -71,18 +77,39 @@ describe Chef::Knife::NodeEdit do end it "does not consider unedited data updated" do - view = Chef::JSONCompat.from_json( @knife.node_editor.view ) - @knife.node_editor.apply_updates(view) + view = deserialized_json_view + @knife.node_editor.send(:apply_updates, view) @knife.node_editor.should_not be_updated end it "considers edited data updated" do - view = Chef::JSONCompat.from_json( @knife.node_editor.view ) + view = deserialized_json_view view["run_list"] << "role[fuuu]" - @knife.node_editor.apply_updates(view) + @knife.node_editor.send(:apply_updates, view) @knife.node_editor.should be_updated end end + + describe "edit_node" do + + before do + @knife.stub!(:node).and_return(@node) + end + + let(:subject) { @knife.node_editor.edit_node } + + it "raises an exception when editing is disabled" do + @knife.config[:disable_editing] = true + expect{ subject }.to raise_error(SystemExit) + end + + it "raises an exception when the editor is not set" do + @knife.config[:editor] = nil + expect{ subject }.to raise_error(SystemExit) + end + + end + end |