1
0
Fork 0
mirror of https://github.com/thoughtbot/shoulda-matchers.git synced 2022-11-09 12:01:38 -05:00

colorize README.md with Github Flavored Markdown

This makes the example code easier to skim, especially on Github
This commit is contained in:
Phil Cohen 2012-11-04 19:55:51 -08:00
parent 9e1188eea6
commit f5b5617663

View file

@ -12,6 +12,7 @@ about using shoulda with Test::Unit.
Matchers to test associations: Matchers to test associations:
```ruby
describe Post do describe Post do
it { should belong_to(:user) } it { should belong_to(:user) }
it { should have_many(:tags).through(:taggings) } it { should have_many(:tags).through(:taggings) }
@ -20,11 +21,13 @@ Matchers to test associations:
describe User do describe User do
it { should have_many(:posts) } it { should have_many(:posts) }
end end
```
## ActiveModel Matchers ## ActiveModel Matchers
Matchers to test validations and mass assignments: Matchers to test validations and mass assignments:
```ruby
describe Post do describe Post do
it { should validate_uniqueness_of(:title) } it { should validate_uniqueness_of(:title) }
it { should validate_uniqueness_of(:title).scoped_to(:user_id, :category_id) } it { should validate_uniqueness_of(:title).scoped_to(:user_id, :category_id) }
@ -40,11 +43,13 @@ Matchers to test validations and mass assignments:
it { should ensure_inclusion_of(:age).in_range(1..100) } it { should ensure_inclusion_of(:age).in_range(1..100) }
it { should_not allow_mass_assignment_of(:password) } it { should_not allow_mass_assignment_of(:password) }
end end
```
## ActionController Matchers ## ActionController Matchers
Matchers to test common patterns: Matchers to test common patterns:
```ruby
describe PostsController, "#show" do describe PostsController, "#show" do
context "for a fictional user" do context "for a fictional user" do
before do before do
@ -57,19 +62,23 @@ Matchers to test common patterns:
it { should_not set_the_flash } it { should_not set_the_flash }
end end
end end
```
## Independent Matchers ## Independent Matchers
Matchers to test non-Rails-dependent code: Matchers to test non-Rails-dependent code:
```ruby
describe Human do describe Human do
it { should delegate_method(:work).to(:robot) } it { should delegate_method(:work).to(:robot) }
end end
```
## Installation ## Installation
In Rails 3 and Bundler, add the following to your Gemfile: In Rails 3 and Bundler, add the following to your Gemfile:
```ruby
group :test do group :test do
gem "shoulda-matchers" gem "shoulda-matchers"
end end
@ -79,6 +88,7 @@ In Rails 3 and Bundler, add the following to your Gemfile:
group :development, :test do group :development, :test do
gem "rspec-rails" gem "rspec-rails"
end end
```
Shoulda will automatically include matchers into the appropriate example groups. Shoulda will automatically include matchers into the appropriate example groups.