2016-05-31 57 views
2

有沒有辦法讓rspec僅僅打印失敗示例的數量而沒有任何其他信息?只打印rspec的失敗示例的數量

我所要的輸出是這樣的:

Finished in 2.35 seconds (files took 7.33 seconds to load) 
1207 examples, 40 failures, 15 pending 

謝謝

+0

您可以通過'grep'傳遞rspec輸出。 –

回答

5

開箱RSpec中沒有您想要的輸出相匹配的格式。但是,可以編寫自己的格式化程序。

這裏的是什麼樣子的RSpec的3+

RSpec::Support.require_rspec_core "formatters/base_text_formatter" 

class SimpleFormatter < RSpec::Core::Formatters::BaseTextFormatter 
    RSpec::Core::Formatters.register self, :example_passed, :example_pending, :example_failed, :dump_pending, :dump_failures, :dump_summary 

    def example_passed(message) 
    # Do nothing 
    end 

    def example_pending(message) 
    # Do nothing 
    end 

    def example_failed(message) 
    # Do nothing 
    end 

    def dump_pending(message) 
    # Do nothing 
    end 

    def dump_failures(message) 
    end 

    def dump_summary(message) 
    colorizer = ::RSpec::Core::Formatters::ConsoleCodes 

    output.puts "\nFinished in #{message.formatted_duration} " \ 
     "(files took #{message.formatted_load_time} to load)\n" \ 
     "#{message.colorized_totals_line(colorizer)}\n" 
    end 
end 

# Example from RSpec Core - https://github.com/rspec/rspec-core/blob/bc1482605763cc16efa55c98b8da64a89c8ff5f9/lib/rspec/core/formatters/base_text_formatter.rb 

然後在命令行中運行rspec spec/ -r ./path/to/formatter -f SimpleFormatter

爲了避免不斷地鍵入了-r-f選項,你可以將它們放置在您的.rspec

--require ./path/to/formatter 
--format SimpleFormatter 

現在只是運行rspec spec/會自動使用我們剛剛創建的格式。

+0

謝謝你這是非常接近我想要的。使用您提供的格式化程序,除了一些失敗的示例外,屏幕上還會顯示其他一些文本。是否有可能完全擺脫它們,只顯示我在問題中提到的文字? – Lokesh

+0

你能粘貼你看到的額外文字嗎? – patkoperwas

+0

它是這裏:https://gist.github.com/lokeshh/b967188e661cf45a3242dd20991ebcd9 – Lokesh