From e822aac931e82606948b147e5d8aba8e11a66a71 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 6 Feb 2013 14:25:36 -0800 Subject: [PATCH] Convert builder tests to use rspec "subjects" --- test/unit/vagrant/action/builder_test.rb | 83 ++++++++++++------------ 1 file changed, 41 insertions(+), 42 deletions(-) diff --git a/test/unit/vagrant/action/builder_test.rb b/test/unit/vagrant/action/builder_test.rb index ee00e0818..b3d65410b 100644 --- a/test/unit/vagrant/action/builder_test.rb +++ b/test/unit/vagrant/action/builder_test.rb @@ -2,7 +2,6 @@ require File.expand_path("../../../base", __FILE__) describe Vagrant::Action::Builder do let(:data) { { :data => [] } } - let(:instance) { described_class.new } # This returns a proc that can be used with the builder # that simply appends data to an array in the env. @@ -15,8 +14,8 @@ describe Vagrant::Action::Builder do data = {} proc = Proc.new { |env| env[:data] = true } - instance = described_class.build(proc) - instance.call(data) + subject = described_class.build(proc) + subject.call(data) data[:data].should == true end @@ -27,8 +26,8 @@ describe Vagrant::Action::Builder do data = {} proc = Proc.new { |env| env[:data] = true } - instance.use proc - instance.call(data) + subject.use proc + subject.call(data) data[:data].should == true end @@ -38,9 +37,9 @@ describe Vagrant::Action::Builder do proc1 = Proc.new { |env| env[:one] = true } proc2 = Proc.new { |env| env[:two] = true } - instance.use proc1 - instance.use proc2 - instance.call(data) + subject.use proc1 + subject.use proc2 + subject.call(data) data[:one].should == true data[:two].should == true @@ -66,9 +65,9 @@ describe Vagrant::Action::Builder do context "inserting" do it "can insert at an index" do - instance.use appender_proc(1) - instance.insert(0, appender_proc(2)) - instance.call(data) + subject.use appender_proc(1) + subject.insert(0, appender_proc(2)) + subject.call(data) data[:data].should == [2, 1] end @@ -78,48 +77,48 @@ describe Vagrant::Action::Builder do bar_proc = appender_proc(2) def bar_proc.name; :bar; end - instance.use appender_proc(1) - instance.use bar_proc - instance.insert_before :bar, appender_proc(3) - instance.call(data) + subject.use appender_proc(1) + subject.use bar_proc + subject.insert_before :bar, appender_proc(3) + subject.call(data) data[:data].should == [1, 3, 2] end it "can insert next to a previous object" do proc2 = appender_proc(2) - instance.use appender_proc(1) - instance.use proc2 - instance.insert(proc2, appender_proc(3)) - instance.call(data) + subject.use appender_proc(1) + subject.use proc2 + subject.insert(proc2, appender_proc(3)) + subject.call(data) data[:data].should == [1, 3, 2] end it "can insert before" do - instance.use appender_proc(1) - instance.insert_before 0, appender_proc(2) - instance.call(data) + subject.use appender_proc(1) + subject.insert_before 0, appender_proc(2) + subject.call(data) data[:data].should == [2, 1] end it "can insert after" do - instance.use appender_proc(1) - instance.use appender_proc(3) - instance.insert_after 0, appender_proc(2) - instance.call(data) + subject.use appender_proc(1) + subject.use appender_proc(3) + subject.insert_after 0, appender_proc(2) + subject.call(data) data[:data].should == [1, 2, 3] end it "raises an exception if an invalid object given for insert" do - expect { instance.insert "object", appender_proc(1) }. + expect { subject.insert "object", appender_proc(1) }. to raise_error(RuntimeError) end it "raises an exception if an invalid object given for insert_after" do - expect { instance.insert_after "object", appender_proc(1) }. + expect { subject.insert_after "object", appender_proc(1) }. to raise_error(RuntimeError) end end @@ -129,9 +128,9 @@ describe Vagrant::Action::Builder do proc1 = appender_proc(1) proc2 = appender_proc(2) - instance.use proc1 - instance.replace proc1, proc2 - instance.call(data) + subject.use proc1 + subject.replace proc1, proc2 + subject.call(data) data[:data].should == [2] end @@ -140,9 +139,9 @@ describe Vagrant::Action::Builder do proc1 = appender_proc(1) proc2 = appender_proc(2) - instance.use proc1 - instance.replace 0, proc2 - instance.call(data) + subject.use proc1 + subject.replace 0, proc2 + subject.call(data) data[:data].should == [2] end @@ -152,10 +151,10 @@ describe Vagrant::Action::Builder do it "can delete by object" do proc1 = appender_proc(1) - instance.use proc1 - instance.use appender_proc(2) - instance.delete proc1 - instance.call(data) + subject.use proc1 + subject.use appender_proc(2) + subject.delete proc1 + subject.call(data) data[:data].should == [2] end @@ -163,10 +162,10 @@ describe Vagrant::Action::Builder do it "can delete by index" do proc1 = appender_proc(1) - instance.use proc1 - instance.use appender_proc(2) - instance.delete 0 - instance.call(data) + subject.use proc1 + subject.use appender_proc(2) + subject.delete 0 + subject.call(data) data[:data].should == [2] end