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

Commit 7cec8f4

Browse files
committed
Remove it_should_behave_like
1 parent f501c66 commit 7cec8f4

File tree

8 files changed

+32
-37
lines changed

8 files changed

+32
-37
lines changed

Changelog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ Breaking Changes:
1818
* Remove deprecated Hash-like behavior from example
1919
execution result. (Phil Pirozhkov, #2862)
2020
* Remove deprecated `color` configuration option. (Phil Pirozhkov, #2864)
21+
* Remove `it_should_behave_like` nested shared group method and
22+
`alias_it_should_behave_like_to` configuration option. (Phil Pirozhkov, #2864)
2123

2224
Enhancements:
2325

features/example_groups/shared_examples.feature

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ Feature: shared examples
1010
```ruby
1111
include_examples "name" # include the examples in the current context
1212
it_behaves_like "name" # include the examples in a nested context
13-
it_should_behave_like "name" # include the examples in a nested context
1413
matching metadata # include the examples in the current context
1514
```
1615

@@ -206,34 +205,34 @@ Feature: shared examples
206205
207206
RSpec.describe Array, "with 3 items" do
208207
subject { [1, 2, 3] }
209-
it_should_behave_like "a measurable object", 3, [:size, :length]
208+
it_behaves_like "a measurable object", 3, [:size, :length]
210209
end
211210
212211
RSpec.describe String, "of 6 characters" do
213212
subject { "FooBar" }
214-
it_should_behave_like "a measurable object", 6, [:size, :length]
213+
it_behaves_like "a measurable object", 6, [:size, :length]
215214
end
216215
"""
217216
When I run `rspec shared_example_group_params_spec.rb --format documentation`
218217
Then the examples should all pass
219218
And the output should contain:
220219
"""
221220
Array with 3 items
222-
it should behave like a measurable object
221+
behaves like a measurable object
223222
should return 3 from #size
224223
should return 3 from #length
225224
226225
String of 6 characters
227-
it should behave like a measurable object
226+
behaves like a measurable object
228227
should return 6 from #size
229228
should return 6 from #length
230229
"""
231230

232-
Scenario: Aliasing `it_should_behave_like` to `it_has_behavior`
231+
Scenario: Aliasing `it_behaves_like` to `it_has_behavior`
233232
Given a file named "shared_example_group_spec.rb" with:
234233
"""ruby
235234
RSpec.configure do |c|
236-
c.alias_it_should_behave_like_to :it_has_behavior, 'has behavior:'
235+
c.alias_it_behaves_like_to :it_has_behavior, 'has behavior:'
237236
end
238237
239238
RSpec.shared_examples 'sortability' do

lib/rspec/core/configuration.rb

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1079,8 +1079,8 @@ def alias_example_group_to(new_name, *args)
10791079
RSpec::Core::ExampleGroup.define_example_group_method(new_name, extra_options)
10801080
end
10811081

1082-
# Define an alias for it_should_behave_like that allows different
1083-
# language (like "it_has_behavior" or "it_behaves_like") to be
1082+
# Define an alias for it_behaves_like that allows different
1083+
# language (like "it_has_behavior" or "it_is_able_to") to be
10841084
# employed when including shared examples.
10851085
#
10861086
# @example
@@ -1102,13 +1102,10 @@ def alias_example_group_to(new_name, *args)
11021102
# # ...sortability examples here
11031103
#
11041104
# @note Use with caution. This extends the language used in your
1105-
# specs, but does not add any additional documentation. We use this
1106-
# in RSpec to define `it_should_behave_like` (for backward
1107-
# compatibility), but we also add docs for that method.
1105+
# specs, but does not add any additional documentation.
11081106
def alias_it_behaves_like_to(new_name, report_label='')
11091107
RSpec::Core::ExampleGroup.define_nested_shared_group_method(new_name, report_label)
11101108
end
1111-
alias_method :alias_it_should_behave_like_to, :alias_it_behaves_like_to
11121109

11131110
# Adds key/value pairs to the `inclusion_filter`. If `args`
11141111
# includes any symbols that are not part of the hash, each symbol

lib/rspec/core/example_group.rb

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ def self.define_example_group_method(name, metadata={})
314314
# @!scope class
315315
#
316316
# @see SharedExampleGroup
317-
def self.define_nested_shared_group_method(new_name, report_label="it should behave like")
317+
def self.define_nested_shared_group_method(new_name, report_label="behaves like")
318318
idempotently_define_singleton_method(new_name) do |name, *args, &customization_block|
319319
# Pass :caller so the :location metadata is set properly.
320320
# Otherwise, it'll be set to the next line because that's
@@ -329,10 +329,7 @@ def self.define_nested_shared_group_method(new_name, report_label="it should beh
329329

330330
# Generates a nested example group and includes the shared content
331331
# mapped to `name` in the nested group.
332-
define_nested_shared_group_method :it_behaves_like, "behaves like"
333-
# Generates a nested example group and includes the shared content
334-
# mapped to `name` in the nested group.
335-
define_nested_shared_group_method :it_should_behave_like
332+
define_nested_shared_group_method :it_behaves_like
336333

337334
# Includes shared content mapped to `name` directly in the group in which
338335
# it is declared, as opposed to `it_behaves_like`, which creates a nested

spec/rspec/core/example_group_spec.rb

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1723,19 +1723,19 @@ def foo; "bar"; end
17231723
end
17241724
end
17251725

1726-
describe "#it_should_behave_like" do
1726+
describe "#it_behaves_like" do
17271727
it "creates a nested group" do
17281728
group = RSpec.describe('fake group')
17291729
group.shared_examples_for("thing") {}
1730-
group.it_should_behave_like("thing")
1730+
group.it_behaves_like("thing")
17311731
expect(group.children.count).to eq(1)
17321732
end
17331733

17341734
it "creates a nested group for a class" do
17351735
klass = Class.new
17361736
group = RSpec.describe('fake group')
17371737
group.shared_examples_for(klass) {}
1738-
group.it_should_behave_like(klass)
1738+
group.it_behaves_like(klass)
17391739
expect(group.children.count).to eq(1)
17401740
end
17411741

@@ -1744,7 +1744,7 @@ def foo; "bar"; end
17441744
group.shared_examples_for("thing") do
17451745
it("does something")
17461746
end
1747-
shared_group = group.it_should_behave_like("thing")
1747+
shared_group = group.it_behaves_like("thing")
17481748
expect(shared_group.examples.count).to eq(1)
17491749
end
17501750

@@ -1753,7 +1753,7 @@ def foo; "bar"; end
17531753
group.shared_examples_for("thing") do
17541754
def foo; end
17551755
end
1756-
shared_group = group.it_should_behave_like("thing")
1756+
shared_group = group.it_behaves_like("thing")
17571757
expect(shared_group.public_instance_methods.map{|m| m.to_s}).to include("foo")
17581758
end
17591759

@@ -1762,7 +1762,7 @@ def foo; end
17621762
group.shared_examples_for("thing") do
17631763
def self.foo; end
17641764
end
1765-
shared_group = group.it_should_behave_like("thing")
1765+
shared_group = group.it_behaves_like("thing")
17661766
expect(shared_group.methods.map{|m| m.to_s}).to include("foo")
17671767
end
17681768

@@ -1777,7 +1777,7 @@ def self.foo; end
17771777
end
17781778
end
17791779

1780-
it_should_behave_like "thing", :value1, :value2
1780+
it_behaves_like "thing", :value1, :value2
17811781
end
17821782

17831783
group.run
@@ -1790,15 +1790,15 @@ def self.foo; end
17901790
group.shared_examples_for("thing") do |param1|
17911791
def foo; end
17921792
end
1793-
shared_group = group.it_should_behave_like("thing", :a)
1793+
shared_group = group.it_behaves_like("thing", :a)
17941794
expect(shared_group.public_instance_methods.map{|m| m.to_s}).to include("foo")
17951795
end
17961796

17971797
it "evals the shared example group only once" do
17981798
eval_count = 0
17991799
group = RSpec.describe('fake group')
18001800
group.shared_examples_for("thing") { |p| eval_count += 1 }
1801-
group.it_should_behave_like("thing", :a)
1801+
group.it_behaves_like("thing", :a)
18021802
expect(eval_count).to eq(1)
18031803
end
18041804

@@ -1811,7 +1811,7 @@ def foo; end
18111811
scopes << self.class
18121812
end
18131813
end
1814-
it_should_behave_like "thing" do
1814+
it_behaves_like "thing" do
18151815
it("gets run in the same nested group") do
18161816
scopes << self.class
18171817
end
@@ -1826,7 +1826,7 @@ def foo; end
18261826
it "raises a helpful error message when shared context is not found" do
18271827
expect do
18281828
RSpec.describe do
1829-
it_should_behave_like "shared stuff"
1829+
it_behaves_like "shared stuff"
18301830
end
18311831
end.to raise_error(ArgumentError,%q|Could not find shared examples "shared stuff"|)
18321832
end
@@ -1835,7 +1835,7 @@ def foo; end
18351835
expect {
18361836
RSpec.describe do
18371837
shared_examples_for("stuff") { }
1838-
it_should_behave_like "stuff"
1838+
it_behaves_like "stuff"
18391839
end
18401840
}.to avoid_changing(RSpec::Support, :thread_local_data)
18411841
end
@@ -1844,7 +1844,7 @@ def foo; end
18441844
expect {
18451845
RSpec.describe do
18461846
shared_examples_for("stuff") { }
1847-
it_should_behave_like "stuff" do
1847+
it_behaves_like "stuff" do
18481848
raise "boom"
18491849
end
18501850
end

spec/rspec/core/formatters/base_text_formatter_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ def run_all_and_dump_failures
212212
end
213213
end
214214

215-
%w[ include_examples it_should_behave_like ].each do |inclusion_method|
215+
%w[ include_examples it_behaves_like ].each do |inclusion_method|
216216
context "for #shared_examples included using #{inclusion_method}" do
217217
it 'outputs the name and location' do
218218
group.shared_examples 'foo bar' do

spec/rspec/core/formatters/profile_formatter_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def profile *groups
4646
end)
4747
end
4848

49-
it_should_behave_like "profiles examples"
49+
it_behaves_like "profiles examples"
5050

5151
it "doesn't profile a single example group" do
5252
expect(formatter_output.string).not_to match(/slowest example groups/)
@@ -72,7 +72,7 @@ def profile *groups
7272
profile group1, group2
7373
end
7474

75-
it_should_behave_like "profiles examples"
75+
it_behaves_like "profiles examples"
7676

7777
it "prints the slowest example groups" do
7878
expect(formatter_output.string).to match(/slowest example groups/)

spec/rspec/core/memoized_helpers_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -615,17 +615,17 @@ def hello_message; "Hello from module"; end
615615

616616
describe Object do
617617
context 'with implicit subject' do
618-
it_should_behave_like 'a subject'
618+
it_behaves_like 'a subject'
619619
end
620620

621621
context 'with explicit subject' do
622622
subject { Object.new }
623-
it_should_behave_like 'a subject'
623+
it_behaves_like 'a subject'
624624
end
625625

626626
context 'with a constant subject'do
627627
subject { 123 }
628-
it_should_behave_like 'a subject'
628+
it_behaves_like 'a subject'
629629
end
630630
end
631631
end

0 commit comments

Comments
 (0)