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:
> 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, LLChttp://
www.yourmediashelf.com