Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 97 lines (65 sloc) 2.741 kb
43a3cb7 Steve Richert Fix SSL Travis build status image
laserlemon authored
1 # shoulda [![Build Status](https://secure.travis-ci.org/thoughtbot/shoulda.png)](http://travis-ci.org/thoughtbot/shoulda)
8d48a1a convert the README to markdown, add credit and license info
Chad Pytel authored
2
9c59966 Joe Ferris Updated docs
jferris authored
3 The shoulda gem is a meta gem with two dependencies:
8d48a1a convert the README to markdown, add credit and license info
Chad Pytel authored
4
9c59966 Joe Ferris Updated docs
jferris authored
5 * [shoulda-context](https://github.com/thoughtbot/shoulda-context)
6 * [shoulda-matchers](https://github.com/thoughtbot/shoulda-matchers)
8d48a1a convert the README to markdown, add credit and license info
Chad Pytel authored
7
9c59966 Joe Ferris Updated docs
jferris authored
8 Official documentation for each gem:
8d48a1a convert the README to markdown, add credit and license info
Chad Pytel authored
9
9c59966 Joe Ferris Updated docs
jferris authored
10 * [shoulda-context](http://rubydoc.info/github/thoughtbot/shoulda-context/master/frames)
11 * [shoulda-matchers](http://rubydoc.info/github/thoughtbot/shoulda-matchers/master/frames)
8d48a1a convert the README to markdown, add credit and license info
Chad Pytel authored
12
9c59966 Joe Ferris Updated docs
jferris authored
13 The following describes different use cases and combinations.
8d48a1a convert the README to markdown, add credit and license info
Chad Pytel authored
14
9c59966 Joe Ferris Updated docs
jferris authored
15 rspec with shoulda-matchers
16 ---------------------------
8d48a1a convert the README to markdown, add credit and license info
Chad Pytel authored
17
9c59966 Joe Ferris Updated docs
jferris authored
18 This is what thoughtbot currently does. We write tests like:
8d48a1a convert the README to markdown, add credit and license info
Chad Pytel authored
19
5565a11 Matt Jankowski markdown wants more spaces for code samples
mjankowski authored
20 describe Post do
21 it { should belong_to(:user) }
22 it { should validate_presence_of(:title) }
23 end
8d48a1a convert the README to markdown, add credit and license info
Chad Pytel authored
24
9c59966 Joe Ferris Updated docs
jferris authored
25 The belong_to and validate_presence_of methods are the matchers.
26 All matchers are Rails 3-specific.
8d48a1a convert the README to markdown, add credit and license info
Chad Pytel authored
27
e8a866d Tristan Dunn Documentation correction.
tristandunn authored
28 Add rspec-rails and shoulda-matchers to the project's Gemfile:
8d48a1a convert the README to markdown, add credit and license info
Chad Pytel authored
29
a6e7d11 Frankie Roberto Updating 'only' to 'group', as 'only' has been deprecated from Bundler 0...
frankieroberto authored
30 group :test do
5565a11 Matt Jankowski markdown wants more spaces for code samples
mjankowski authored
31 gem 'rspec-rails'
32 gem 'shoulda-matchers'
33 end
8d48a1a convert the README to markdown, add credit and license info
Chad Pytel authored
34
9c59966 Joe Ferris Updated docs
jferris authored
35 test/unit with shoulda
36 ----------------------
8d48a1a convert the README to markdown, add credit and license info
Chad Pytel authored
37
9c59966 Joe Ferris Updated docs
jferris authored
38 For the folks who prefer Test::Unit, they'd write tests like:
8d48a1a convert the README to markdown, add credit and license info
Chad Pytel authored
39
5565a11 Matt Jankowski markdown wants more spaces for code samples
mjankowski authored
40 class UserTest < Test::Unit::TestCase
41 should have_many(:posts)
42 should_not allow_value("blah").for(:email)
43 end
8d48a1a convert the README to markdown, add credit and license info
Chad Pytel authored
44
9c59966 Joe Ferris Updated docs
jferris authored
45 The have_many and allow_value methods are the same kind of matchers
46 seen in the RSpec example. They come from the shoulda-matchers gem.
8d48a1a convert the README to markdown, add credit and license info
Chad Pytel authored
47
9c59966 Joe Ferris Updated docs
jferris authored
48 Add shoulda to the project's Gemfile:
8d48a1a convert the README to markdown, add credit and license info
Chad Pytel authored
49
a6e7d11 Frankie Roberto Updating 'only' to 'group', as 'only' has been deprecated from Bundler 0...
frankieroberto authored
50 group :test do
5565a11 Matt Jankowski markdown wants more spaces for code samples
mjankowski authored
51 gem 'shoulda'
52 end
8d48a1a convert the README to markdown, add credit and license info
Chad Pytel authored
53
9c59966 Joe Ferris Updated docs
jferris authored
54 test/unit with shoulda-context
55 ------------------------------
8d48a1a convert the README to markdown, add credit and license info
Chad Pytel authored
56
9c59966 Joe Ferris Updated docs
jferris authored
57 If you're not testing a Rails project or don't want to use the matchers,
58 you can use shoulda-context independently to write tests like:
8d48a1a convert the README to markdown, add credit and license info
Chad Pytel authored
59
5565a11 Matt Jankowski markdown wants more spaces for code samples
mjankowski authored
60 class CalculatorTest < Test::Unit::TestCase
61 context "a calculator" do
62 setup do
63 @calculator = Calculator.new
64 end
8d48a1a convert the README to markdown, add credit and license info
Chad Pytel authored
65
5565a11 Matt Jankowski markdown wants more spaces for code samples
mjankowski authored
66 should "add two numbers for the sum" do
67 assert_equal 4, @calculator.sum(2, 2)
68 end
8d48a1a convert the README to markdown, add credit and license info
Chad Pytel authored
69
5565a11 Matt Jankowski markdown wants more spaces for code samples
mjankowski authored
70 should "multiply two numbers for the product" do
71 assert_equal 10, @calculator.product(2, 5)
72 end
9c59966 Joe Ferris Updated docs
jferris authored
73 end
8d48a1a convert the README to markdown, add credit and license info
Chad Pytel authored
74 end
9c59966 Joe Ferris Updated docs
jferris authored
75
76 Add shoulda-context to the project's Gemfile:
8d48a1a convert the README to markdown, add credit and license info
Chad Pytel authored
77
a6e7d11 Frankie Roberto Updating 'only' to 'group', as 'only' has been deprecated from Bundler 0...
frankieroberto authored
78 group :test do
5565a11 Matt Jankowski markdown wants more spaces for code samples
mjankowski authored
79 gem 'shoulda-context'
80 end
8d48a1a convert the README to markdown, add credit and license info
Chad Pytel authored
81
82 Credits
83 -------
84
85 ![thoughtbot](http://thoughtbot.com/images/tm/logo.png)
86
87 Shoulda is maintained and funded by [thoughtbot, inc](http://thoughtbot.com/community)
88
cc184ac Matt Jankowski add contributors line
mjankowski authored
89 Thank you to all [the contributors](https://github.com/thoughtbot/shoulda/contributors)!
90
8d48a1a convert the README to markdown, add credit and license info
Chad Pytel authored
91 The names and logos for thoughtbot are trademarks of thoughtbot, inc.
92
93 License
94 -------
95
7be3592 Adarsh Pandit Update copyright year
adarsh authored
96 Shoulda is Copyright © 2006-2012 Tammer Saleh, thoughtbot. It is free software, and may be redistributed under the terms specified in the MIT-LICENSE file.
Something went wrong with that request. Please try again.