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:
parent
9e1188eea6
commit
f5b5617663
1 changed files with 53 additions and 43 deletions
10
README.md
10
README.md
|
@ -12,6 +12,7 @@ about using shoulda with Test::Unit.
|
|||
|
||||
Matchers to test associations:
|
||||
|
||||
```ruby
|
||||
describe Post do
|
||||
it { should belong_to(:user) }
|
||||
it { should have_many(:tags).through(:taggings) }
|
||||
|
@ -20,11 +21,13 @@ Matchers to test associations:
|
|||
describe User do
|
||||
it { should have_many(:posts) }
|
||||
end
|
||||
```
|
||||
|
||||
## ActiveModel Matchers
|
||||
|
||||
Matchers to test validations and mass assignments:
|
||||
|
||||
```ruby
|
||||
describe Post do
|
||||
it { should validate_uniqueness_of(:title) }
|
||||
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_not allow_mass_assignment_of(:password) }
|
||||
end
|
||||
```
|
||||
|
||||
## ActionController Matchers
|
||||
|
||||
Matchers to test common patterns:
|
||||
|
||||
```ruby
|
||||
describe PostsController, "#show" do
|
||||
context "for a fictional user" do
|
||||
before do
|
||||
|
@ -57,19 +62,23 @@ Matchers to test common patterns:
|
|||
it { should_not set_the_flash }
|
||||
end
|
||||
end
|
||||
```
|
||||
|
||||
## Independent Matchers
|
||||
|
||||
Matchers to test non-Rails-dependent code:
|
||||
|
||||
```ruby
|
||||
describe Human do
|
||||
it { should delegate_method(:work).to(:robot) }
|
||||
end
|
||||
```
|
||||
|
||||
## Installation
|
||||
|
||||
In Rails 3 and Bundler, add the following to your Gemfile:
|
||||
|
||||
```ruby
|
||||
group :test do
|
||||
gem "shoulda-matchers"
|
||||
end
|
||||
|
@ -79,6 +88,7 @@ In Rails 3 and Bundler, add the following to your Gemfile:
|
|||
group :development, :test do
|
||||
gem "rspec-rails"
|
||||
end
|
||||
```
|
||||
|
||||
Shoulda will automatically include matchers into the appropriate example groups.
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue