Sha256: 8ce815ca27509a1c4594906ba00b6f118c55a88ff8383ad6386bc62880a4febb

Contents?: true

Size: 1.22 KB

Versions: 39

Compression:

Stored size: 1.22 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

39 entries across 39 versions & 8 rubygems

Version Path
vagrant-unbundled-2.2.7.0 vendor/bundle/ruby/2.4.0/gems/rspec-core-2.14.8/features/formatters/custom_formatter.feature
vagrant-unbundled-1.9.5.1 vendor/bundle/ruby/2.4.0/gems/rspec-core-2.14.8/features/formatters/custom_formatter.feature
vagrant-unbundled-1.9.1.1 vendor/bundle/ruby/2.4.0/gems/rspec-core-2.14.8/features/formatters/custom_formatter.feature
vagrant-unbundled-1.8.5.2 vendor/bundle/ruby/2.3.0/gems/rspec-core-2.14.8/features/formatters/custom_formatter.feature
vagrant-unbundled-1.8.5.1 vendor/bundle/ruby/2.3.0/gems/rspec-core-2.14.8/features/formatters/custom_formatter.feature
vagrant-unbundled-1.8.4.2 vendor/bundle/ruby/2.3.0/gems/rspec-core-2.14.8/features/formatters/custom_formatter.feature
vagrant-unbundled-1.8.4.1 vendor/bundle/ruby/2.3.0/gems/rspec-core-2.14.8/features/formatters/custom_formatter.feature
vagrant-unbundled-1.8.1.1 vendor/bundle/ruby/2.3.0/gems/rspec-core-2.14.8/features/formatters/custom_formatter.feature
vagrant-cloudstack-1.1.0 vendor/bundle/gems/rspec-core-2.14.8/features/formatters/custom_formatter.feature
rspec-core-2.99.2 features/formatters/custom_formatter.feature
dxruby_rp5-0.0.4 spec/vendor/rspec-core-2.14.7/features/formatters/custom_formatter.feature
rspec-core-2.99.1 features/formatters/custom_formatter.feature
rspec-core-2.99.0 features/formatters/custom_formatter.feature
rspec-core-2.99.0.rc1 features/formatters/custom_formatter.feature
rspec-core-2.14.8 features/formatters/custom_formatter.feature
rspec-core-2.99.0.beta2 features/formatters/custom_formatter.feature
mango-0.8.0 vendor/bundler/ruby/2.1.0/gems/rspec-core-2.14.7/features/formatters/custom_formatter.feature
mango-0.7.1 vendor/bundler/ruby/2.0.0/gems/rspec-core-2.14.7/features/formatters/custom_formatter.feature
dxruby_rp5-0.0.3 spec/vendor/rspec-core-2.14.7/features/formatters/custom_formatter.feature
tuktuk-rails-0.0.10 vendor/bundle/ruby/2.0.0/gems/rspec-core-2.14.7/features/formatters/custom_formatter.feature