forked from thoughtbot/shoulda-context
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
brand new documentation
- Loading branch information
Dan Croak
committed
Dec 15, 2010
1 parent
d1c6ba6
commit 891c94c
Showing
1 changed file
with
19 additions
and
18 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,53 @@ | ||
= shoulda-context | ||
|
||
{Official Documentation}[http://rubydoc.info/github/thoughtbot/shoulda-context/master/frames] | ||
|
||
Shoulda's contexts make it easy to write understandable and maintainable tests for Test::Unit. | ||
It's fully compatible with your existing tests in Test::Unit, and requires no retooling to use. | ||
|
||
Refer to the {shoulda}[https://github.com/thoughtbot/shoulda] gem if you want to know more | ||
about using shoulda with Rails or RSpec. | ||
|
||
== Contexts | ||
|
||
Stop killing your fingers with all of those underscores... Name your tests with plain sentences! | ||
Instead of writing Ruby methods with lots_of_underscores, shoulda-context adds | ||
context, setup, and should blocks... | ||
|
||
class UserTest < Test::Unit::TestCase | ||
context "A User instance" do | ||
class CalculatorTest < Test::Unit::TestCase | ||
context "a calculator" do | ||
setup do | ||
@user = User.find(:first) | ||
@calculator = Calculator.new | ||
end | ||
|
||
should "return its full name" do | ||
assert_equal "John Doe", @user.full_name | ||
should "add two numbers for the sum" do | ||
assert_equal 4, @calculator.sum(2, 2) | ||
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 | ||
should "multiply two numbers for the product" do | ||
assert_equal 10, @calculator.product(2, 5) | ||
end | ||
end | ||
end | ||
|
||
Produces the following test methods: | ||
... which combine to produce 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! | ||
|
||
== Assertions | ||
|
||
It also has two additional Test::Unit assertions for working with Ruby's Array: | ||
|
||
assert_same_elements([:a, :b, :c], [:c, :a, :b]) | ||
assert_contains(['a', '1'], /\d/) | ||
assert_contains(['a', '1'], 'a') | ||
|
||
= Credits | ||
|
||
Shoulda is maintained and funded by {thoughtbot}[http://thoughtbot.com/community]. | ||
Thank you to all the {contributors}[https://github.com/thoughtbot/shoulda-context/contributors]. | ||
|
||
= License | ||
|
||
Shoulda is Copyright © 2010 thoughtbot, inc. | ||
Shoulda is Copyright © 2006-2010 thoughtbot, inc. | ||
It is free software, and may be redistributed under the terms specified in the MIT-LICENSE file. |