Update
This commit is contained in:
parent
eddc632c29
commit
37d10e629e
34
rspec.md
34
rspec.md
|
@ -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
|
||||||
|
```
|
||||||
|
|
Loading…
Reference in New Issue