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

Commit bc8f7c1

Browse files
committed
Remove non-monkey-patching should syntax, too
1 parent cff54e9 commit bc8f7c1

File tree

7 files changed

+20
-76
lines changed

7 files changed

+20
-76
lines changed

Changelog.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
Breaking Changes:
44

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

810
Enhancements:
911

features/subject/one_liner_syntax.feature

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,7 @@ Feature: One-liner syntax
88
produce documentation output that does not read well or contribute to
99
understanding the object you are describing.
1010

11-
This comes in two flavors:
12-
13-
* `is_expected` is defined simply as `expect(subject)` and is designed for
14-
when you are using rspec-expectations with its newer expect-based syntax.
15-
* `should` was designed back when rspec-expectations only had a should-based
16-
syntax.
11+
`is_expected` is a shorthand syntax for `expect(subject)`.
1712

1813
Notes:
1914

@@ -26,8 +21,6 @@ Feature: One-liner syntax
2621
"""ruby
2722
RSpec.describe Array do
2823
describe "when first created" do
29-
it { should be_empty }
30-
# or
3124
it { is_expected.to be_empty }
3225
end
3326
end
@@ -48,8 +41,6 @@ Feature: One-liner syntax
4841
RSpec.describe Array do
4942
describe "with 3 items" do
5043
subject { [1,2,3] }
51-
it { should_not be_empty }
52-
# or
5344
it { is_expected.not_to be_empty }
5445
end
5546
end

lib/rspec/core/memoized_helpers.rb

Lines changed: 4 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ module MemoizedHelpers
1212
#
1313
# RSpec.describe Widget do
1414
# it { is_expected.to validate_presence_of(:name) }
15-
# # or
16-
# it { should validate_presence_of(:name) }
1715
# end
1816
#
1917
# While the examples below demonstrate how to use `subject`
@@ -25,32 +23,28 @@ module MemoizedHelpers
2523
# # Explicit declaration of subject.
2624
# RSpec.describe Person do
2725
# subject { Person.new(:birthdate => 19.years.ago) }
28-
# it "should be eligible to vote" do
29-
# should be_eligible_to_vote
26+
# it "is eligible to vote" do
27+
# is_expected.to be_eligible_to_vote
3028
# end
3129
# end
3230
#
3331
# # Implicit subject => { Person.new }.
3432
# RSpec.describe Person do
35-
# it "should be eligible to vote" do
36-
# should be_eligible_to_vote
33+
# it "is eligible to vote" do
34+
# is_expected.to be_eligible_to_vote
3735
# end
3836
# end
3937
#
4038
# # One-liner syntax - expectation is set on the subject.
4139
# RSpec.describe Person do
4240
# it { is_expected.to be_eligible_to_vote }
43-
# # or
44-
# it { should be_eligible_to_vote }
4541
# end
4642
#
4743
# @note Because `subject` is designed to create state that is reset
4844
# between each example, and `before(:context)` is designed to setup
4945
# state that is shared across _all_ examples in an example group,
5046
# `subject` is _not_ intended to be used in a `before(:context)` hook.
5147
#
52-
# @see #should
53-
# @see #should_not
5448
# @see #is_expected
5549
def subject
5650
__memoized.fetch_or_store(:subject) do
@@ -59,45 +53,6 @@ def subject
5953
end
6054
end
6155

62-
# When `should` is called with no explicit receiver, the call is
63-
# delegated to the object returned by `subject`. Combined with an
64-
# implicit subject this supports very concise expressions.
65-
#
66-
# @example
67-
#
68-
# RSpec.describe Person do
69-
# it { should be_eligible_to_vote }
70-
# end
71-
#
72-
# @see #subject
73-
# @see #is_expected
74-
#
75-
# @note This only works if you are using rspec-expectations.
76-
# @note If you are using RSpec's newer expect-based syntax you may
77-
# want to use `is_expected.to` instead of `should`.
78-
def should(matcher=nil, message=nil)
79-
RSpec::Expectations::PositiveExpectationHandler.handle_matcher(subject, matcher, message)
80-
end
81-
82-
# Just like `should`, `should_not` delegates to the subject (implicit or
83-
# explicit) of the example group.
84-
#
85-
# @example
86-
#
87-
# RSpec.describe Person do
88-
# it { should_not be_eligible_to_vote }
89-
# end
90-
#
91-
# @see #subject
92-
# @see #is_expected
93-
#
94-
# @note This only works if you are using rspec-expectations.
95-
# @note If you are using RSpec's newer expect-based syntax you may
96-
# want to use `is_expected.to_not` instead of `should_not`.
97-
def should_not(matcher=nil, message=nil)
98-
RSpec::Expectations::NegativeExpectationHandler.handle_matcher(subject, matcher, message)
99-
end
100-
10156
# Wraps the `subject` in `expect` to make it the target of an expectation.
10257
# Designed to read nicely for one-liners.
10358
#
@@ -109,8 +64,6 @@ def should_not(matcher=nil, message=nil)
10964
# end
11065
#
11166
# @see #subject
112-
# @see #should
113-
# @see #should_not
11467
#
11568
# @note This only works if you are using rspec-expectations.
11669
def is_expected
@@ -410,8 +363,6 @@ def let!(name, &block)
410363
# end
411364
# end
412365
#
413-
# @see MemoizedHelpers#should
414-
# @see MemoizedHelpers#should_not
415366
# @see MemoizedHelpers#is_expected
416367
def subject(name=nil, &block)
417368
if name

spec/rspec/core/example_group_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1873,7 +1873,7 @@ def foo; end
18731873
# for users. RSpec internals should not add methods here, though.
18741874
expect(rspec_core_methods.map(&:to_sym)).to contain_exactly(
18751875
:described_class, :subject,
1876-
:is_expected, :should, :should_not,
1876+
:is_expected,
18771877
:pending, :skip,
18781878
:setup_mocks_for_rspec, :teardown_mocks_for_rspec, :verify_mocks_for_rspec
18791879
)

spec/rspec/core/memoized_helpers_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ def working_with?(double)
107107
end.new 1
108108
end
109109

110-
it { should be_working_with double(:value => 10) }
110+
it { is_expected.to be_working_with double(:value => 10) }
111111
end
112112

113113
[false, nil].each do |falsy_value|
@@ -331,9 +331,9 @@ def should_raise_not_supported_error(&block)
331331
def ok?; true; end
332332
def not_ok?; false; end
333333

334-
it { should eq(self) }
335-
it { should be_ok }
336-
it { should_not be_not_ok }
334+
it { is_expected.to eq(self) }
335+
it { is_expected.to be_ok }
336+
it { is_expected.not_to be_not_ok }
337337
end
338338

339339
expect(group.run).to be true

spec/rspec/core/metadata_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ module Core
2626
expect([nil, "."]).to include(value)
2727
end
2828

29-
it 'should not transform directories beginning with the same prefix' do
29+
it 'does not transform directories beginning with the same prefix' do
3030
#E.g. /foo/bar_baz is not relative to /foo/bar !!
3131

3232
similar_directory = "#{File.expand_path(".")}_similar"

spec/rspec/core/runner_spec.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -177,15 +177,15 @@ def interrupt
177177
instance_double(::DRb::DRbServer, :uri => "druby://127.0.0.1:0000/", :alive? => true)
178178
end
179179

180-
it { should be_truthy }
180+
it { is_expected.to be_truthy }
181181
end
182182

183183
context "when drb server is started with localhost" do
184184
let(:drb_server) do
185185
instance_double(::DRb::DRbServer, :uri => "druby://localhost:0000/", :alive? => true)
186186
end
187187

188-
it { should be_truthy }
188+
it { is_expected.to be_truthy }
189189
end
190190

191191
context "when drb server is started with another local ip address" do
@@ -197,15 +197,15 @@ def interrupt
197197
allow(::IPSocket).to receive(:getaddress).and_return("192.168.0.1")
198198
end
199199

200-
it { should be_truthy }
200+
it { is_expected.to be_truthy }
201201
end
202202

203203
context "when drb server is started with 127.0.0.1 but not alive" do
204204
let(:drb_server) do
205205
instance_double(::DRb::DRbServer, :uri => "druby://127.0.0.1:0000/", :alive? => false)
206206
end
207207

208-
it { should be_falsey }
208+
it { is_expected.to be_falsey }
209209
end
210210

211211
context "when IPSocket cannot resolve the current hostname" do
@@ -219,15 +219,15 @@ def interrupt
219219
)
220220
end
221221

222-
it { should be_falsey }
222+
it { is_expected.to be_falsey }
223223
end
224224

225225
context "when no drb server is running" do
226226
let(:drb_server) do
227227
raise ::DRb::DRbServerNotFound
228228
end
229229

230-
it { should be_falsey }
230+
it { is_expected.to be_falsey }
231231
end
232232
end
233233

0 commit comments

Comments
 (0)