-
-
Save matid/584078 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
class PostTest < ActiveSupport::TestCase | |
test "adds 20 points to post author" do | |
@post.save! | |
assert 20, @post.author.points # should be assert_equal | |
end | |
should "add 20 points to post author" do | |
@post.save! | |
@post.author.points == 20 # no assertion, should be "@post.author.points.should == 20" | |
end | |
end |
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
class PostTest < ActiveSupport::TestCase | |
def setup | |
@post = Post.make # "generic" post | |
@old_post = Post.make(:created_at => 1.year.ago) | |
@reported_post = Post.make.tap(&:report) | |
end | |
# ... | |
end |
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
class PostTest < ActiveSupport::TestCase | |
def setup | |
@post = Post.make_unsaved | |
end | |
test "reporting posts" do | |
@post.report! # saves and reports the post when needed | |
assert @post.reported? | |
end | |
# ... | |
end |
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
class PostTest < ActiveSupport::TestCase | |
def self.startup | |
@@author = User.make | |
end | |
def setup | |
@post = Post.make_unsaved(:author => @@author) | |
end | |
test "saves successfully" do | |
assert @post.save | |
end | |
test "can be reported" do | |
@post.save | |
assert @post.report | |
end | |
# ... | |
end |
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
module RemovableTests | |
def test_sets_removed_at_attribute | |
@model.remove | |
assert @model.removed_at | |
end | |
end | |
class PostTest < ActiveSupport::TestCase | |
include RemovableTests | |
def setup | |
@post = @model = Post.make_unsaved | |
end | |
# ... | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I find 1.rb to be more of a problem with Test::Unit than RSpec. In Rspec, everything you write, ends in .should . While of course you could leave it off by accident, once you write a few RSpec tests, it rarely happens again. I did the assert vs. assert_equal thing all the time.