当前位置: 首页 > 工具软件 > rspec-mocks > 使用案例 >

RoR利用RSpec测试项目

唐弘厚
2023-12-01

rspec-rails

安装依赖库

> 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

创建了一个用例文件

 类似资料: