Convert builder tests to use rspec "subjects"
This commit is contained in:
parent
80a7c8a0cb
commit
e822aac931
|
@ -2,7 +2,6 @@ require File.expand_path("../../../base", __FILE__)
|
||||||
|
|
||||||
describe Vagrant::Action::Builder do
|
describe Vagrant::Action::Builder do
|
||||||
let(:data) { { :data => [] } }
|
let(:data) { { :data => [] } }
|
||||||
let(:instance) { described_class.new }
|
|
||||||
|
|
||||||
# This returns a proc that can be used with the builder
|
# This returns a proc that can be used with the builder
|
||||||
# that simply appends data to an array in the env.
|
# that simply appends data to an array in the env.
|
||||||
|
@ -15,8 +14,8 @@ describe Vagrant::Action::Builder do
|
||||||
data = {}
|
data = {}
|
||||||
proc = Proc.new { |env| env[:data] = true }
|
proc = Proc.new { |env| env[:data] = true }
|
||||||
|
|
||||||
instance = described_class.build(proc)
|
subject = described_class.build(proc)
|
||||||
instance.call(data)
|
subject.call(data)
|
||||||
|
|
||||||
data[:data].should == true
|
data[:data].should == true
|
||||||
end
|
end
|
||||||
|
@ -27,8 +26,8 @@ describe Vagrant::Action::Builder do
|
||||||
data = {}
|
data = {}
|
||||||
proc = Proc.new { |env| env[:data] = true }
|
proc = Proc.new { |env| env[:data] = true }
|
||||||
|
|
||||||
instance.use proc
|
subject.use proc
|
||||||
instance.call(data)
|
subject.call(data)
|
||||||
|
|
||||||
data[:data].should == true
|
data[:data].should == true
|
||||||
end
|
end
|
||||||
|
@ -38,9 +37,9 @@ describe Vagrant::Action::Builder do
|
||||||
proc1 = Proc.new { |env| env[:one] = true }
|
proc1 = Proc.new { |env| env[:one] = true }
|
||||||
proc2 = Proc.new { |env| env[:two] = true }
|
proc2 = Proc.new { |env| env[:two] = true }
|
||||||
|
|
||||||
instance.use proc1
|
subject.use proc1
|
||||||
instance.use proc2
|
subject.use proc2
|
||||||
instance.call(data)
|
subject.call(data)
|
||||||
|
|
||||||
data[:one].should == true
|
data[:one].should == true
|
||||||
data[:two].should == true
|
data[:two].should == true
|
||||||
|
@ -66,9 +65,9 @@ describe Vagrant::Action::Builder do
|
||||||
|
|
||||||
context "inserting" do
|
context "inserting" do
|
||||||
it "can insert at an index" do
|
it "can insert at an index" do
|
||||||
instance.use appender_proc(1)
|
subject.use appender_proc(1)
|
||||||
instance.insert(0, appender_proc(2))
|
subject.insert(0, appender_proc(2))
|
||||||
instance.call(data)
|
subject.call(data)
|
||||||
|
|
||||||
data[:data].should == [2, 1]
|
data[:data].should == [2, 1]
|
||||||
end
|
end
|
||||||
|
@ -78,48 +77,48 @@ describe Vagrant::Action::Builder do
|
||||||
bar_proc = appender_proc(2)
|
bar_proc = appender_proc(2)
|
||||||
def bar_proc.name; :bar; end
|
def bar_proc.name; :bar; end
|
||||||
|
|
||||||
instance.use appender_proc(1)
|
subject.use appender_proc(1)
|
||||||
instance.use bar_proc
|
subject.use bar_proc
|
||||||
instance.insert_before :bar, appender_proc(3)
|
subject.insert_before :bar, appender_proc(3)
|
||||||
instance.call(data)
|
subject.call(data)
|
||||||
|
|
||||||
data[:data].should == [1, 3, 2]
|
data[:data].should == [1, 3, 2]
|
||||||
end
|
end
|
||||||
|
|
||||||
it "can insert next to a previous object" do
|
it "can insert next to a previous object" do
|
||||||
proc2 = appender_proc(2)
|
proc2 = appender_proc(2)
|
||||||
instance.use appender_proc(1)
|
subject.use appender_proc(1)
|
||||||
instance.use proc2
|
subject.use proc2
|
||||||
instance.insert(proc2, appender_proc(3))
|
subject.insert(proc2, appender_proc(3))
|
||||||
instance.call(data)
|
subject.call(data)
|
||||||
|
|
||||||
data[:data].should == [1, 3, 2]
|
data[:data].should == [1, 3, 2]
|
||||||
end
|
end
|
||||||
|
|
||||||
it "can insert before" do
|
it "can insert before" do
|
||||||
instance.use appender_proc(1)
|
subject.use appender_proc(1)
|
||||||
instance.insert_before 0, appender_proc(2)
|
subject.insert_before 0, appender_proc(2)
|
||||||
instance.call(data)
|
subject.call(data)
|
||||||
|
|
||||||
data[:data].should == [2, 1]
|
data[:data].should == [2, 1]
|
||||||
end
|
end
|
||||||
|
|
||||||
it "can insert after" do
|
it "can insert after" do
|
||||||
instance.use appender_proc(1)
|
subject.use appender_proc(1)
|
||||||
instance.use appender_proc(3)
|
subject.use appender_proc(3)
|
||||||
instance.insert_after 0, appender_proc(2)
|
subject.insert_after 0, appender_proc(2)
|
||||||
instance.call(data)
|
subject.call(data)
|
||||||
|
|
||||||
data[:data].should == [1, 2, 3]
|
data[:data].should == [1, 2, 3]
|
||||||
end
|
end
|
||||||
|
|
||||||
it "raises an exception if an invalid object given for insert" do
|
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)
|
to raise_error(RuntimeError)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "raises an exception if an invalid object given for insert_after" do
|
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)
|
to raise_error(RuntimeError)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -129,9 +128,9 @@ describe Vagrant::Action::Builder do
|
||||||
proc1 = appender_proc(1)
|
proc1 = appender_proc(1)
|
||||||
proc2 = appender_proc(2)
|
proc2 = appender_proc(2)
|
||||||
|
|
||||||
instance.use proc1
|
subject.use proc1
|
||||||
instance.replace proc1, proc2
|
subject.replace proc1, proc2
|
||||||
instance.call(data)
|
subject.call(data)
|
||||||
|
|
||||||
data[:data].should == [2]
|
data[:data].should == [2]
|
||||||
end
|
end
|
||||||
|
@ -140,9 +139,9 @@ describe Vagrant::Action::Builder do
|
||||||
proc1 = appender_proc(1)
|
proc1 = appender_proc(1)
|
||||||
proc2 = appender_proc(2)
|
proc2 = appender_proc(2)
|
||||||
|
|
||||||
instance.use proc1
|
subject.use proc1
|
||||||
instance.replace 0, proc2
|
subject.replace 0, proc2
|
||||||
instance.call(data)
|
subject.call(data)
|
||||||
|
|
||||||
data[:data].should == [2]
|
data[:data].should == [2]
|
||||||
end
|
end
|
||||||
|
@ -152,10 +151,10 @@ describe Vagrant::Action::Builder do
|
||||||
it "can delete by object" do
|
it "can delete by object" do
|
||||||
proc1 = appender_proc(1)
|
proc1 = appender_proc(1)
|
||||||
|
|
||||||
instance.use proc1
|
subject.use proc1
|
||||||
instance.use appender_proc(2)
|
subject.use appender_proc(2)
|
||||||
instance.delete proc1
|
subject.delete proc1
|
||||||
instance.call(data)
|
subject.call(data)
|
||||||
|
|
||||||
data[:data].should == [2]
|
data[:data].should == [2]
|
||||||
end
|
end
|
||||||
|
@ -163,10 +162,10 @@ describe Vagrant::Action::Builder do
|
||||||
it "can delete by index" do
|
it "can delete by index" do
|
||||||
proc1 = appender_proc(1)
|
proc1 = appender_proc(1)
|
||||||
|
|
||||||
instance.use proc1
|
subject.use proc1
|
||||||
instance.use appender_proc(2)
|
subject.use appender_proc(2)
|
||||||
instance.delete 0
|
subject.delete 0
|
||||||
instance.call(data)
|
subject.call(data)
|
||||||
|
|
||||||
data[:data].should == [2]
|
data[:data].should == [2]
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue