From 2d7c161f494da621fbef935fea2a61b8cf00a0c6 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sat, 8 Feb 2014 15:11:51 -0800 Subject: [PATCH] core: Ui#dup works properly --- lib/vagrant/ui.rb | 10 ++++++++++ test/unit/vagrant/ui_test.rb | 7 +++++++ 2 files changed, 17 insertions(+) diff --git a/lib/vagrant/ui.rb b/lib/vagrant/ui.rb index e150aa2e7..006928113 100644 --- a/lib/vagrant/ui.rb +++ b/lib/vagrant/ui.rb @@ -26,6 +26,11 @@ module Vagrant @opts = {} end + def initialize_copy(original) + super + @opts = original.opts.dup + end + [:ask, :detail, :warn, :error, :info, :output, :success].each do |method| define_method(method) do |message, *opts| # Log normal console messages @@ -214,6 +219,11 @@ module Vagrant @ui = ui end + def initialize_copy(original) + super + @ui = original.instance_variable_get(:@ui).dup + end + # Use some light meta-programming to create the various methods to # output text to the UI. These all delegate the real functionality # to `say`. diff --git a/test/unit/vagrant/ui_test.rb b/test/unit/vagrant/ui_test.rb index 8e4b98c48..586403c75 100644 --- a/test/unit/vagrant/ui_test.rb +++ b/test/unit/vagrant/ui_test.rb @@ -237,6 +237,13 @@ describe Vagrant::UI::Prefixed do subject { described_class.new(ui, prefix) } + describe "#initialize_copy" do + it "duplicates the underlying ui too" do + another = subject.dup + expect(another.opts).to_not equal(subject.opts) + end + end + describe "#ask" do it "does not request bolding" do ui.should_receive(:ask).with(" #{prefix}: foo", bold: false)