Skip to content

Commit

Permalink
Merge pull request #1245 from rspec/remove-monkey-patching
Browse files Browse the repository at this point in the history
Scrape out monkey patching
  • Loading branch information
JonRowe committed Dec 31, 2020
2 parents a0b3c36 + e8e8bfc commit ebab7e2
Show file tree
Hide file tree
Showing 26 changed files with 37 additions and 1,282 deletions.
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
Breaking Changes:

* Ruby < 2.3 is no longer supported. (Phil Pirozhkov, #1231)
* Remove `should` and `should_not` syntax (including one-liners). (Phil Pirozhkov, #1245)

Enhancements:

Expand Down
12 changes: 0 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -216,18 +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
`should` syntax:

```ruby
actual.should eq expected
actual.should be > 3
[1, 2, 3].should_not include 4
```

See [detailed information on the `should` syntax and its usage.](https://github.com/rspec/rspec-expectations/blob/main/Should.md)

## Compound Matcher Expressions

Expand Down
176 changes: 0 additions & 176 deletions Should.md

This file was deleted.

2 changes: 0 additions & 2 deletions 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 All @@ -36,7 +35,6 @@
- customized_message.feature
- diffing.feature
- implicit_docstrings.feature
- syntax_configuration.feature
- test_frameworks:
- test_unit.feature
- Changelog.md
4 changes: 1 addition & 3 deletions features/built_in_matchers/README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
rspec-expectations ships with a number of built-in matchers. Each matcher can be used
with `expect(..).to` or `expect(..).not_to` to define positive and negative expectations
respectively on an object. Most matchers can also be accessed using the `(...).should` and
`(...).should_not` syntax; see [using should syntax](https://github.com/rspec/rspec-expectations/blob/main/Should.md) for why we recommend using `expect`.
respectively on an object.

e.g.

expect(result).to eq(3)
expect(list).not_to be_empty
pi.should be > 3

## Object identity

Expand Down
24 changes: 12 additions & 12 deletions features/built_in_matchers/predicates.feature
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ Feature: Predicate matchers

Any arguments passed to the matcher will be passed on to the predicate method.

Scenario: should be_zero (based on Integer#zero?)
Given a file named "should_be_zero_spec.rb" with:
Scenario: is_expected.to be_zero (based on Integer#zero?)
Given a file named "be_zero_spec.rb" with:
"""ruby
RSpec.describe 0 do
it { is_expected.to be_zero }
Expand All @@ -58,12 +58,12 @@ Feature: Predicate matchers
it { is_expected.to be_zero } # deliberate failure
end
"""
When I run `rspec should_be_zero_spec.rb`
When I run `rspec be_zero_spec.rb`
Then the output should contain "2 examples, 1 failure"
And the output should contain "expected `7.zero?` to be truthy, got false"

Scenario: should_not be_empty (based on Array#empty?)
Given a file named "should_not_be_empty_spec.rb" with:
Scenario: is_expected.not_to be_empty (based on Array#empty?)
Given a file named "not_to_be_empty_spec.rb" with:
"""ruby
RSpec.describe [1, 2, 3] do
it { is_expected.not_to be_empty }
Expand All @@ -73,25 +73,25 @@ Feature: Predicate matchers
it { is_expected.not_to be_empty } # deliberate failure
end
"""
When I run `rspec should_not_be_empty_spec.rb`
When I run `rspec not_to_be_empty_spec.rb`
Then the output should contain "2 examples, 1 failure"
And the output should contain "expected `[].empty?` to be falsey, got true"

Scenario: should have_key (based on Hash#has_key?)
Given a file named "should_have_key_spec.rb" with:
Scenario: is_expected.to have_key (based on Hash#has_key?)
Given a file named "have_key_spec.rb" with:
"""ruby
RSpec.describe Hash do
subject { { :foo => 7 } }
it { is_expected.to have_key(:foo) }
it { is_expected.to have_key(:bar) } # deliberate failure
end
"""
When I run `rspec should_have_key_spec.rb`
When I run `rspec have_key_spec.rb`
Then the output should contain "2 examples, 1 failure"
And the output should contain "expected `{:foo=>7}.has_key?(:bar)` to be truthy, got false"

Scenario: should_not have_all_string_keys (based on custom #has_all_string_keys? method)
Given a file named "should_not_have_all_string_keys_spec.rb" with:
Scenario: is_expected.to have_decimals (based on custom #have_decimals? method)
Given a file named "have_decimals_spec.rb" with:
"""ruby
class Float
def has_decimals?
Expand All @@ -112,7 +112,7 @@ Feature: Predicate matchers
end
end
"""
When I run `rspec should_not_have_all_string_keys_spec.rb`
When I run `rspec have_decimals_spec.rb`
Then the output should contain "2 examples, 1 failure"
And the output should contain "expected `42.0.has_decimals?` to be truthy, got false"

Expand Down
6 changes: 3 additions & 3 deletions features/custom_matchers/define_matcher.feature
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ Feature: Define a custom matcher
end
RSpec.describe "these two arrays" do
specify "should be similar" do
it "is similar" do
expect([1,2,3]).to have_same_elements_as([2,3,1])
end
end
Expand Down Expand Up @@ -278,7 +278,7 @@ Feature: Define a custom matcher
Then the output should contain "3 examples, 0 failures"

Scenario: Matcher with separate logic for expect().to and expect().not_to
Given a file named "matcher_with_separate_should_not_logic_spec.rb" with:
Given a file named "matcher_with_separate_not_to_logic_spec.rb" with:
"""ruby
RSpec::Matchers.define :contain do |*expected|
match do |actual|
Expand All @@ -299,7 +299,7 @@ Feature: Define a custom matcher
it { is_expected.not_to contain(1, 4) }
end
"""
When I run `rspec matcher_with_separate_should_not_logic_spec.rb`
When I run `rspec matcher_with_separate_not_to_logic_spec.rb`
Then the output should contain all of these:
| 4 examples, 2 failures |
| expected [1, 2, 3] to contain 1 and 4 |
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
33 changes: 0 additions & 33 deletions features/support/disallow_certain_apis.rb

This file was deleted.

Loading

0 comments on commit ebab7e2

Please sign in to comment.