开发者

Finding out how many examples are in a spec file

When I run a spec file (rspec spec/models/user_spec.rb) it prints something like 12 examples, 2 failures, 3 pending.

What's the fastest way to get the 12 examples part of it? (without running the spec)开发者_StackOverflow中文版


I have found a way to do this and involves the following snippet being add to spec/spec_helper.rb:

if ENV['COUNT']
  class RSpec::Core::Example
    def pending; true; end
  end
end

This way when I do:

COUNT=true rspec spec/controller/posts_controller_spec.rb

it assumes all the spec examples are pending and returns:

80 examples, 80 pending

Of course there is a problem. It doesn't account for all the really pending spec examples but I think it is a good enough solution.


Similar to vrinek's answer, but for RSpec 3, you can use:

[In path/to/skip_rspec.rb]

class RSpec::Core::ExampleGroup
  define_example_method :it,      :skip => true
  define_example_method :example, :skip => true
  define_example_method :specify, :skip => true
end

Command line:

$ rspec --require path/to/skip_rspec.rb

NB. If you have config.filter_run_excluding :skip in your spec_helper.rb, you will have to take it out.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