Created
May 1, 2014 13:34
-
-
Save jarrettmeyer/bf66de831fa30cb0199b to your computer and use it in GitHub Desktop.
This file contains 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
describe User do | |
# The test suite adds a #stub() method to every object. Since instances of objects | |
# and class definitions are considered objects in Ruby, the #stub() method gets | |
# applied just about everywhere. It can be used to stub both instance methods and | |
# class methods. | |
it "can have tests that hit a database" do | |
user = User.find(1) # This test will go to the database | |
expect(user.username).to eq("admin") | |
end | |
it "can have tests that are stubbed" do | |
User.stub(:find) do |id| | |
User.new { id: id, username: "user-#{id}" } | |
end | |
user = User.find(123) | |
expect(user.username).to eq("user-123") # This has been stubbed | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment