Skip to content

Instantly share code, notes, and snippets.

@matid
Created September 17, 2010 11:23
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 matid/584078 to your computer and use it in GitHub Desktop.
Save matid/584078 to your computer and use it in GitHub Desktop.
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
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
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
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
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
@scotttam
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment