![](/img/trans.png)
[英]Which one does rspec run first? spec_helper.rb or db:test:prepare
[英]what changes to be made in spec_helper.rb to run my specs?
我想将我的spec文件夹重组为以下内容:
-spec
-unit
-Controller
-example.rb
-model
-Integration
-controller
-model
为了在/spec/unit/controller/example.rb文件中运行规格,我必须在spec_helper.rb中进行哪些更改?
是否有人曾尝试根据其较高的水平(例如单元/集成等)来重组规范?
您无需在spec_helper.rb
进行任何更改。 但是,您确实需要将example.rb
更改为example_spec.rb
这是实现此目的的相关代码行,位于
/gems/rspec-rails-2.14.1/lib/rspec/rails/tasks/rspec.rake
:namespace :spec do types = begin dirs = Dir['./spec/**/*_spec.rb']. map { |f| g=f.sub(/^\\.\\/(spec\\/\\w+)\\/.*/, '\\\\1') ; puts ">>> Found #{g}."; g }. uniq. select { |f| File.directory?(f) } Hash[dirs.map { |d| [d.split('/').last, d] }] end
因此,_spec.rb之前的文件名中的所有文本都是约定-它不会改变Rails处理文件的方式。
要仅运行某些规范,可以在命令行中通过标签或文本过滤它们,或者简单地通过提供所需的根目录即可:
rspec . --example controller # only runs tests which have the word 'controller' in them
rsepc . --tag model # only runs tests which are tagged as 'model' => true
rspec ./spec/unit # only runs specs which are under ./spec/unit
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.