This commit is contained in:
Rico Sta. Cruz 2016-09-26 18:01:18 +08:00
parent eddc632c29
commit 37d10e629e
No known key found for this signature in database
GPG Key ID: CAAD38AE2962619A
1 changed files with 27 additions and 15 deletions

View File

@ -5,22 +5,14 @@ category: Ruby
### Invoking tests ### Invoking tests
```sh
rake -T spec # List spec tasks rake -T spec # List spec tasks
rake spec # Run all rake spec # Run all
rake spec/models/mymodel_spec.rb rake spec/models/mymodel_spec.rb
rake spec/models/mymodel_spec.rb:27 rake spec/models/mymodel_spec.rb:27
```
### Spec helpers
module UserSpecHelper
def valid_user_attributes
{ :email => "joe@bloggs.com",
:username => "joebloggs",
:password => "abcdefg"}
end
end
## A tests ## A tests
@ -144,7 +136,7 @@ expect { thing.destroy }.to \
.by(-1) .by(-1)
``` ```
### Double ## Doubles
```rb ```rb
book = double('book') book = double('book')
@ -185,3 +177,23 @@ expect(die).to receive(:roll)
``` ```
https://relishapp.com/rspec/rspec-mocks/docs https://relishapp.com/rspec/rspec-mocks/docs
## Spec helpers
```rb
module UserSpecHelper
def valid_user_attributes
{ :email => "joe@bloggs.com",
:username => "joebloggs",
:password => "abcdefg"}
end
end
```
```rb
describe User do
include UserSpecHelper
...
end
```