core: add more tests for MachineReadable UI

This commit is contained in:
Mitchell Hashimoto 2014-01-21 12:11:53 -08:00
parent f2f58655e8
commit 06f1ebf752
2 changed files with 61 additions and 2 deletions

View File

@ -80,8 +80,7 @@ module Vagrant
# Prepare the data by replacing characters that aren't outputted
data.each_index do |i|
data[i] = data[i].to_s
data[i] = data[i].dup if data[i].frozen?
data[i] = data[i].to_s.dup
data[i].gsub!(",", "%!(VAGRANT_COMMA)")
data[i].gsub!("\n", "\\n")
data[i].gsub!("\r", "\\r")

View File

@ -142,6 +142,66 @@ describe Vagrant::UI::Colored do
end
end
describe Vagrant::UI::MachineReadable do
describe "#ask" do
it "raises an exception" do
expect { subject.ask("foo") }.
to raise_error(Vagrant::Errors::UIExpectsTTY)
end
end
describe "#machine" do
it "is formatted properly" do
subject.should_receive(:safe_puts).with do |message|
parts = message.split(",")
expect(parts.length).to eq(5)
expect(parts[1]).to eq("")
expect(parts[2]).to eq("type")
expect(parts[3]).to eq("data")
expect(parts[4]).to eq("another")
true
end
subject.machine(:type, "data", "another")
end
it "includes a target if given" do
subject.should_receive(:safe_puts).with do |message|
parts = message.split(",")
expect(parts.length).to eq(4)
expect(parts[1]).to eq("boom")
expect(parts[2]).to eq("type")
expect(parts[3]).to eq("data")
true
end
subject.machine(:type, "data", target: "boom")
end
it "replaces commas" do
subject.should_receive(:safe_puts).with do |message|
parts = message.split(",")
expect(parts.length).to eq(4)
expect(parts[3]).to eq("foo%!(VAGRANT_COMMA)bar")
true
end
subject.machine(:type, "foo,bar")
end
it "replaces newlines" do
subject.should_receive(:safe_puts).with do |message|
parts = message.split(",")
expect(parts.length).to eq(4)
expect(parts[3]).to eq("foo\\nbar\\r")
true
end
subject.machine(:type, "foo\nbar\r")
end
end
end
describe Vagrant::UI::Prefixed do
let(:prefix) { "foo" }
let(:ui) { Vagrant::UI::Basic.new }