You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@deltacloud.apache.org by mf...@redhat.com on 2011/11/23 17:23:21 UTC

[PATCH core 1/5] CIMI: Added 'should_properly_serialize_model' helper to RSpec tests

From: Michal Fojtik <mf...@redhat.com>


Signed-off-by: Michal fojtik <mf...@redhat.com>
---
 server/spec/cimi/model/machine_admin_spec.rb       |   14 ++------------
 .../spec/cimi/model/machine_configuration_spec.rb  |   12 ++----------
 server/spec/cimi/model/machine_image_spec.rb       |   11 ++---------
 server/spec/cimi/model/machine_spec.rb             |   17 ++---------------
 server/spec/cimi/model/machine_template_spec.rb    |   12 ++----------
 server/spec/cimi/model/volume_spec.rb              |   12 ++----------
 server/spec/spec_helper.rb                         |   15 +++++++--------
 7 files changed, 19 insertions(+), 74 deletions(-)

diff --git a/server/spec/cimi/model/machine_admin_spec.rb b/server/spec/cimi/model/machine_admin_spec.rb
index e9cabc4..036a66d 100644
--- a/server/spec/cimi/model/machine_admin_spec.rb
+++ b/server/spec/cimi/model/machine_admin_spec.rb
@@ -21,18 +21,8 @@ describe "MachineAdmin model" do
     @json = IO::read(File::join(DATA_DIR, "machine_admin.json"))
   end
 
-  it "can be constructed from XML" do
-    conf = CIMI::Model::MachineAdmin.from_xml(@xml)
-    conf.should_not be_nil
-    should_serialize_from_xml! conf, @xml, @json
+  it "can be constructed from XML and JSON" do
+    should_properly_serialize_model CIMI::Model::MachineAdmin, @xml, @json
   end
 
-  it "can be constructed from JSON" do
-    conf = CIMI::Model::MachineAdmin.from_json(@json)
-    conf.should_not be_nil
-    should_serialize_from_json! conf, @xml, @json
-  end
-
-
-
 end
diff --git a/server/spec/cimi/model/machine_configuration_spec.rb b/server/spec/cimi/model/machine_configuration_spec.rb
index 454e8c4..2a57269 100644
--- a/server/spec/cimi/model/machine_configuration_spec.rb
+++ b/server/spec/cimi/model/machine_configuration_spec.rb
@@ -20,16 +20,8 @@ describe "MachineConfiguration model" do
     @json = IO::read(File::join(DATA_DIR, "machine_configuration.json"))
   end
 
-  it "can be constructed from XML" do
-    conf = CIMI::Model::MachineConfiguration.from_xml(@xml)
-    conf.should_not be_nil
-    should_serialize_from_xml! conf, @xml, @json
-  end
-
-  it "can be constructed from JSON" do
-    conf = CIMI::Model::MachineConfiguration.from_json(@json)
-    conf.should_not be_nil
-    should_serialize_from_json! conf, @xml, @json
+  it "can be constructed from XML and JSON" do
+    should_properly_serialize_model CIMI::Model::MachineConfiguration, @xml, @json
   end
 
 end
diff --git a/server/spec/cimi/model/machine_image_spec.rb b/server/spec/cimi/model/machine_image_spec.rb
index d4af9af..f284952 100644
--- a/server/spec/cimi/model/machine_image_spec.rb
+++ b/server/spec/cimi/model/machine_image_spec.rb
@@ -21,16 +21,9 @@ describe "MachineImage model" do
     @json = IO::read(File::join(DATA_DIR, "machine_image.json"))
   end
 
-  it "can be constructed from XML" do
-    img = CIMI::Model::MachineImage.from_xml(@xml)
-    img.should_not be_nil
-    should_serialize_from_xml! img, @xml, @json
+  it "can be constructed from XML and JSON" do
+    should_properly_serialize_model CIMI::Model::MachineImage, @xml, @json
   end
 
-  it "can be constructed from JSON" do
-    img = CIMI::Model::MachineImage.from_json(@json)
-    img.should_not be_nil
-    should_serialize_from_json! img, @xml, @json
-  end
 
 end
diff --git a/server/spec/cimi/model/machine_spec.rb b/server/spec/cimi/model/machine_spec.rb
index f1ee296..59b5d6f 100644
--- a/server/spec/cimi/model/machine_spec.rb
+++ b/server/spec/cimi/model/machine_spec.rb
@@ -20,21 +20,8 @@ describe "Machine model" do
     @json = IO::read(File::join(DATA_DIR, "machine.json"))
   end
 
