新手问题 rails project 文件夹下运行 rspec spec 和 rake spec 到底有什么区别

dfang · 2012年09月08日 · 最后由 dfang 回复于 2012年09月09日 · 8518 次阅读

RT,貌似有区别的、 现象 1:某个项目下:rake spec 和 rspec spec 都能运行,但后者要比前者快 现象 2:另个项目下:rake spec 直接输出是空的,啥效果都没有,rspec spec 有消息输出

这两个到底有什么区别啊?大家用的是哪一种啊?

Gemfile 中: ‘rspec_rails’ ‘factory_girl_rails’ ...........

rake 执行: 查看 rake 中所有的 RSpec 任务: rake --tasks spec

rake spec # Run all specs in spec directory (excluding plugin specs) rake spec:controllers # Run the code examples in spec/controllers rake spec:helpers # Run the code examples in spec/helpers rake spec:lib # Run the code examples in spec/lib rake spec:mailers # Run the code examples in spec/mailers rake spec:models # Run the code examples in spec/models rake spec:rcov # Run all specs with rcov rake spec:requests # Run the code examples in spec/requests rake spec:routing # Run the code examples in spec/routing rake spec:views # Run the code examples in spec/views

rake spec #执行所有测试 rspec spec/models/mymodel_spec.rb # 只测试一个文件

rake spec 既然是执行所有测试,为什么会出现现象 2 呢

@pobing 有个项目下 rake -T spec 是空的,这是怎么回事? rspec,rspec-rails 的版本都是 2.10 的

现象 1 你是自己手动 创建的 rspec 测试文件吧?一般工程创建后,执行 rails generate rspec:install,以后每创建一个 scaffold 就会自动生成其对应的 controller,modle,view 的测试文件框架http://pobing.iteye.com/blog/1286199

不是,肯定是用了 rails g rspec:install 的,因为都有 spec 目录和 spec_helper 等,我没有去建他

我都知道原因了,rspec 也可以测试文件夹的 比如 rspec spec/models 运行 spec/models 文件夹下的所有 spec,rake spec 应该只是用 rake 任务包装了一下,当然了也包括一些测试环境的准备工作,现象 2 是因为 gem‘rspec-rails’没有放到 development group 里,这个项目不是我搭的,看看 gemfile 才想到的

需要 登录 后方可回复, 如果你还没有账号请 注册新账号