Shell UI tests. Added option to not translate. Updated non-translated strings.
This commit is contained in:
parent
ce080e908f
commit
7ddff513f0
|
@ -7,7 +7,8 @@ env = Vagrant::Environment.load!
|
||||||
begin
|
begin
|
||||||
Vagrant::CLI.start(ARGV, :env => env)
|
Vagrant::CLI.start(ARGV, :env => env)
|
||||||
rescue Vagrant::Errors::VagrantError => e
|
rescue Vagrant::Errors::VagrantError => e
|
||||||
env.ui.error e.message, false
|
opts = { :_translate => false, :_prefix => false }
|
||||||
env.ui.error e.backtrace.join("\n"), false if ENV["VAGRANT_DEBUG"]
|
env.ui.error e.message, opts
|
||||||
|
env.ui.error e.backtrace.join("\n"), opts if ENV["VAGRANT_DEBUG"]
|
||||||
exit e.status_code
|
exit e.status_code
|
||||||
end
|
end
|
||||||
|
|
|
@ -25,8 +25,8 @@ module Vagrant
|
||||||
desc "list", "Lists all installed boxes"
|
desc "list", "Lists all installed boxes"
|
||||||
def list
|
def list
|
||||||
boxes = Box.all(env).sort
|
boxes = Box.all(env).sort
|
||||||
return env.ui.warn("vagrant.commands.box.no_installed_boxes", :_prefix => false)# if boxes.empty?
|
return env.ui.warn("vagrant.commands.box.no_installed_boxes", :_prefix => false) if boxes.empty?
|
||||||
boxes.each { |b| env.ui.info(b) }
|
boxes.each { |b| env.ui.info(b, :_translate => false, :_prefix => false) }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -19,7 +19,7 @@ module Vagrant
|
||||||
ssh_vm.ssh.execute do |ssh|
|
ssh_vm.ssh.execute do |ssh|
|
||||||
ssh_vm.env.ui.info "vagrant.commands.ssh.execute", :command => options[:execute]
|
ssh_vm.env.ui.info "vagrant.commands.ssh.execute", :command => options[:execute]
|
||||||
ssh.exec!(options[:execute]) do |channel, type, data|
|
ssh.exec!(options[:execute]) do |channel, type, data|
|
||||||
ssh_vm.env.ui.info "#{data}"
|
ssh_vm.env.ui.info "#{data}", :_translate => false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -10,12 +10,12 @@ module Vagrant
|
||||||
vm = target_vms.first
|
vm = target_vms.first
|
||||||
raise VMNotCreatedError.new if !vm.created?
|
raise VMNotCreatedError.new if !vm.created?
|
||||||
|
|
||||||
env.ui.info Util::TemplateRenderer.render("ssh_config", {
|
env.ui.info(Util::TemplateRenderer.render("ssh_config", {
|
||||||
:host_key => options[:host] || "vagrant",
|
:host_key => options[:host] || "vagrant",
|
||||||
:ssh_user => vm.env.config.ssh.username,
|
:ssh_user => vm.env.config.ssh.username,
|
||||||
:ssh_port => vm.ssh.port,
|
:ssh_port => vm.ssh.port,
|
||||||
:private_key_path => vm.env.config.ssh.private_key_path
|
:private_key_path => vm.env.config.ssh.private_key_path
|
||||||
})
|
}), :_translate => false, :_prefix => false)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -58,7 +58,7 @@ module Vagrant
|
||||||
if type == :exit_status
|
if type == :exit_status
|
||||||
ssh.check_exit_status(data, command)
|
ssh.check_exit_status(data, command)
|
||||||
else
|
else
|
||||||
env.ui.info("#{data}: #{type}")
|
env.ui.info("#{data}: #{type}", :_translate => false)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -44,7 +44,7 @@ module Vagrant
|
||||||
vm.ssh.execute do |ssh|
|
vm.ssh.execute do |ssh|
|
||||||
ssh.exec!(command) do |channel, type, data|
|
ssh.exec!(command) do |channel, type, data|
|
||||||
ssh.check_exit_status(data, command) if type == :exit_status
|
ssh.check_exit_status(data, command) if type == :exit_status
|
||||||
env.ui.info("#{data}: #{type}") if type != :exit_status
|
env.ui.info("#{data}: #{type}", :_translate => false) if type != :exit_status
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -26,9 +26,9 @@ module Vagrant
|
||||||
end
|
end
|
||||||
|
|
||||||
[[:warn, :yellow], [:error, :red], [:info, nil], [:confirm, :green]].each do |method, color|
|
[[:warn, :yellow], [:error, :red], [:info, nil], [:confirm, :green]].each do |method, color|
|
||||||
define_method(method) do |key, opts=nil|
|
define_method(method) do |message, opts=nil|
|
||||||
opts = { :_prefix => true }.merge(opts || {})
|
opts = { :_prefix => true, :_translate => true }.merge(opts || {})
|
||||||
message = I18n.t(key, opts)
|
message = I18n.t(message, opts) if opts[:_translate]
|
||||||
message = format_message(message) if opts[:_prefix]
|
message = format_message(message) if opts[:_prefix]
|
||||||
@shell.say("#{line_reset}#{message}", color)
|
@shell.say("#{line_reset}#{message}", color)
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1,49 @@
|
||||||
|
require "test_helper"
|
||||||
|
|
||||||
|
class ShellUITest < Test::Unit::TestCase
|
||||||
|
setup do
|
||||||
|
@klass = Vagrant::UI::Shell
|
||||||
|
@shell = mock("shell")
|
||||||
|
@instance = @klass.new(mock_environment, @shell)
|
||||||
|
end
|
||||||
|
|
||||||
|
context "prefixing with resource" do
|
||||||
|
should "prefix message with environment resource" do
|
||||||
|
@shell.expects(:say).with() do |message, color|
|
||||||
|
assert message =~ /\[#{@instance.env.resource}\]/
|
||||||
|
true
|
||||||
|
end
|
||||||
|
|
||||||
|
@instance.info("vagrant.errors.test_key")
|
||||||
|
end
|
||||||
|
|
||||||
|
should "not prefix the message if given false" do
|
||||||
|
@shell.expects(:say).with() do |message, color|
|
||||||
|
assert message !~ /\[#{@instance.env.resource}\]/
|
||||||
|
true
|
||||||
|
end
|
||||||
|
|
||||||
|
@instance.info("vagrant.errors.test_key", :_prefix => false)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "translating" do
|
||||||
|
should "translate the message by default" do
|
||||||
|
@shell.expects(:say).with() do |message, color|
|
||||||
|
assert message.include?(I18n.t("vagrant.errors.test_key"))
|
||||||
|
true
|
||||||
|
end
|
||||||
|
|
||||||
|
@instance.info("vagrant.errors.test_key")
|
||||||
|
end
|
||||||
|
|
||||||
|
should "not translate the message if noted" do
|
||||||
|
@shell.expects(:say).with() do |message, color|
|
||||||
|
assert message.include?("vagrant.errors.test_key")
|
||||||
|
true
|
||||||
|
end
|
||||||
|
|
||||||
|
@instance.info("vagrant.errors.test_key", :_translate => false)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue