Skip to content

Commit

Permalink
Remove non-monkey-patching should syntax, too
Browse files Browse the repository at this point in the history
  • Loading branch information
pirj committed Dec 23, 2020
1 parent 31d95d5 commit 6077df7
Show file tree
Hide file tree
Showing 11 changed files with 5 additions and 420 deletions.
3 changes: 2 additions & 1 deletion Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
Breaking Changes:

* Ruby < 2.3 is no longer supported. (Phil Pirozhkov, #1231)
* Extract monkey-patching `should*` syntax and globally-exposed DSL. (Phil Pirozhkov, #1245)
* Extract `should*` (both monkey-patching and non-monkey-patching) syntax and
globally-exposed DSL. (Phil Pirozhkov, #1245)

Enhancements:

Expand Down
11 changes: 0 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -216,17 +216,6 @@ expect(
).to match([a_hash_including(:a => 'hash'), a_hash_including(:a => 'another')])
```

## `should` syntax

In addition to the `expect` syntax, rspec-expectations continues to support the
non-monkey patching `should` syntax:

```ruby
subject(:number) { 4 }
it { should eq(4) }
it { should be > 3 }
it { should_not be_odd }
```

## Compound Matcher Expressions

Expand Down
1 change: 0 additions & 1 deletion features/.nav
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
- have_attributes.feature
- include.feature
- match.feature
- operators.feature
- raise_error.feature
- respond_to.feature
- satisfy.feature
Expand Down
3 changes: 1 addition & 2 deletions features/customized_message.feature
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
Feature: customized message

RSpec tries to provide useful failure messages, but for cases in which you want more
specific information, you can define your own message right in the example.This works for
any matcher _other than the operator matchers_.
specific information, you can define your own message right in the example.

Scenario: customize failure message
Given a file named "example_spec.rb" with:
Expand Down
4 changes: 0 additions & 4 deletions lib/rspec/expectations/handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ def self.handle_failure(matcher, message, failure_message_method)
class PositiveExpectationHandler
def self.handle_matcher(actual, initial_matcher, custom_message=nil, &block)
ExpectationHelper.with_matcher(self, initial_matcher, custom_message) do |matcher|
return ::RSpec::Matchers::BuiltIn::PositiveOperatorMatcher.new(actual) unless initial_matcher

match_result = matcher.matches?(actual, &block)
if custom_message && match_result.respond_to?(:error_generator)
match_result.error_generator.opts[:message] = custom_message
Expand All @@ -74,8 +72,6 @@ def self.opposite_should_method
class NegativeExpectationHandler
def self.handle_matcher(actual, initial_matcher, custom_message=nil, &block)
ExpectationHelper.with_matcher(self, initial_matcher, custom_message) do |matcher|
return ::RSpec::Matchers::BuiltIn::NegativeOperatorMatcher.new(actual) unless initial_matcher

negated_match_result = does_not_match?(matcher, actual, &block)
if custom_message && negated_match_result.respond_to?(:error_generator)
negated_match_result.error_generator.opts[:message] = custom_message
Expand Down
3 changes: 0 additions & 3 deletions lib/rspec/matchers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -501,9 +501,6 @@ def change(receiver=nil, message=nil, &block)
# This works for collections. Pass in multiple args and it will only
# pass if all args are found in collection.
#
# @note This is also available using the `=~` operator with `should`,
# but `=~` is not supported with `expect`.
#
# @example
# expect([1, 2, 3]).to contain_exactly(1, 2, 3)
# expect([1, 2, 3]).to contain_exactly(1, 3, 2)
Expand Down
3 changes: 0 additions & 3 deletions lib/rspec/matchers/built_in.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,7 @@ module BuiltIn
autoload :Include, 'rspec/matchers/built_in/include'
autoload :All, 'rspec/matchers/built_in/all'
autoload :Match, 'rspec/matchers/built_in/match'
autoload :NegativeOperatorMatcher, 'rspec/matchers/built_in/operators'
autoload :OperatorMatcher, 'rspec/matchers/built_in/operators'
autoload :Output, 'rspec/matchers/built_in/output'
autoload :PositiveOperatorMatcher, 'rspec/matchers/built_in/operators'
autoload :RaiseError, 'rspec/matchers/built_in/raise_error'
autoload :RespondTo, 'rspec/matchers/built_in/respond_to'
autoload :Satisfy, 'rspec/matchers/built_in/satisfy'
Expand Down
128 changes: 0 additions & 128 deletions lib/rspec/matchers/built_in/operators.rb

This file was deleted.

4 changes: 2 additions & 2 deletions spec/rspec/expectations/expectation_target_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,13 @@ module Expectations
it 'does not support operator matchers from #to' do
expect {
expect(3).to == 3
}.to raise_error(ArgumentError)
}.to raise_error(ArgumentError, /The expect syntax does not support operator matchers, so you must pass a matcher to `#to`/)
end

it 'does not support operator matchers from #not_to' do
expect {
expect(3).not_to == 4
}.to raise_error(ArgumentError)
}.to raise_error(ArgumentError, /The expect syntax does not support operator matchers, so you must pass a matcher to `#not_to`/)
end
end

Expand Down
14 changes: 0 additions & 14 deletions spec/rspec/matchers/built_in/be_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -746,20 +746,6 @@ def send
end
end

RSpec.describe "should be =~" do
subject { "a string" }

it "passes when =~ operator returns true" do
should be =~ /str/
end

it "fails when =~ operator returns false" do
expect {
should be =~ /blah/
}.to fail_with(%(expected: =~ /blah/\n got: "a string"))
end
end

RSpec.describe "expect(...).to be ===" do
it "passes when === operator returns true" do
expect(Hash).to be === {}
Expand Down
Loading

0 comments on commit 6077df7

Please sign in to comment.