File: deprecation_stream.feature

package info (click to toggle)
ruby-rspec 3.13.0c0e0m0s1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 6,856 kB
  • sloc: ruby: 70,868; sh: 1,423; makefile: 99
file content (87 lines) | stat: -rw-r--r-- 2,626 bytes parent folder | download
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
Feature: Custom deprecation stream

  Define a custom output stream for warning about deprecations (default
  `$stderr`).

  ```ruby
  RSpec.configure do |c|
    c.deprecation_stream = File.open('deprecations.txt', 'w')
  end
  ```

  or

  ```ruby
  RSpec.configure { |c| c.deprecation_stream = 'deprecations.txt' }
  ```

  or pass `--deprecation-out`

  Background:
    Given a file named "lib/foo.rb" with:
      """ruby
      class Foo
        def bar
          RSpec.deprecate "Foo#bar"
        end
      end
      """

  Scenario: Default - print deprecations to `$stderr`
    Given a file named "spec/example_spec.rb" with:
      """ruby
      require "foo"

      RSpec.describe "calling a deprecated method" do
        example { Foo.new.bar }
      end
      """
    When I run `rspec spec/example_spec.rb`
    Then the output should contain "Deprecation Warnings:\n\nFoo#bar is deprecated"

  Scenario: Configure using the path to a file
    Given a file named "spec/example_spec.rb" with:
      """ruby
      require "foo"

      RSpec.configure {|c| c.deprecation_stream = 'deprecations.txt' }

      RSpec.describe "calling a deprecated method" do
        example { Foo.new.bar }
      end
      """
    When I run `rspec spec/example_spec.rb`
    Then the output should not contain "Deprecation Warnings:"
    But the output should contain "1 deprecation logged to deprecations.txt"
    And the file "deprecations.txt" should contain "Foo#bar is deprecated"

  Scenario: Configure using a `File` object
    Given a file named "spec/example_spec.rb" with:
      """ruby
      require "foo"

      RSpec.configure do |c|
        c.deprecation_stream = File.open('deprecations.txt', 'w')
      end

      RSpec.describe "calling a deprecated method" do
        example { Foo.new.bar }
      end
      """
    When I run `rspec spec/example_spec.rb`
    Then the output should not contain "Deprecation Warnings:"
    But the output should contain "1 deprecation logged to deprecations.txt"
    And the file "deprecations.txt" should contain "Foo#bar is deprecated"

  Scenario: Configure using the CLI `--deprecation-out` option
    Given a file named "spec/example_spec.rb" with:
      """ruby
      require "foo"
      RSpec.describe "calling a deprecated method" do
        example { Foo.new.bar }
      end
      """
    When I run `rspec spec/example_spec.rb --deprecation-out deprecations.txt`
    Then the output should not contain "Deprecation Warnings:"
    But the output should contain "1 deprecation logged to deprecations.txt"
    And the file "deprecations.txt" should contain "Foo#bar is deprecated"