/vendor/bundle/jruby/2.1/gems/rspec-core-2.14.8/features/formatters/custom_formatter.feature

https://github.com/delowong/logstash · Gherkin Specification · 36 lines · 31 code · 5 blank · 0 comment · 3 complexity · 829ab76bbd08407c8df2ebe9787f6f46 MD5 · raw file

  1. Feature: custom formatters
  2. RSpec ships with general purpose output formatters. You can tell RSpec which
  3. one to use using the [`--format` command line
  4. option]('../command_line/format_option').
  5. When RSpec's built-in output formatters don't, however, give you everything
  6. you need, you can write your own custom formatter and tell RSpec to use that
  7. one instead. The simplest way is to subclass RSpec's `BaseTextFormatter`,
  8. and then override just the methods that you want to modify.
  9. Scenario: custom formatter
  10. Given a file named "custom_formatter.rb" with:
  11. """ruby
  12. require "rspec/core/formatters/base_text_formatter"
  13. class CustomFormatter < RSpec::Core::Formatters::BaseTextFormatter
  14. def initialize(output)
  15. super(output)
  16. end
  17. def example_started(proxy)
  18. output << "example: " << proxy.description
  19. end
  20. end
  21. """
  22. And a file named "example_spec.rb" with:
  23. """ruby
  24. describe "my group" do
  25. specify "my example" do
  26. end
  27. end
  28. """
  29. When I run `rspec example_spec.rb --require ./custom_formatter.rb --format CustomFormatter`
  30. Then the output should contain "example: my example"
  31. And the exit status should be 0