diff --git a/spec/vcloud/requests/login_spec.rb b/spec/vcloud/requests/login_spec.rb index 4bd48754b..cd3b709c7 100644 --- a/spec/vcloud/requests/login_spec.rb +++ b/spec/vcloud/requests/login_spec.rb @@ -8,6 +8,13 @@ end if Fog.mocking? describe Fog::Vcloud, :type => :mock_vcloud_request do it_should_behave_like "real or mock login requests" + + describe "#body" do + subject { @vcloud.login.body } + its(:Org) { should == { :type => "application/vnd.vmware.vcloud.org+xml", + :href => @mock_organization[:info][:href], + :name => @mock_organization[:info][:name]} } + end end else describe Fog::Vcloud, :type => :vcloud_request do diff --git a/spec/vcloud/spec_helper.rb b/spec/vcloud/spec_helper.rb index e45989284..c3912ca80 100644 --- a/spec/vcloud/spec_helper.rb +++ b/spec/vcloud/spec_helper.rb @@ -102,17 +102,27 @@ shared_examples_for "all login requests" do its(:headers) { should include "Set-Cookie" } - it { should have_headers_denoting_a_content_type_of "application/vnd.vmware.vcloud.orgslist+xml" } - describe "#body" do subject { @login.body } - it { should have(4).organizations } - + it { should have(4).items } it_should_behave_like "it has the standard vcloud v0.8 xmlns attributes" # 3 keys - its(:Org) { should == { :type => "application/vnd.vmware.vcloud.org+xml", - :href => @mock_organization[:info][:href], - :name => @mock_organization[:info][:name]} } + it { should include(:Org) } + + describe ":Org" do + subject { arrayify(@login.body[:Org]) } + + specify do + subject.each do |org| + org.should include(:type) + org[:type].should be_of_type "application/vnd.vmware.vcloud.org+xml" + org.should include(:name) + org[:name].should be_an_instance_of String + org.should include(:href) + org[:href].should be_a_url + end + end + end end end end @@ -353,3 +363,21 @@ Spec::Matchers.define :be_either_a_hash_or_array do actual.is_a?(Hash) || actual.is_a?(Array) end end + +Spec::Matchers.define :be_a_known_vmware_type do + match do |actual| + ["application/vnd.vmware.vcloud.org+xml"].include?(actual) + end +end + +Spec::Matchers.define :be_of_type do |type| + match do |actual| + actual == type || + if actual.is_a?(Hash) && actual[:type] + actual[:type] == type + end || + if actual.respond_to(:type) + actual.type == type + end + end +end