diff options
Diffstat (limited to 'spec/unit/resource_collection_spec.rb')
-rw-r--r-- | spec/unit/resource_collection_spec.rb | 104 |
1 files changed, 52 insertions, 52 deletions
diff --git a/spec/unit/resource_collection_spec.rb b/spec/unit/resource_collection_spec.rb index 5966fdd1f2..b43b012dfc 100644 --- a/spec/unit/resource_collection_spec.rb +++ b/spec/unit/resource_collection_spec.rb @@ -29,39 +29,39 @@ describe Chef::ResourceCollection do describe "initialize" do it "should return a Chef::ResourceCollection" do - rc.should be_kind_of(Chef::ResourceCollection) + expect(rc).to be_kind_of(Chef::ResourceCollection) end end describe "[]" do it "should accept Chef::Resources through [index]" do - lambda { rc[0] = resource }.should_not raise_error - lambda { rc[0] = "string" }.should raise_error(ArgumentError) + expect { rc[0] = resource }.not_to raise_error + expect { rc[0] = "string" }.to raise_error(ArgumentError) end it "should allow you to fetch Chef::Resources by position" do rc[0] = resource - rc[0].should eql(resource) + expect(rc[0]).to eql(resource) end end describe "push" do it "should accept Chef::Resources through pushing" do - lambda { rc.push(resource) }.should_not raise_error - lambda { rc.push("string") }.should raise_error(ArgumentError) + expect { rc.push(resource) }.not_to raise_error + expect { rc.push("string") }.to raise_error(ArgumentError) end end describe "<<" do it "should accept the << operator" do - lambda { rc << resource }.should_not raise_error + expect { rc << resource }.not_to raise_error end end describe "insert" do it "should accept only Chef::Resources" do - lambda { rc.insert(resource) }.should_not raise_error - lambda { rc.insert("string") }.should raise_error(ArgumentError) + expect { rc.insert(resource) }.not_to raise_error + expect { rc.insert("string") }.to raise_error(ArgumentError) end it "should accept named arguments in any order" do @@ -73,8 +73,8 @@ describe Chef::ResourceCollection do zmr = Chef::Resource::ZenMaster.new("there is no spoon") rc.insert(resource) rc.insert(zmr) - rc[0].should eql(resource) - rc[1].should eql(zmr) + expect(rc[0]).to eql(resource) + expect(rc[1]).to eql(zmr) end it "should insert resources to the middle of the collection if called while executing a run" do @@ -88,9 +88,9 @@ describe Chef::ResourceCollection do rc.insert(resource_to_inject) if resource == zmr end - rc[0].should eql(zmr) - rc[1].should eql(resource_to_inject) - rc[2].should eql(dummy) + expect(rc[0]).to eql(zmr) + expect(rc[1]).to eql(resource_to_inject) + expect(rc[2]).to eql(dummy) end end @@ -98,19 +98,19 @@ describe Chef::ResourceCollection do it "should allow you to iterate over every resource in the collection" do load_up_resources results = Array.new - lambda { + expect { rc.each do |r| results << r.name end - }.should_not raise_error + }.not_to raise_error results.each_index do |i| case i when 0 - results[i].should eql("dog") + expect(results[i]).to eql("dog") when 1 - results[i].should eql("cat") + expect(results[i]).to eql("cat") when 2 - results[i].should eql("monkey") + expect(results[i]).to eql("monkey") end end end @@ -120,19 +120,19 @@ describe Chef::ResourceCollection do it "should allow you to iterate over every resource by index" do load_up_resources results = Array.new - lambda { + expect { rc.each_index do |i| results << rc[i].name end - }.should_not raise_error + }.not_to raise_error results.each_index do |i| case i when 0 - results[i].should eql("dog") + expect(results[i]).to eql("dog") when 1 - results[i].should eql("cat") + expect(results[i]).to eql("cat") when 2 - results[i].should eql("monkey") + expect(results[i]).to eql("monkey") end end end @@ -142,23 +142,23 @@ describe Chef::ResourceCollection do it "should allow you to find resources by name via lookup" do zmr = Chef::Resource::ZenMaster.new("dog") rc << zmr - rc.lookup(zmr.to_s).should eql(zmr) + expect(rc.lookup(zmr.to_s)).to eql(zmr) zmr = Chef::Resource::ZenMaster.new("cat") rc[0] = zmr - rc.lookup(zmr).should eql(zmr) + expect(rc.lookup(zmr)).to eql(zmr) zmr = Chef::Resource::ZenMaster.new("monkey") rc.push(zmr) - rc.lookup(zmr).should eql(zmr) + expect(rc.lookup(zmr)).to eql(zmr) end it "should raise an exception if you send something strange to lookup" do - lambda { rc.lookup(:symbol) }.should raise_error(ArgumentError) + expect { rc.lookup(:symbol) }.to raise_error(ArgumentError) end it "should raise an exception if it cannot find a resource with lookup" do - lambda { rc.lookup("zen_master[dog]") }.should raise_error(Chef::Exceptions::ResourceNotFound) + expect { rc.lookup("zen_master[dog]") }.to raise_error(Chef::Exceptions::ResourceNotFound) end end @@ -166,81 +166,81 @@ describe Chef::ResourceCollection do it "should find a resource by symbol and name (:zen_master => monkey)" do load_up_resources - rc.resources(:zen_master => "monkey").name.should eql("monkey") + expect(rc.resources(:zen_master => "monkey").name).to eql("monkey") end it "should find a resource by symbol and array of names (:zen_master => [a,b])" do load_up_resources results = rc.resources(:zen_master => [ "monkey", "dog" ]) - results.length.should eql(2) + expect(results.length).to eql(2) check_by_names(results, "monkey", "dog") end it "should find resources of multiple kinds (:zen_master => a, :file => b)" do load_up_resources results = rc.resources(:zen_master => "monkey", :file => "something") - results.length.should eql(2) + expect(results.length).to eql(2) check_by_names(results, "monkey", "something") end it "should find a resource by string zen_master[a]" do load_up_resources - rc.resources("zen_master[monkey]").name.should eql("monkey") + expect(rc.resources("zen_master[monkey]").name).to eql("monkey") end it "should find resources by strings of zen_master[a,b]" do load_up_resources results = rc.resources("zen_master[monkey,dog]") - results.length.should eql(2) + expect(results.length).to eql(2) check_by_names(results, "monkey", "dog") end it "should find resources of multiple types by strings of zen_master[a]" do load_up_resources results = rc.resources("zen_master[monkey]", "file[something]") - results.length.should eql(2) + expect(results.length).to eql(2) check_by_names(results, "monkey", "something") end it "should raise an exception if you pass a bad name to resources" do - lambda { rc.resources("michael jackson") }.should raise_error(ArgumentError) + expect { rc.resources("michael jackson") }.to raise_error(ArgumentError) end it "should raise an exception if you pass something other than a string or hash to resource" do - lambda { rc.resources([Array.new]) }.should raise_error(ArgumentError) + expect { rc.resources([Array.new]) }.to raise_error(ArgumentError) end it "raises an error when attempting to find a resource that does not exist" do - lambda {rc.find("script[nonesuch]")}.should raise_error(Chef::Exceptions::ResourceNotFound) + expect {rc.find("script[nonesuch]")}.to raise_error(Chef::Exceptions::ResourceNotFound) end end describe "when validating a resource query object" do it "accepts a string of the form 'resource_type[resource_name]'" do - rc.validate_lookup_spec!("resource_type[resource_name]").should be_true + expect(rc.validate_lookup_spec!("resource_type[resource_name]")).to be_truthy end it "accepts a single-element :resource_type => 'resource_name' Hash" do - rc.validate_lookup_spec!(:service => "apache2").should be_true + expect(rc.validate_lookup_spec!(:service => "apache2")).to be_truthy end it "accepts a chef resource object" do res = Chef::Resource.new("foo", nil) - rc.validate_lookup_spec!(res).should be_true + expect(rc.validate_lookup_spec!(res)).to be_truthy end it "rejects a malformed query string" do - lambda do + expect do rc.validate_lookup_spec!("resource_type[missing-end-bracket") - end.should raise_error(Chef::Exceptions::InvalidResourceSpecification) + end.to raise_error(Chef::Exceptions::InvalidResourceSpecification) end it "rejects an argument that is not a String, Hash, or Chef::Resource" do - lambda do + expect do rc.validate_lookup_spec!(Object.new) - end.should raise_error(Chef::Exceptions::InvalidResourceSpecification) + end.to raise_error(Chef::Exceptions::InvalidResourceSpecification) end end @@ -248,8 +248,8 @@ describe Chef::ResourceCollection do describe "to_json" do it "should serialize to json" do json = rc.to_json - json.should =~ /json_class/ - json.should =~ /instance_vars/ + expect(json).to match(/json_class/) + expect(json).to match(/instance_vars/) end include_examples "to_json equalivent to Chef::JSONCompat.to_json" do @@ -266,27 +266,27 @@ describe Chef::ResourceCollection do rc << resource json = Chef::JSONCompat.to_json(rc) s_rc = Chef::JSONCompat.from_json(json) - s_rc.should be_a_kind_of(Chef::ResourceCollection) - s_rc[0].name.should eql(resource.name) + expect(s_rc).to be_a_kind_of(Chef::ResourceCollection) + expect(s_rc[0].name).to eql(resource.name) end end describe "provides access to the raw resources array" do it "returns the resources via the all_resources method" do - rc.all_resources.should equal(rc.instance_variable_get(:@resource_list).instance_variable_get(:@resources)) + expect(rc.all_resources).to equal(rc.instance_variable_get(:@resource_list).instance_variable_get(:@resources)) end end describe "provides access to stepable iterator" do it "returns the iterator object" do rc.instance_variable_get(:@resource_list).instance_variable_set(:@iterator, :fooboar) - rc.iterator.should == :fooboar + expect(rc.iterator).to eq(:fooboar) end end def check_by_names(results, *names) names.each do |res_name| - results.detect{ |res| res.name == res_name }.should_not eql(nil) + expect(results.detect{ |res| res.name == res_name }).not_to eql(nil) end end |