Skip to content
This repository was archived by the owner on Nov 30, 2024. It is now read-only.

Commit 832adc1

Browse files
authored
Merge pull request #2803 from rspec/remove-monkey-patching
Scrape out monkey patching
2 parents 46292a3 + c8c5356 commit 832adc1

20 files changed

+48
-675
lines changed

Changelog.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
Breaking Changes:
44

55
* Ruby < 2.3 is no longer supported. (Phil Pirozhkov, #2787)
6+
* Extract `should` syntax (including the non-monkey-patching one liner). (Phil Pirozhkov, #2803)
7+
* Remove globally-exposed DSL (example and shared group methods
8+
in the root scope and on Module). (Phil Pirozhkov, #2803)
69

710
Enhancements:
811

features/configuration/enable_global_dsl.feature

Lines changed: 0 additions & 74 deletions
This file was deleted.

features/configuration/zero_monkey_patching_mode.feature

Lines changed: 0 additions & 106 deletions
This file was deleted.
Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,13 @@
1-
@oneliner-should
21
Feature: One-liner syntax
32

4-
RSpec supports a one-liner syntax for setting an expectation on the
5-
`subject`. RSpec will give the examples a doc string that is auto-
3+
RSpec supports a one-liner syntax, `is_expected`, for setting an expectation
4+
on the `subject`. RSpec will give the examples a doc string that is auto-
65
generated from the matcher used in the example. This is designed specifically
76
to help avoid duplication in situations where the doc string and the matcher
87
used in the example mirror each other exactly. When used excessively, it can
98
produce documentation output that does not read well or contribute to
10-
understanding the object you are describing.
11-
12-
This comes in two flavors:
13-
14-
* `is_expected` is defined simply as `expect(subject)` and is designed for
15-
when you are using rspec-expectations with its newer expect-based syntax.
16-
* `should` was designed back when rspec-expectations only had a should-based
17-
syntax. However, it continues to be available and work even if the
18-
`:should` syntax is disabled (since that merely removes `Object#should`
19-
but this is `RSpec::Core::ExampleGroup#should`).
9+
understanding the object you are describing. This syntax is a shorthand for
10+
`expect(subject)`.
2011

2112
Notes:
2213

@@ -29,13 +20,6 @@ Feature: One-liner syntax
2920
"""ruby
3021
RSpec.describe Array do
3122
describe "when first created" do
32-
# Rather than:
33-
# it "should be empty" do
34-
# subject.should be_empty
35-
# end
36-
37-
it { should be_empty }
38-
# or
3923
it { is_expected.to be_empty }
4024
end
4125
end
@@ -47,7 +31,6 @@ Feature: One-liner syntax
4731
Array
4832
when first created
4933
is expected to be empty
50-
is expected to be empty
5134
"""
5235

5336
Scenario: Explicit subject
@@ -56,8 +39,6 @@ Feature: One-liner syntax
5639
RSpec.describe Array do
5740
describe "with 3 items" do
5841
subject { [1,2,3] }
59-
it { should_not be_empty }
60-
# or
6142
it { is_expected.not_to be_empty }
6243
end
6344
end
@@ -69,5 +50,4 @@ Feature: One-liner syntax
6950
Array
7051
with 3 items
7152
is expected not to be empty
72-
is expected not to be empty
7353
"""
Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,10 @@
11
if defined?(Cucumber)
22
require 'shellwords'
3-
Before('~@allow-should-syntax', '~@with-clean-spec-opts') do
3+
Before('~@with-clean-spec-opts') do
44
set_environment_variable('SPEC_OPTS', "-r#{Shellwords.escape(__FILE__)}")
55
end
6-
7-
Before('@oneliner-should') do
8-
set_environment_variable('ALLOW_ONELINER_SHOULD', 'true')
9-
end
106
else
117
if ENV['REMOVE_OTHER_RSPEC_LIBS_FROM_LOAD_PATH']
128
$LOAD_PATH.reject! { |x| /rspec-mocks/ === x || /rspec-expectations/ === x }
139
end
14-
15-
module DisallowOneLinerShould
16-
def should(*)
17-
raise "one-liner should is not allowed"
18-
end
19-
20-
def should_not(*)
21-
raise "one-liner should_not is not allowed"
22-
end
23-
end
24-
25-
RSpec.configure do |rspec|
26-
rspec.disable_monkey_patching!
27-
rspec.include DisallowOneLinerShould unless ENV['ALLOW_ONELINER_SHOULD']
28-
end
2910
end

lib/rspec/core.rb

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,4 @@ def self.const_missing(name)
178178
require MODULES_TO_AUTOLOAD.fetch(name) { return super }
179179
::RSpec.const_get(name)
180180
end
181-
182-
Core::DSL.expose_globally!
183-
Core::SharedExampleGroup::TopLevelDSL.expose_globally!
184181
end

0 commit comments

Comments
 (0)