Skip to content

Commit c5f6ce6

Browse files
authored
Use correct terminology for RSpec matchers (#220)
There are four kinds of matchers which are referred to within the RSpec source code: - **(Built-in) matchers:** Also simply shortened to "matcher", these are instances of RSpec::Matchers::BuiltIn::Base and are created via convenience methods which are available in all RSpec example groups (e.g. `eq` for RSpec::Matchers::BuiltIn::Eq, `include` for RSpec::Matchers::BuiltIn::Include, etc.). - **Custom matchers:** These are matchers that end users can create via `RSpec::Matchers.define`. They are not instances of RSpec::Matchers::BuiltIn::Base, but rather RSpec::Matchers::DSL::Matcher. - **Aliased matchers:** These are matchers which act just like other matchers but are created via a different method name and hence have a different description to match. For instance, `include` has four aliases: `a_collection_including`, `a_string_including`, `a_hash_including`, and `including`. The objects that such methods return are actually an instance of RSpec::Matchers::AliasedMatcher and wrap the original matcher object. - **Describable matchers:** These are matchers which satisfy a minimal matcher interface including `description`, so they effectively match both built-in and custom matchers. More formally, they are objects which pass the check that `RSpec::Matchers.is_a_describable_matcher?` makes: that is, they are either instances of RSpec::Matchers::BuiltIn::Base, or they respond to `matches?` and `description` and either `failure_message` or `failure_message_when_negated`. So far in the SuperDiff code we have been using the phrase "fuzzy object" to describe an aliased matcher. That was derived from `rspec-support`'s FuzzyMatcher class, which compares two objects with the consideration that either could be an RSpec matcher object. But that's not an official term, and so it could be confusing if we use that. This commit corrects this term to simply "RSpec matcher object", except in the case where it was being used to test whether a value was an aliased matcher, in which case that term is now used.
1 parent 773da4a commit c5f6ce6

7 files changed

+22
-22
lines changed

lib/super_diff/rspec.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def self.configuration
2020
end
2121

2222
def self.a_hash_including_something?(value)
23-
fuzzy_object?(value) && value.respond_to?(:expecteds) &&
23+
aliased_matcher?(value) && value.respond_to?(:expecteds) &&
2424
value.expecteds.one? && value.expecteds.first.is_a?(::Hash)
2525
end
2626

@@ -31,7 +31,7 @@ def self.hash_including_something?(value)
3131
end
3232

3333
def self.a_collection_including_something?(value)
34-
fuzzy_object?(value) && value.respond_to?(:expecteds) &&
34+
aliased_matcher?(value) && value.respond_to?(:expecteds) &&
3535
!(value.expecteds.one? && value.expecteds.first.is_a?(::Hash))
3636
end
3737

@@ -40,17 +40,17 @@ def self.array_including_something?(value)
4040
end
4141

4242
def self.an_object_having_some_attributes?(value)
43-
fuzzy_object?(value) &&
43+
aliased_matcher?(value) &&
4444
value.base_matcher.is_a?(::RSpec::Matchers::BuiltIn::HaveAttributes)
4545
end
4646

4747
def self.a_collection_containing_exactly_something?(value)
48-
fuzzy_object?(value) &&
48+
aliased_matcher?(value) &&
4949
value.base_matcher.is_a?(::RSpec::Matchers::BuiltIn::ContainExactly)
5050
end
5151

5252
def self.a_kind_of_something?(value)
53-
fuzzy_object?(value) &&
53+
aliased_matcher?(value) &&
5454
value.base_matcher.is_a?(::RSpec::Matchers::BuiltIn::BeAKindOf)
5555
end
5656

@@ -61,7 +61,7 @@ def self.kind_of_something?(value)
6161
end
6262

6363
def self.an_instance_of_something?(value)
64-
fuzzy_object?(value) &&
64+
aliased_matcher?(value) &&
6565
value.base_matcher.is_a?(::RSpec::Matchers::BuiltIn::BeAnInstanceOf)
6666
end
6767

@@ -72,11 +72,11 @@ def self.instance_of_something?(value)
7272
end
7373

7474
def self.a_value_within_something?(value)
75-
fuzzy_object?(value) &&
75+
aliased_matcher?(value) &&
7676
value.base_matcher.is_a?(::RSpec::Matchers::BuiltIn::BeWithin)
7777
end
7878

79-
def self.fuzzy_object?(value)
79+
def self.aliased_matcher?(value)
8080
value.is_a?(::RSpec::Matchers::AliasedMatcher)
8181
end
8282

spec/integration/rspec/contain_exactly_matcher_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@
308308
end
309309
end
310310

311-
context "and some of them are fuzzy objects" do
311+
context "and some of them are RSpec matchers" do
312312
it "produces the correct failure message" do
313313
as_both_colored_and_uncolored do |color_enabled|
314314
snippet = <<~TEST.strip

spec/integration/rspec/have_attributes_matcher_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -347,8 +347,8 @@
347347
end
348348
end
349349

350-
# TODO: Add as many fuzzy matchers as we can here
351-
context "that contains fuzzy matcher objects instead of an object" do
350+
# TODO: Add as many RSpec matchers as we can here
351+
context "that contains RSpec matchers" do
352352
it "displays the hash correctly" do
353353
as_both_colored_and_uncolored do |color_enabled|
354354
snippet = <<~TEST.strip

spec/integration/rspec/match_array_matcher_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@
310310
end
311311
end
312312

313-
context "and some of them are fuzzy objects" do
313+
context "and some of them are RSpec matchers" do
314314
it "produces the correct failure message" do
315315
as_both_colored_and_uncolored do |color_enabled|
316316
snippet = <<~TEST.strip

spec/integration/rspec/raise_error_matcher_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,7 +1006,7 @@
10061006
end
10071007
end
10081008

1009-
context "given a simple RSpec fuzzy object" do
1009+
context "given a simple RSpec matcher" do
10101010
context "when used in the positive" do
10111011
context "when the block raises a different error than what is given" do
10121012
context "when the expected error and/or actual message is short" do
@@ -1184,7 +1184,7 @@
11841184
end
11851185
end
11861186

1187-
context "given only a simple RSpec fuzzy object and string message" do
1187+
context "given only a simple RSpec matcher and string message" do
11881188
context "when used in the positive" do
11891189
context "when the block raises a different error than what is given" do
11901190
it "produces the correct failure message" do
@@ -1260,7 +1260,7 @@
12601260
end
12611261
end
12621262

1263-
context "given only a simple RSpec fuzzy object and regexp message" do
1263+
context "given only a simple RSpec matcher and regexp message" do
12641264
context "when used in the positive" do
12651265
context "when the block raises a different error than what is given" do
12661266
it "produces the correct failure message" do
@@ -1338,7 +1338,7 @@
13381338

13391339
# NOTE: No need to test this using a string or regexp message — we've tested
13401340
# it enough above
1341-
context "given a compound RSpec fuzzy object" do
1341+
context "given a compound RSpec matcher" do
13421342
context "when used in the positive" do
13431343
context "when the block raises a different error than what is given" do
13441344
context "when the expected error and/or actual message is short" do

spec/unit/rspec/matchers/raise_error_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,31 +42,31 @@
4242
end
4343
end
4444

45-
context "given a simple RSpec fuzzy object" do
45+
context "given a simple RSpec matcher" do
4646
it "returns the correct output" do
4747
expect(raise_error(a_kind_of(RuntimeError)).description).to eq(
4848
"raise #<a kind of RuntimeError>"
4949
)
5050
end
5151
end
5252

53-
context "given a simple RSpec fuzzy object and string message" do
53+
context "given a simple RSpec matcher and string message" do
5454
it "returns the correct output" do
5555
expect(raise_error(a_kind_of(RuntimeError), "boo").description).to eq(
5656
'raise #<a kind of RuntimeError> with message "boo"'
5757
)
5858
end
5959
end
6060

61-
context "given a simple RSpec fuzzy object and regexp message" do
61+
context "given a simple RSpec matcher and regexp message" do
6262
it "returns the correct output" do
6363
expect(raise_error(a_kind_of(RuntimeError), /boo/i).description).to eq(
6464
"raise #<a kind of RuntimeError> with message matching /boo/i"
6565
)
6666
end
6767
end
6868

69-
context "given a compound RSpec fuzzy object" do
69+
context "given a compound RSpec matcher" do
7070
it "returns the correct output" do
7171
expect(raise_error(a_kind_of(Array).or eq(true)).description).to eq(
7272
"raise #<a kind of Array or eq true>"

spec/unit/rspec/object_inspection_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
require "spec_helper"
22

33
RSpec.describe SuperDiff, type: :unit do
4-
describe ".inspect_object", "for RSpec objects" do
4+
describe ".inspect_object", "for RSpec aliased matchers" do
55
context "given a hash-including-<something>" do
66
context "given as_lines: false" do
77
it "returns an inspected version of the object" do
@@ -116,7 +116,7 @@
116116
end
117117
end
118118

119-
context "given a fuzzy object" do
119+
context "given an object-having-<something>" do
120120
context "given as_lines: false" do
121121
it "returns an inspected version of the object" do
122122
string =

0 commit comments

Comments
 (0)