This file should be yum_spec.rb instead of yum.rb.  It both matches
what all the other spec files do and it prevents weird loading errors
in ruby if an implementation file ever does a "require 'yum'".

On the downgrade test there is a way to have stubbed query return two
different things.

http://mocha.rubyforge.org/classes/Mocha/Expectation.html#M000047

--- a/spec/unit/provider/package/yum.rb
+++ b/spec/unit/provider/package/yum.rb
@@ -44,11 +44,9 @@ describe provider do
     it 'should be able to downgrade' do
       @resource.stubs(:should).with(:ensure).returns '1.0'
       @provider.expects(:yum).with('-d', '0', '-e', '0', '-y',
:downgrade, 'mypackage-1.0')
-      @provider.stubs(:query).returns :ensure => '1.2'
-      stubs(:raise).returns true
-      # this is annoying that it has to raise an expcetion here
-      # it is because I can only stub query once and it is called twice.
-      lambda {[email protected]}.should raise_error(Puppet::Error)
+
+      @provider.stubs(:query).returns(:ensure =>
'1.2').then.returns(:ensure => '1.0')
+      @provider.install
     end
   end


On Tue, Sep 7, 2010 at 3:08 PM, Dan Bode <[email protected]> wrote:
> patch originally from Grzegorz Nosek with contributions on
> the test from Oliver Hookins.
>
> checks if the current version is greater than the should
> version, if so, calls yum downgrade.
>
> Signed-off-by: Dan Bode <[email protected]>
> ---
>  spec/unit/provider/package/yum.rb |   23 ++++++++++++++++-------
>  1 files changed, 16 insertions(+), 7 deletions(-)
>
> diff --git a/spec/unit/provider/package/yum.rb 
> b/spec/unit/provider/package/yum.rb
> index ddf6863..b58b688 100644
> --- a/spec/unit/provider/package/yum.rb
> +++ b/spec/unit/provider/package/yum.rb
> @@ -31,21 +31,30 @@ describe provider do
>       @provider.expects(:yum).with('-d', '0', '-e', '0', '-y', :install, 
> 'mypackage')
>       @provider.install
>     end
> -    it "should use :install to update" do
> +    it 'should use :install to update' do
>       @provider.expects(:install)
>       @provider.update
>     end
> -    it "should be able to set version" do
> -     �[email protected](:should).with(:ensure).returns "1.2"
> +    it 'should be able to set version' do
> +     �[email protected](:should).with(:ensure).returns '1.2'
>       @provider.expects(:yum).with('-d', '0', '-e', '0', '-y', :install, 
> 'mypackage-1.2')
> -     �[email protected](:query).returns :ensure => '1.2'
> +     �[email protected](:query).returns :ensure => '1.2'
>       @provider.install
>     end
> +    it 'should be able to downgrade' do
> +     �[email protected](:should).with(:ensure).returns '1.0'
> +     �[email protected](:yum).with('-d', '0', '-e', '0', '-y', 
> :downgrade, 'mypackage-1.0')
> +     �[email protected](:query).returns :ensure => '1.2'
> +      stubs(:raise).returns true
> +      # this is annoying that it has to raise an expcetion here
> +      # it is because I can only stub query once and it is called twice.
> +      lambda {[email protected]}.should raise_error(Puppet::Error)
> +    end
>   end
>
>   describe 'when uninstalling' do
> -    it "should use erase to purge" do
> -     �[email protected](:yum).with("-y", :erase, 'mypackage')
> +    it 'should use erase to purge' do
> +     �[email protected](:yum).with('-y', :erase, 'mypackage')
>       @provider.purge
>     end
>     it 'should use rpm to uninstall' do
> @@ -54,7 +63,7 @@ describe provider do
>     end
>   end
>
> -  it "should be versionable" do
> +  it 'should be versionable' do
>     provider.should be_versionable
>   end
>  end
> --
> 1.5.5.6
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Puppet Developers" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to 
> [email protected].
> For more options, visit this group at 
> http://groups.google.com/group/puppet-dev?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Developers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/puppet-dev?hl=en.

Reply via email to