Created
May 13, 2013 22:03
-
-
Save KristineHines/5571893 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
Shoulda allows you to create unit tests and matchers in a light-weight, readable format. | |
Matchers | |
Matchers for Active Record test associations. | |
Active Record matchers | |
describe Post do | |
it {should belong_to(:user)} | |
it {should have_many(:tags).through(:taggings)} | |
end | |
Matchers for Active Model tests valiations. | |
Active Model matchers | |
describe Post do | |
it {should validate_uniqueness of(:title)} | |
end | |
describe User do | |
it {should_not allow_value("blah").for(:email)} | |
end | |
Unit Testing | |
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 "multiply two numbers for the product" do | |
assert_equal 10, @calculator.product(2, 5) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment