File: zero_monkey_patching_mode.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 (106 lines) | stat: -rw-r--r-- 3,189 bytes parent folder | download | duplicates (6)
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
@allow-should-syntax
Feature: Zero monkey patching mode

  Use the `disable_monkey_patching!` configuration option to
  disable all monkey patching done by RSpec:

  - stops exposing DSL globally
  - disables `should` and `should_not` syntax for rspec-expectations
  - disables `stub`, `should_receive`, and `should_not_receive` syntax for
    rspec-mocks

  ```ruby
  RSpec.configure { |c| c.disable_monkey_patching! }
  ```

  Background:
    Given a file named "spec/example_describe_spec.rb" with:
      """ruby
      require 'spec_helper'

      describe "specs here" do
        it "passes" do
        end
      end
      """
    Given a file named "spec/example_should_spec.rb" with:
      """ruby
      require 'spec_helper'

      RSpec.describe "another specs here" do
        it "passes with monkey patched expectations" do
          x = 25
          x.should eq 25
          x.should_not be > 30
        end

        it "passes with monkey patched mocks" do
          x = double("thing")
          x.stub(:hello => [:world])
          x.should_receive(:count).and_return(4)
          x.should_not_receive(:all)
          (x.hello * x.count).should eq([:world, :world, :world, :world])
        end
      end
      """
    Given a file named "spec/example_expect_spec.rb" with:
      """ruby
      require 'spec_helper'

      RSpec.describe "specs here too" do
        it "passes in zero monkey patching mode" do
          x = double("thing")
          allow(x).to receive(:hello).and_return([:world])
          expect(x).to receive(:count).and_return(4)
          expect(x).not_to receive(:all)
          expect(x.hello * x.count).to eq([:world, :world, :world, :world])
        end

        it "passes in zero monkey patching mode" do
          x = 25
          expect(x).to eq(25)
          expect(x).not_to be > 30
        end
      end
      """

  Scenario: By default RSpec allows monkey patching
    Given a file named "spec/spec_helper.rb" with:
      """ruby
      # Empty spec_helper
      """
    When I run `rspec`
    Then the examples should all pass

  Scenario: Monkey patched methods are undefined with `disable_monkey_patching!`
    Given a file named "spec/spec_helper.rb" with:
      """ruby
      RSpec.configure do |config|
        config.disable_monkey_patching!
      end
      """
    When I run `rspec spec/example_should_spec.rb`
    Then the output should contain all of these:
      | undefined method `should'   |
      | unexpected message :stub    |
    When I run `rspec spec/example_describe_spec.rb`
    Then the output should contain "undefined method `describe'"

  Scenario: `allow` and `expect` syntax works with monkey patching
    Given a file named "spec/spec_helper.rb" with:
      """ruby
      # Empty spec_helper
      """
    When I run `rspec spec/example_expect_spec.rb`
    Then the examples should all pass

  Scenario: `allow` and `expect` syntax works without monkey patching
    Given a file named "spec/spec_helper.rb" with:
      """ruby
      RSpec.configure do |config|
        config.disable_monkey_patching!
      end
      """
    When I run `rspec spec/example_expect_spec.rb`
    Then the examples should all pass