Sha256: 630c2f20c75f157aa28109c28a1760c0276dc29c01d3b7288acc6e3654107f53

Contents?: true

Size: 1.22 KB

Versions: 158

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:
      """
      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:
      """
      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

158 entries across 103 versions & 14 rubygems

Version Path
classiccms-0.7.5 vendor/bundle/gems/rspec-core-2.9.0/features/formatters/custom_formatter.feature
classiccms-0.7.5 vendor/bundle/gems/rspec-core-2.10.0/features/formatters/custom_formatter.feature
classiccms-0.7.4 vendor/bundle/gems/rspec-core-2.10.0/features/formatters/custom_formatter.feature
classiccms-0.7.4 vendor/bundle/gems/rspec-core-2.9.0/features/formatters/custom_formatter.feature
classiccms-0.7.3 vendor/bundle/gems/rspec-core-2.10.0/features/formatters/custom_formatter.feature
classiccms-0.7.3 vendor/bundle/gems/rspec-core-2.9.0/features/formatters/custom_formatter.feature
tnargav-1.3.3 vendor/bundle/ruby/1.9.1/gems/rspec-core-2.11.1/features/formatters/custom_formatter.feature
tnargav-1.2.3 vendor/bundle/ruby/1.9.1/gems/rspec-core-2.11.1/features/formatters/custom_formatter.feature
classiccms-0.7.2 vendor/bundle/gems/rspec-core-2.9.0/features/formatters/custom_formatter.feature
classiccms-0.7.2 vendor/bundle/gems/rspec-core-2.10.0/features/formatters/custom_formatter.feature
classiccms-0.7.1 vendor/bundle/gems/rspec-core-2.10.0/features/formatters/custom_formatter.feature
classiccms-0.7.1 vendor/bundle/gems/rspec-core-2.9.0/features/formatters/custom_formatter.feature
classiccms-0.7.0 vendor/bundle/gems/rspec-core-2.10.0/features/formatters/custom_formatter.feature
classiccms-0.7.0 vendor/bundle/gems/rspec-core-2.9.0/features/formatters/custom_formatter.feature
sunrise-cms-0.5.0.rc1 vendor/bundle/ruby/1.9.1/gems/rspec-core-2.10.1/features/formatters/custom_formatter.feature
classiccms-0.6.9 vendor/bundle/gems/rspec-core-2.10.0/features/formatters/custom_formatter.feature
classiccms-0.6.9 vendor/bundle/gems/rspec-core-2.9.0/features/formatters/custom_formatter.feature
classiccms-0.6.8 vendor/bundle/gems/rspec-core-2.10.0/features/formatters/custom_formatter.feature
classiccms-0.6.8 vendor/bundle/gems/rspec-core-2.9.0/features/formatters/custom_formatter.feature
classiccms-0.6.7 vendor/bundle/gems/rspec-core-2.10.0/features/formatters/custom_formatter.feature