Module: RspecStubout

Defined in:
lib/rspec_stubout/version.rb,
lib/rspec_stubout/prevent_stubout.rb

Constant Summary collapse

VERSION =
'0.0.4'

Class Method Summary collapse

Class Method Details

.prevent_stub_on(o) ⇒ Object



20
21
22
23
24
# 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) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/rspec_stubout/prevent_stubout.rb', line 7

def prevent_stubout(rspec_config)
  rspec_config.before(:each) do
    unless example.[: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