Permalink
Browse files

markdown wants more spaces for code samples

  • Loading branch information...
1 parent 0cb32aa commit 5565a11513f744f592a3e7863426b04ce99847f1 @mjankowski mjankowski committed Jan 19, 2011
Showing with 29 additions and 29 deletions.
  1. +29 −29 README.md
View
@@ -18,67 +18,67 @@ rspec with shoulda-matchers
This is what thoughtbot currently does. We write tests like:
- describe Post do
- it { should belong_to(:user) }
- it { should validate_presence_of(:title) }
- end
+ describe Post do
+ it { should belong_to(:user) }
+ it { should validate_presence_of(:title) }
+ end
The belong_to and validate_presence_of methods are the matchers.
All matchers are Rails 3-specific.
Add rspec-rails and shoulda-matchers to the project's Gemfile:
- only :test do
- gem 'rspec-rails'
- gem 'shoulda-matchers'
- end
+ only :test do
+ gem 'rspec-rails'
+ gem 'shoulda-matchers'
+ end
test/unit with shoulda
----------------------
For the folks who prefer Test::Unit, they'd write tests like:
- class UserTest < Test::Unit::TestCase
- should have_many(:posts)
- should_not allow_value("blah").for(:email)
- end
+ class UserTest < Test::Unit::TestCase
+ should have_many(:posts)
+ should_not allow_value("blah").for(:email)
+ end
The have_many and allow_value methods are the same kind of matchers
seen in the RSpec example. They come from the shoulda-matchers gem.
Add shoulda to the project's Gemfile:
- only :test do
- gem 'shoulda'
- end
+ only :test do
+ gem 'shoulda'
+ end
test/unit with shoulda-context
------------------------------
If you're not testing a Rails project or don't want to use the matchers,
you can use shoulda-context independently to write tests like:
- class CalculatorTest < Test::Unit::TestCase
- context "a calculator" do
- setup do
- @calculator = Calculator.new
- end
+ class CalculatorTest < Test::Unit::TestCase
+ context "a calculator" do
+ setup do
+ @calculator = Calculator.new
+ end
- should "add two numbers for the sum" do
- assert_equal 4, @calculator.sum(2, 2)
- end
+ should "add two numbers for the sum" do
+ assert_equal 4, @calculator.sum(2, 2)
+ end
- should "multiply two numbers for the product" do
- assert_equal 10, @calculator.product(2, 5)
+ should "multiply two numbers for the product" do
+ assert_equal 10, @calculator.product(2, 5)
+ end
end
end
- end
Add shoulda-context to the project's Gemfile:
- only :test do
- gem 'shoulda-context'
- end
+ only :test do
+ gem 'shoulda-context'
+ end
Credits
-------

0 comments on commit 5565a11

Please sign in to comment.