Skip to content

Commit

Permalink
more updates to README: replacing Macros references to Matchers where…
Browse files Browse the repository at this point in the history
… appropriate, prioritizing matchers first, helpers (context and should) second
  • Loading branch information
Dan Croak committed Jun 17, 2010
1 parent 385907e commit f3e56ed
Showing 1 changed file with 44 additions and 47 deletions.
91 changes: 44 additions & 47 deletions README.rdoc
Original file line number Diff line number Diff line change
@@ -1,56 +1,20 @@
= Shoulda - Making tests easy on the fingers and eyes

Shoulda makes it easy to write elegant, understandable, and maintainable tests. Shoulda consists of test macros, assertions, and helpers added on to the Test::Unit framework. It's fully compatible with your existing tests, and requires no retooling to use.
Shoulda makes it easy to write elegant, understandable, and maintainable tests. Shoulda consists of matchers, test helpers, and assertions. It's fully compatible with your existing tests in Test::Unit or RSpec, and requires no retooling to use.

Helpers:: #context and #should give you RSpec like test blocks.
Matchers:: Test::Unit- and RSpec-compatible one-liners that test common Rails functionality.
These tests would otherwise be much longer, more complex, and error-prone.
Helpers:: #context and #should give you RSpec like test blocks in Test::Unit.
In addition, you get nested contexts and a much more readable syntax.
Macros:: Generate hundreds of lines of Controller and ActiveRecord tests with these powerful macros.
They get you started quickly, and can help you ensure that your application is conforming to best practices.
Assertions:: Many common rails testing idioms have been distilled into a set of useful assertions.
Matchers:: Rspec-compatible matchers providing the same tests as Shoulda macros.
Assertions:: Many common Rails testing idioms have been distilled into a set of useful assertions.

= Usage

=== Context Helpers (Shoulda::Context)

Stop killing your fingers with all of those underscores... Name your tests with plain sentences!

class UserTest < Test::Unit::TestCase
context "A User instance" do
setup do
@user = User.find(:first)
end
=== ActiveRecord Tests (Shoulda::ActiveRecord::Matchers)

should "return its full name" do
assert_equal 'John Doe', @user.full_name
end

context "with a profile" do
setup do
@user.profile = Profile.find(:first)
end

should "return true when sent #has_profile?" do
assert @user.has_profile?
end
end
end
end

Produces the following test methods:

"test: A User instance should return its full name."
"test: A User instance with a profile should return true when sent #has_profile?."

So readable!

=== ActiveRecord Tests (Shoulda::ActiveRecord::Macros)

Quick macro tests for your ActiveRecord associations and validations:
Test your ActiveRecord associations and validations with these powerful matchers:

class PostTest < Test::Unit::TestCase
fixtures :all

should belong_to(:user)
should have_many(:tags).through(:taggings)

Expand All @@ -74,10 +38,10 @@ Quick macro tests for your ActiveRecord associations and validations:

Makes TDD so much easier.

=== Controller Tests (Shoulda::Controller::Macros)
=== Controller Tests (Shoulda::Controller::Matchers)

Matchers to test the most common controller patterns...

Macros to test the most common controller patterns...

class PostsControllerTest < ActionController::TestCase
context "on GET to :show for first record" do
setup do
Expand All @@ -94,7 +58,40 @@ Macros to test the most common controller patterns...
end
end
end


=== Context Helpers (Shoulda::Context)

Stop killing your fingers with all of those underscores... Name your tests with plain sentences!

class UserTest < Test::Unit::TestCase
context "A User instance" do
setup do
@user = User.find(:first)
end

should "return its full name" do
assert_equal 'John Doe', @user.full_name
end

context "with a profile" do
setup do
@user.profile = Profile.find(:first)
end

should "return true when sent #has_profile?" do
assert @user.has_profile?
end
end
end
end

Produces the following test methods:

"test: A User instance should return its full name."
"test: A User instance with a profile should return true when sent #has_profile?."

So readable!

=== Helpful Assertions (Shoulda::Assertions)

More to come here, but have fun with what's there.
Expand Down

0 comments on commit f3e56ed

Please sign in to comment.