-  it "should hold just machine schema" do
-    CIMI::Model::Machine.schema.attribute_names.should_not include(:image_location)
-    CIMI::Model::Machine.schema.attribute_names.should include(:meters)
-  end
-
-  it "can be constructed from XML" do
-    machine = CIMI::Model::Machine.from_xml(@xml)
-    machine.should_not be_nil
-    should_serialize_from_xml! machine, @xml, @json
-  end
-
-  it "can be constructed from JSON" do
-    machine = CIMI::Model::Machine.from_json(@json)
-    machine.should_not be_nil
-    should_serialize_from_json! machine, @xml, @json
+  it "can be constructed from XML and JSON" do
+    should_properly_serialize_model CIMI::Model::Machine, @xml, @json
   end
 
 end
diff --git a/server/spec/cimi/model/machine_template_spec.rb b/server/spec/cimi/model/machine_template_spec.rb
index 0c6f50a..3ca2c9a 100644
--- a/server/spec/cimi/model/machine_template_spec.rb
+++ b/server/spec/cimi/model/machine_template_spec.rb
@@ -20,16 +20,8 @@ describe "MachineTemplate model" do
     @json = IO::read(File::join(DATA_DIR, "machine_template.json"))
   end
 
-  it "can be constructed from XML" do
-    conf = CIMI::Model::MachineTemplate.from_xml(@xml)
-    conf.should_not be_nil
-    should_serialize_from_xml! conf, @xml, @json
-  end
-
-  it "can be constructed from JSON" do
-    conf = CIMI::Model::MachineTemplate.from_json(@json)
-    conf.should_not be_nil
-    should_serialize_from_json! conf, @xml, @json
+  it "can be constructed from XML and JSON" do
+    should_properly_serialize_model CIMI::Model::MachineTemplate, @xml, @json
   end
 
 end
diff --git a/server/spec/cimi/model/volume_spec.rb b/server/spec/cimi/model/volume_spec.rb
index 829dc57..d208e15 100644
--- a/server/spec/cimi/model/volume_spec.rb
+++ b/server/spec/cimi/model/volume_spec.rb
@@ -21,16 +21,8 @@ describe "Volume model" do
     @json = IO::read(File::join(DATA_DIR, "volume.json"))
   end
 
-  it "can be constructed from XML" do
-    conf = CIMI::Model::Volume.from_xml(@xml)
-    conf.should_not be_nil
-    should_serialize_from_xml! conf, @xml, @json
-  end
-
-  it "can be constructed from JSON" do
-    conf = CIMI::Model::Volume.from_json(@json)
-    conf.should_not be_nil
-    should_serialize_from_json! conf, @xml, @json
+  it "can be constructed from XML and JSON" do
+    should_properly_serialize_model CIMI::Model::Volume, @xml, @json
   end
 
 end
diff --git a/server/spec/spec_helper.rb b/server/spec/spec_helper.rb
index c8b41fc..69d4797 100644
--- a/server/spec/spec_helper.rb
+++ b/server/spec/spec_helper.rb
@@ -90,14 +90,13 @@ class HashCmp
   end
 end
 
-def should_serialize_from_xml!(model, xml, json)
-  model.to_xml.should serialize_to xml, :fmt => :xml
-  model.to_json.should serialize_to json, :fmt => :json
-end
-
-def should_serialize_from_json!(model, xml, json)
-  model.to_xml.should serialize_to xml, :fmt => :xml
-  model.to_json.should serialize_to json, :fmt => :json
+def should_properly_serialize_model(model_class, xml, json)
+  # Roundtrip in same format
+  model_class.from_xml(xml).should serialize_to xml, :fmt => :xml
+  model_class.from_json(json).should serialize_to json, :fmt => :json
+  # Roundtrip crossing format
+  model_class.from_xml(xml).should serialize_to json, :fmt => :json
+  model_class.from_json(json).should serialize_to xml, :fmt => :xml
 end
 
 RSpec::Matchers.define :serialize_to do |exp, opts|
-- 
1.7.4.4


Re: [PATCH core 1/5] CIMI: Added 'should_properly_serialize_model' helper to RSpec tests

Posted by "marios@redhat.com" <ma...@redhat.com>.
ACK, pushed

On 24/11/11 02:34, David Lutterkort wrote:
> This fails in two places: (1) ruby-debug19 is not found (it shouldn't
> look for it since I am on mri_18, but who knows); is there a good reason
> why we even mention ruby-debug in the Gemfile ? FWIW, you can do
> development perfectly fine without a debugger installed. (2) no rspec ~>
> 2.0.0; I have 2.7.0. Is there a good reason why we can't just require
> rspec >= 2.0.0 ?
> 
> TL;DR: can we commit this patch (and whoever ACK's this should just
> commit it):
> 
> diff --git a/server/Gemfile b/server/Gemfile
> index f453f4a..b3180e3 100644
> --- a/server/Gemfile
> +++ b/server/Gemfile
> @@ -3,8 +3,6 @@ source "http://rubygems.org"
>  gemspec
>  
>  group :development do
> -  gem 'ruby-debug', :platforms => :mri_18
> -  gem 'ruby-debug19', :platforms => :mri_19, :require => 'ruby-debug'
>    gem "compass", ">= 0.8.17"
>    gem "vcr"
>    gem "webmock"
> @@ -12,6 +10,6 @@ group :development do
>    gem "ci_reporter"
>    gem "cucumber", ">= 0.6.3"
>    gem "rcov", ">= 0.9.8"
> -  gem "rspec", "~> 2.0.0"
> +  gem "rspec", ">= 2.0.0"
>  end
> 
> David
> 
> 


Re: [PATCH core 1/5] CIMI: Added 'should_properly_serialize_model' helper to RSpec tests

Posted by David Lutterkort <lu...@redhat.com>.
On Wed, 2011-11-23 at 17:23 +0100, mfojtik@redhat.com wrote:
> From: Michal Fojtik <mf...@redhat.com>
> 
> 
> Signed-off-by: Michal fojtik <mf...@redhat.com>
> ---
>  server/spec/cimi/model/machine_admin_spec.rb       |   14 ++------------
>  .../spec/cimi/model/machine_configuration_spec.rb  |   12 ++----------
>  server/spec/cimi/model/machine_image_spec.rb       |   11 ++---------
>  server/spec/cimi/model/machine_spec.rb             |   17 ++---------------
>  server/spec/cimi/model/machine_template_spec.rb    |   12 ++----------
>  server/spec/cimi/model/volume_spec.rb              |   12 ++----------
>  server/spec/spec_helper.rb                         |   15 +++++++--------
>  7 files changed, 19 insertions(+), 74 deletions(-)

This gives me a bunch of spec failures since should_serialize_from_json!
and should_serialize_from_xml! are still used in some specs.

ACK after updating those specs.

Incidentally, on my Fedora 15 machine, I also run into trouble with the
Gemfile:

        source "http://rubygems.org"
        
        gemspec
        
        group :development do
          gem 'ruby-debug', :platforms => :mri_18
          gem 'ruby-debug19', :platforms => :mri_19, :require => 'ruby-debug'
          gem "compass", ">= 0.8.17"
          gem "vcr"
          gem "webmock"
          gem "rack-test", ">= 0.5.3"
          gem "ci_reporter"
          gem "cucumber", ">= 0.6.3"
          gem "rcov", ">= 0.9.8"
          gem "rspec", "~> 2.0.0"
        end

This fails in two places: (1) ruby-debug19 is not found (it shouldn't
look for it since I am on mri_18, but who knows); is there a good reason
why we even mention ruby-debug in the Gemfile ? FWIW, you can do
development perfectly fine without a debugger installed. (2) no rspec ~>
2.0.0; I have 2.7.0. Is there a good reason why we can't just require
rspec >= 2.0.0 ?

TL;DR: can we commit this patch (and whoever ACK's this should just
commit it):

diff --git a/server/Gemfile b/server/Gemfile
index f453f4a..b3180e3 100644
--- a/server/Gemfile
+++ b/server/Gemfile
@@ -3,8 +3,6 @@ source "http://rubygems.org"
 gemspec
 
 group :development do
-  gem 'ruby-debug', :platforms => :mri_18
-  gem 'ruby-debug19', :platforms => :mri_19, :require => 'ruby-debug'
   gem "compass", ">= 0.8.17"
   gem "vcr"
   gem "webmock"
@@ -12,6 +10,6 @@ group :development do
   gem "ci_reporter"
   gem "cucumber", ">= 0.6.3"
   gem "rcov", ">= 0.9.8"
-  gem "rspec", "~> 2.0.0"
+  gem "rspec", ">= 2.0.0"
 end

David