File: require_option.feature

package info (click to toggle)
ruby-rspec 3.4.0c3e0m1s1-1~bpo8%2B1
  • links: PTS, VCS
  • area: main
  • in suites: jessie-backports
  • size: 6,124 kB
  • sloc: ruby: 59,418; sh: 1,405; makefile: 98
file content (45 lines) | stat: -rw-r--r-- 1,310 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
Feature: `--require` option

  Use the `--require` (or `-r`) option to specify a file to require before
  running specs.

  Scenario: Using the `--require` option
    Given a file named "logging_formatter.rb" with:
      """ruby
      require "rspec/core/formatters/base_text_formatter"
      require 'delegate'

      class LoggingFormatter < RSpec::Core::Formatters::BaseTextFormatter
        RSpec::Core::Formatters.register self, :dump_summary

        def initialize(output)
          super LoggingIO.new(output)
        end

        class LoggingIO < SimpleDelegator
          def initialize(output)
            @file = File.new('rspec.log', 'w')
            super
          end

          def puts(*args)
            [@file, __getobj__].each { |out| out.puts(*args) }
          end

          def close
            @file.close
          end
        end
      end
      """
    And a file named "spec/example_spec.rb" with:
      """ruby
      RSpec.describe "an embarassing situation" do
        it "happens to everyone" do
        end
      end
      """
    When I run `rspec --require ./logging_formatter.rb --format LoggingFormatter`
    Then the output should contain "1 example, 0 failures"
    And  the file "rspec.log" should contain "1 example, 0 failures"
    And  the exit status should be 0