> vi Gemfile
:
gem 'rspec-rails'
规范的写法:
group :development, :test do
...
gem 'rspec-rails'
...
end
> bundler install
:
Using rspec-support 3.5.0
Using rspec-core 3.5.1
Using rspec-expectations 3.5.0
Using rspec-mocks 3.5.0
Using rspec-rails 3.5.1
> rails generate rspec:install
: create .rspec
create spec
create spec/spec_helper.rb
create spec/rails_helper.rb
生成rspec
文件夹.
> rake spec
:/Users/doctorq/.rvm/rubies/ruby-2.3.0/bin/ruby -I/Users/doctorq/.rvm/gems/ruby-2.3.0@global/gems/rspec-core-3.5.1/lib:/Users/doctorq/.rvm/gems/ruby-2.3.0@global/gems/rspec-support-3.5.0/lib /Users/doctorq/.rvm/gems/ruby-2.3.0@global/gems/rspec-core-3.5.1/exe/rspec --pattern spec/\*\*\{,/\*/\*\*\}/\*_spec.rb
No examples found.
Finished in 0.00038 seconds (files took 0.11575 seconds to load)
0 examples, 0 failures
执行用例。
> rails generate rspec:model article
create spec/models/article_spec.rb
创建了一个用例文件