RCov with RSpec-2

喜夏-厌秋 提交于 2019-12-21 04:34:35

问题


I'm working with a bit of a bleeding edge rails app. Rails 3, RSpec 2, Rspec-Rails2.

It seems as if RSpec2 doesn't include the spec:rcov rake task that RSpec 1 has. (at least it isn't there yet)

Has anyone had any luck running rcov with rspec 2, or writing their own rake task to make this work?


回答1:


Try passing in options to exclude the gem directory. Or since your running rails use the rails flag:

desc  "Run all specs with rcov"
RSpec::Core::RakeTask.new(:rcov => spec_prereq) do |t|
  t.rcov = true
  t.rcov_opts = %w{--rails --exclude osx\/objc,gems\/,spec\/,features\/}
end



回答2:


If you happen to be on Ruby 1.9x, I just got CoverMe (an rcov-ish lib that works under 1.9) working. Snappy and works out of the box w/ RSpec -- pretty much a plug-n-play setup. It just silently does your /coverage stuff every time you run rake:spec. Thought I'd mention it since I'm running 1.9.2preview3 on my bleeding edge stuff and it's possible you'll run into some 1.9 issues if you're using it.




回答3:


We use simplecov at work, and find it easy and effective. I find it to be a cleaner solution than modifying rspec source directly, especially when you have CI servers to worry about.




回答4:


Came up with this -

1) Open ~/.rvm/rubies//lib/ruby/gems//gems/rspec-rails-2.XXXXX/lib/rspec/rails/tasks/rspec.task in your favorite editor.

2) Add this rake task

desc  “Run all specs with rcov”
RSpec::Core::RakeTask.new(:rcov => spec_prereq) do |t|
  t.rcov = true
end

One outstanding problem. it runs rspec on every spec in both my rvm install folder and the project i'm in when i run the task. I can't figure out how to exclude all those rvm install tests. If anyone has an idea please let me know.



来源:https://stackoverflow.com/questions/3058676/rcov-with-rspec-2

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!