Skip to content

Instantly share code, notes, and snippets.

@notahat
Forked from geelen/this_should_fail.rb
Created March 29, 2012 02:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save notahat/2232627 to your computer and use it in GitHub Desktop.
Save notahat/2232627 to your computer and use it in GitHub Desktop.
class Dependency
def self.foo
puts "Foo"
end
def self.bar
puts "Bar"
end
end
class ClassUnderTest
def self.go
Dependency.foo
Dependency.bar
end
end
describe ClassUnderTest do
it "should call dependencies" do
# This script prints "Bar" and passes.
# I want it to explode because calling Dependency.bar was not mocked out.
# i.e. I don't want to accidentally call a real method on the dependency.
# The only way I can see to do this is to add the following line, but that sucks:
#
# Dependency = mock
Dependency.should_receive(:foo)
ClassUnderTest.go
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment