summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2013-10-22 21:33:15 -0700
committerLamont Granquist <lamont@scriptkiddie.org>2013-10-23 17:15:10 -0700
commit984a608b67a398ce0748477ba141db5be238b782 (patch)
treece6d7c8eebcf7aeb7d48be83231f6f8993dac3e2
parentf6400922f18e45d175cc7e20b10a3abe58d9e4ea (diff)
downloadchef-984a608b67a398ce0748477ba141db5be238b782.tar.gz
add semi-functional tests
- don't mock Tempfile, and check its file mode
-rw-r--r--spec/unit/knife/core/ui_spec.rb38
1 files changed, 38 insertions, 0 deletions
diff --git a/spec/unit/knife/core/ui_spec.rb b/spec/unit/knife/core/ui_spec.rb
index 180371bb46..1ee84e420b 100644
--- a/spec/unit/knife/core/ui_spec.rb
+++ b/spec/unit/knife/core/ui_spec.rb
@@ -107,6 +107,44 @@ describe Chef::Knife::UI do
end
end
end
+ context "when editing and not stubbing Tempfile (semi-functional test)" do
+ before do
+ @ui.config[:disable_editing] = false
+ @ui.config[:editor] = my_editor
+ @tempfile = Tempfile.new([ 'knife-edit-', '.json' ])
+ Tempfile.should_receive(:open).with([ 'knife-edit-', '.json' ]).and_yield(@tempfile)
+ end
+
+ context "and the editor works" do
+ before do
+ @ui.should_receive(:system).with("#{my_editor} #{@tempfile.path}").and_return(true)
+ IO.should_receive(:read).with(@tempfile.path).and_return(json_from_editor)
+ end
+
+ context "when parse_output is false" do
+ it "returns an edited pretty json string" do
+ expect(subject).to eql(json_from_editor)
+ end
+ it "the tempfile should have mode 0600" do
+ # XXX: this looks odd because we're really testing Tempfile.new here
+ expect(File.stat(@tempfile.path).mode & 0777).to eql(0600)
+ expect(subject).to eql(json_from_editor)
+ end
+ end
+
+ context "when parse_output is true" do
+ let(:parse_output) { true }
+ it "returns an edited ruby object" do
+ expect(subject).to eql(ruby_from_editor)
+ end
+ it "the tempfile should have mode 0600" do
+ # XXX: this looks odd because we're really testing Tempfile.new here
+ expect(File.stat(@tempfile.path).mode & 0777).to eql(0600)
+ expect(subject).to eql(ruby_from_editor)
+ end
+ end
+ end
+ end
end
describe "format_list_for_display" do