Account Options

  1. Sign in
The old Google Groups will be going away soon.
Switch to the new Google Groups.
Google Groups Home
« Groups Home
proper way to stub Fedora connection?
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  3 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Bess Sadler  
View profile  
 More options Sep 6 2011, 12:45 am
From: Bess Sadler <bess.sad...@gmail.com>
Date: Mon, 5 Sep 2011 21:45:52 -0700
Local: Tues, Sep 6 2011 12:45 am
Subject: proper way to stub Fedora connection?
When you're writing unit tests and you want to fake your fedora connection, what's the best way to do it? Right now I have this line in some of my tests:

    Fedora::Repository.stubs(:instance).returns(stub('stub').as_null_object)

It stubs the Fedora connection just fine, but it means that later, in other tests where I want a real connection to Fedora, I'm getting a stub back instead. Can anyone tell me how to clean up after this stub statement (ActiveFedora.init doesn't work, I tried that) or else give me a better way to mock the connection and then get it back after?

Thanks in advance,
Bess


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Matt Zumwalt  
View profile  
 More options Sep 6 2011, 1:00 am
From: Matt Zumwalt <matt.zumw...@yourmediashelf.com>
Date: Tue, 6 Sep 2011 00:00:20 -0500
Local: Tues, Sep 6 2011 1:00 am
Subject: Re: proper way to stub Fedora connection?

This is a perennial issue with RSpec.  It's bad about unstubbing Class methods like, in this case Fedora::Repository.instance

Technically, RSpec should be unstubbing the class methods after the particular tests run.  Failing that, you should be able to call Fedora::Repository.unstub(:instance) but that usually doesn't seem to actually work.

In the ActiveFedora tests, I do have before blocks that stub Fedora::Repository.instance and it is releasing that stub after running without the test explicitly calling unstub.  Possibly it's sensitive to where you set up the stub?

Example in: spec/unit/base_file_management_spec.rb

describe ActiveFedora::Base do

  before(:each) do
    Fedora::Repository.stubs(:instance).returns(stub_everything())
    ...
   end

end

Matt Zumwalt
MediaShelf, LLC
http://www.yourmediashelf.com

On Sep 5, 2011, at 11:45 PM, Bess Sadler wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Alexander  
View profile  
 More options Sep 7 2011, 5:24 am
From: Alexander <alexander.n.paramo...@gmail.com>
Date: Wed, 7 Sep 2011 02:24:05 -0700 (PDT)
Local: Wed, Sep 7 2011 5:24 am
Subject: Re: proper way to stub Fedora connection?
I am also facing this issue. I desided to inject into Repository like
this
Fedora::NulledRepository.inject
Fedora::NulledRepository.revert

where NulledRepository works as collection to store incoming objects,
but i didnt finish that yet.
so if you need only to stub an instance, alias that method and ignore
all requests, after you done, return old method back.

its first implementation:
    def self.instance
      @instance ||= self.new
    end

    def self.inject
      raise "injected called twice!" if @injected
      @injected = true
      @instance = nil
      class << Fedora::Repository
        # save real instance
        alias_method :real_instance, :instance

        def instance
          Fedora::NulledRepository.instance
        end
      end
    end

    def self.revert
      if Fedora::Repository.respond_to? :real_instance then
        class << Fedora::Repository
          # revert real instance
          alias_method :instance, :real_instance
        end

        @injected = false
      end
    end

On 6 ÓĹÎ, 08:00, Matt Zumwalt <matt.zumw...@yourmediashelf.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions Older topic »