Sha256: 4fc694256d54dac1bc63e170b29b154db4d52ead9b0d26fd7e33947661e5b0a7

Contents?: true

Size: 1.23 KB

Versions: 13

Compression:

Stored size: 1.23 KB

Contents

Feature: custom formatters

  RSpec ships with general purpose output formatters. You can tell RSpec which
  one to use using the [`--format` command line
  option]('../command_line/format_option').
  
  When RSpec's built-in output formatters don't, however, give you everything
  you need, you can write your own custom formatter and tell RSpec to use that
  one instead.  The simplest way is to subclass RSpec's `BaseTextFormatter`,
  and then override just the methods that you want to modify.

  Scenario: custom formatter
    Given a file named "custom_formatter.rb" with:
      """ruby
      require "rspec/core/formatters/base_text_formatter"

      class CustomFormatter < RSpec::Core::Formatters::BaseTextFormatter
        def initialize(output)
          super(output)
        end

        def example_started(proxy)
          output << "example: " << proxy.description
        end
      end
      """
    And a file named "example_spec.rb" with:
      """ruby
      describe "my group" do
        specify "my example" do
        end
      end
      """
    When I run `rspec example_spec.rb --require ./custom_formatter.rb --format CustomFormatter`
    Then the output should contain "example: my example"
    And  the exit status should be 0

Version data entries

13 entries across 13 versions & 6 rubygems

Version Path
judge-2.0.5 vendor/bundle/ruby/2.1.0/gems/rspec-core-2.13.0/features/formatters/custom_formatter.feature
sshp-0.0.2 vendor/ruby/1.9.1/gems/rspec-core-2.13.1/features/formatters/custom_formatter.feature
sshp-0.0.1 vendor/ruby/1.9.1/gems/rspec-core-2.13.1/features/formatters/custom_formatter.feature
sidekiq-statsd-0.1.1 vendor/ruby/1.9.1/gems/rspec-core-2.13.1/features/formatters/custom_formatter.feature
sidekiq-statsd-0.1.0 vendor/ruby/1.9.1/gems/rspec-core-2.13.1/features/formatters/custom_formatter.feature
vagrant-actionio-0.0.9 vendor/bundle/gems/rspec-core-2.13.0/features/formatters/custom_formatter.feature
rspec-core-2.13.1 features/formatters/custom_formatter.feature
rspec-core-2.13.0 features/formatters/custom_formatter.feature
remq-0.0.4 vendor/bundle/gems/rspec-core-2.12.2/features/formatters/custom_formatter.feature
remq-0.0.3 vendor/bundle/gems/rspec-core-2.12.2/features/formatters/custom_formatter.feature
rspec-core-2.12.2 features/formatters/custom_formatter.feature
rspec-core-2.12.1 features/formatters/custom_formatter.feature
rspec-core-2.12.0 features/formatters/custom_formatter.feature