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

Scrape out monkey patching #2803

Merged
merged 2 commits into from
Dec 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
Breaking Changes:

* Ruby < 2.3 is no longer supported. (Phil Pirozhkov, #2787)
* Extract `should` syntax (including the non-monkey-patching one liner). (Phil Pirozhkov, #2803)
* Remove globally-exposed DSL (example and shared group methods
in the root scope and on Module). (Phil Pirozhkov, #2803)

Enhancements:

Expand Down
74 changes: 0 additions & 74 deletions features/configuration/enable_global_dsl.feature

This file was deleted.

106 changes: 0 additions & 106 deletions features/configuration/zero_monkey_patching_mode.feature

This file was deleted.

28 changes: 4 additions & 24 deletions features/subject/one_liner_syntax.feature
Original file line number Diff line number Diff line change
@@ -1,22 +1,13 @@
@oneliner-should
Feature: One-liner syntax

RSpec supports a one-liner syntax for setting an expectation on the
`subject`. RSpec will give the examples a doc string that is auto-
RSpec supports a one-liner syntax, `is_expected`, for setting an expectation
on the `subject`. RSpec will give the examples a doc string that is auto-
generated from the matcher used in the example. This is designed specifically
to help avoid duplication in situations where the doc string and the matcher
used in the example mirror each other exactly. When used excessively, it can
produce documentation output that does not read well or contribute to
understanding the object you are describing.

This comes in two flavors:

* `is_expected` is defined simply as `expect(subject)` and is designed for
when you are using rspec-expectations with its newer expect-based syntax.
* `should` was designed back when rspec-expectations only had a should-based
syntax. However, it continues to be available and work even if the
`:should` syntax is disabled (since that merely removes `Object#should`
but this is `RSpec::Core::ExampleGroup#should`).
understanding the object you are describing. This syntax is a shorthand for
`expect(subject)`.

Notes:

Expand All @@ -29,13 +20,6 @@ Feature: One-liner syntax
"""ruby
RSpec.describe Array do
describe "when first created" do
# Rather than:
# it "should be empty" do
# subject.should be_empty
# end

it { should be_empty }
# or
it { is_expected.to be_empty }
end
end
Expand All @@ -47,7 +31,6 @@ Feature: One-liner syntax
Array
when first created
is expected to be empty
is expected to be empty
"""

Scenario: Explicit subject
Expand All @@ -56,8 +39,6 @@ Feature: One-liner syntax
RSpec.describe Array do
describe "with 3 items" do
subject { [1,2,3] }
it { should_not be_empty }
# or
it { is_expected.not_to be_empty }
end
end
Expand All @@ -69,5 +50,4 @@ Feature: One-liner syntax
Array
with 3 items
is expected not to be empty
is expected not to be empty
"""
21 changes: 1 addition & 20 deletions features/support/require_expect_syntax_in_aruba_specs.rb
Original file line number Diff line number Diff line change
@@ -1,29 +1,10 @@
if defined?(Cucumber)
require 'shellwords'
Before('~@allow-should-syntax', '~@with-clean-spec-opts') do
Before('~@with-clean-spec-opts') do
set_environment_variable('SPEC_OPTS', "-r#{Shellwords.escape(__FILE__)}")
end

Before('@oneliner-should') do
set_environment_variable('ALLOW_ONELINER_SHOULD', 'true')
end
else
if ENV['REMOVE_OTHER_RSPEC_LIBS_FROM_LOAD_PATH']
$LOAD_PATH.reject! { |x| /rspec-mocks/ === x || /rspec-expectations/ === x }
end

module DisallowOneLinerShould
def should(*)
raise "one-liner should is not allowed"
end

def should_not(*)
raise "one-liner should_not is not allowed"
end
end

RSpec.configure do |rspec|
rspec.disable_monkey_patching!
rspec.include DisallowOneLinerShould unless ENV['ALLOW_ONELINER_SHOULD']
end
end
3 changes: 0 additions & 3 deletions lib/rspec/core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,4 @@ def self.const_missing(name)
require MODULES_TO_AUTOLOAD.fetch(name) { return super }
::RSpec.const_get(name)
end

Core::DSL.expose_globally!
Core::SharedExampleGroup::TopLevelDSL.expose_globally!
end
Loading