diff options
author | Serdar Sutay <serdar@opscode.com> | 2014-10-21 09:46:24 -0700 |
---|---|---|
committer | Serdar Sutay <serdar@opscode.com> | 2014-10-21 09:46:24 -0700 |
commit | c038f2bf1a99c162073a9282567b137c7fa91201 (patch) | |
tree | e09a9e0c8bf27c36ffc0c2fbe66b8aab46fa212c /spec/unit/resource_collection | |
parent | b6b5f4a5bea75d391fbe5e06be4cd5230945267e (diff) | |
download | chef-c038f2bf1a99c162073a9282567b137c7fa91201.tar.gz |
Updates based on PR comments.
Diffstat (limited to 'spec/unit/resource_collection')
-rw-r--r-- | spec/unit/resource_collection/resource_list_spec.rb | 95 |
1 files changed, 37 insertions, 58 deletions
diff --git a/spec/unit/resource_collection/resource_list_spec.rb b/spec/unit/resource_collection/resource_list_spec.rb index 8c39fb945a..2df98e3952 100644 --- a/spec/unit/resource_collection/resource_list_spec.rb +++ b/spec/unit/resource_collection/resource_list_spec.rb @@ -23,6 +23,10 @@ describe Chef::ResourceCollection::ResourceList do let(:resource) { Chef::Resource::ZenMaster.new("makoto") } let(:second_resource) { Chef::Resource::ZenMaster.new("hattori") } + def insert_resource(res) + expect{ resource_list.insert(res) }.not_to raise_error + end + describe "initialize" do it "should return a Chef::ResourceList" do expect(resource_list).to be_instance_of(Chef::ResourceCollection::ResourceList) @@ -31,128 +35,103 @@ describe Chef::ResourceCollection::ResourceList do describe "insert" do it "should be able to insert a Chef::Resource" do - lambda { resource_list.insert(resource) }.should_not raise_error - resource_list[0].should be(resource) + insert_resource(resource) + expect(resource_list[0]).to be(resource) end it "should insert things in order" do - lambda { resource_list.insert(resource) }.should_not raise_error - lambda { resource_list.insert(second_resource) }.should_not raise_error - resource_list[0].should be(resource) - resource_list[1].should be(second_resource) + insert_resource(resource) + insert_resource(second_resource) + expect(resource_list[0]).to be(resource) + expect(resource_list[1]).to be(second_resource) end it "should raise error when trying to install something other than Chef::Resource" do - lambda { resource_list.insert("not a resource") }.should raise_error(ArgumentError) + expect{ resource_list.insert("not a resource") }.to raise_error(ArgumentError) end end describe "accessors" do it "should be able to insert with []=" do - lambda { resource_list[0] = resource }.should_not raise_error - lambda { resource_list[1] = second_resource }.should_not raise_error - resource_list[0].should be(resource) - resource_list[1].should be(second_resource) + expect{ resource_list[0] = resource }.not_to raise_error + expect{ resource_list[1] = second_resource }.not_to raise_error + expect(resource_list[0]).to be(resource) + expect(resource_list[1]).to be(second_resource) end it "should be empty by default" do - resource_list.empty?.should be_true + expect(resource_list.empty?).to be_true end describe "when resources are inserted" do before do - lambda { resource_list.insert(resource) }.should_not raise_error - lambda { resource_list.insert(second_resource) }.should_not raise_error + insert_resource(resource) + insert_resource(second_resource) end it "should get resources with all_resources method" do resources = resource_list.all_resources - resources[0].should be(resource) - resources[1].should be(second_resource) + expect(resources[0]).to be(resource) + expect(resources[1]).to be(second_resource) end it "should be able to get resources with each" do current = 0 + expected_resources = [resource, second_resource] - resource_list.each do |r| - case current - when 0 - r.should be(resource) - current += 1 - when 1 - r.should be(second_resource) - else - raise "Unexpected resource" - end + resource_list.execute_each_resource do |r| + expect(r).to be(expected_resources[current]) + current += 1 end - current.should eq(1) + expect(current).to eq(2) end it "should be able to get resources with each_index" do current = 0 resource_list.each_index do |i| - i.should eq(current) + expect(i).to eq(current) current += 1 end - current.should eq(2) + expect(current).to eq(2) end it "should be able to check if the list is empty" do - resource_list.empty?.should be_false + expect(resource_list.empty?).to be_false end end end describe "during execute" do before(:each) do - lambda { resource_list.insert(resource) }.should_not raise_error - lambda { resource_list.insert(second_resource) }.should_not raise_error + insert_resource(resource) + insert_resource(second_resource) end it "should execute resources in order" do current = 0 + expected_resources = [resource, second_resource] resource_list.execute_each_resource do |r| - case current - when 0 - r.should be(resource) - current += 1 - when 1 - r.should be(second_resource) - else - raise "Unexpected resource" - end + expect(r).to be(expected_resources[current]) + current += 1 end - current.should eq(1) + expect(current).to eq(2) end it "should be able to insert resources on the fly" do - current = 0 resource_to_inject = Chef::Resource::ZenMaster.new("there is no spoon") + expected_resources = [resource, resource_to_inject, second_resource] resource_list.execute_each_resource do |r| - case current - when 0 - r.should be(resource) - resource_list.insert(resource_to_inject) - current += 1 - when 1 - r.should be(resource_to_inject) - current += 1 - when 2 - r.should be(second_resource) - current += 1 - else - raise "Unexpected resource" - end + resource_list.insert(resource_to_inject) if r == resource end - resource_list.all_resources.count.should eq(3) + expect(resource_list.all_resources).to eq(expected_resources) end end end |