Created
October 19, 2011 01:34
-
-
Save kbaribeau/1297273 to your computer and use it in GitHub Desktop.
explicit requires, fast specs, and crazy dependencies
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#foo.rb | |
class Foo < Bar | |
end | |
#bar.rb | |
class Bar < ActiveRecord::Base | |
#all sorts of crazy code that depends on a bunch of wacky stuff my tests don't care about | |
end | |
#In my test code, I want to do this | |
it "does something" do | |
fake_foo = stub | |
Foo.stub(:find).and_return(fake_foo) #note that referencing Foo requires the class Foo to be defined | |
end | |
#but, I can't require foo.rb because I would need to require bar.rb, which requires me to pull in a bunch of wacky stuff | |
#my current solution is something like this: | |
before { | |
class Foo; end | |
} | |
it "does something" do | |
Foo.stub(:and).and_return(fake_foo) | |
end | |
after { | |
Object.send(:remove_const, "Foo") | |
} | |
#But that seems ugly. I'm looking for better ideas. Thoughts? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment