module RspecStubout

Constants

VERSION

Public Instance Methods

prevent_stub_on(o) click to toggle source
# File lib/rspec_stubout/prevent_stubout.rb, line 20
def prevent_stub_on(o)
  unless o.nil?
    o.stub(:stub) { raise "#{o} is the object under test and should not be stubbed" }
  end
end
prevent_stubout(rspec_config) click to toggle source
# File lib/rspec_stubout/prevent_stubout.rb, line 7
def prevent_stubout(rspec_config)
  rspec_config.before(:each) do
    unless example.metadata[:allow_stubout]
      begin
        RspecStubout.prevent_stub_on(subject)
        RspecStubout.prevent_stub_on(described_class) unless described_class == subject
      rescue => e
        warn "rspec stubout setup failed, possibly setup in another before(:each) has not run yet: #{e.backtrace[0]}, #{e.inspect}"
      end
    end
  end
end