Rspec Practices 1
U should add gem rspec-rails
in ur project’s Gemfile, then bundle.
Then, u need run command rails g rspec:install
.
When u use rails commands, likes rails g model User xx:xx
. It will help u to create spec/models/user_spec.rb
file.
Yes, Rspec will check _spec.rb
file as test file.
Give me some codes:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
|
and then, u can use rspec
to test all _spec
files,
or u can only test user_spec.rb
file with rspec spec/models/user_spec.rb
command.
if no error, u can get
1
|
|
It is not a good view. We just not work for testing, but say something to others.
U can run rspec --format doc
, will get result:
1 2 3 4 5 6 7 |
|