Convert builder tests to use rspec "subjects"

This commit is contained in:
Mitchell Hashimoto 2013-02-06 14:25:36 -08:00
parent 80a7c8a0cb
commit e822aac931
1 changed files with 41 additions and 42 deletions

View File

@ -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