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

Commit 0ec31db

Browse files
committed
Merge pull request #1879 from rspec/better-avoid-generated-descriptions-tests
Beef up tests for when rspec-expectations is not available.
2 parents 6580db2 + 6525139 commit 0ec31db

File tree

3 files changed

+30
-7
lines changed

3 files changed

+30
-7
lines changed

features/expectation_framework_integration/configure_expectation_framework.feature

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ Feature: configure expectation framework
4545
Then the examples should all pass
4646

4747
Scenario: Configure test/unit assertions
48-
Given a file named "example_spec.rb" with:
48+
Given rspec-expectations is not installed
49+
And a file named "example_spec.rb" with:
4950
"""ruby
5051
RSpec.configure do |config|
5152
config.expect_with :test_unit
@@ -72,7 +73,8 @@ Feature: configure expectation framework
7273
And the output should contain "3 examples, 1 failure"
7374

7475
Scenario: Configure minitest assertions
75-
Given a file named "example_spec.rb" with:
76+
Given rspec-expectations is not installed
77+
And a file named "example_spec.rb" with:
7678
"""ruby
7779
RSpec.configure do |config|
7880
config.expect_with :minitest
@@ -146,7 +148,8 @@ Feature: configure expectation framework
146148
Then the examples should all pass
147149

148150
Scenario: Configure test/unit and minitest assertions
149-
Given a file named "example_spec.rb" with:
151+
Given rspec-expectations is not installed
152+
And a file named "example_spec.rb" with:
150153
"""ruby
151154
RSpec.configure do |config|
152155
config.expect_with :test_unit, :minitest

features/step_definitions/core_standalone_steps.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,7 @@
1010
# rspec-expectations from the load path.
1111
set_env('REMOVE_OTHER_RSPEC_LIBS_FROM_LOAD_PATH', 'true')
1212
end
13+
14+
Given(/^rspec-expectations is not installed$/) do
15+
step "only rspec-core is installed"
16+
end

spec/rspec/core/example_spec.rb

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -187,12 +187,28 @@ def assert(val)
187187
end
188188

189189
context "when `expect_with :stdlib` is configured" do
190-
before(:each) { expect_with :stdlib }
190+
around do |ex|
191+
# Prevent RSpec::Matchers from being autoloaded.
192+
orig_autoloads = RSpec::MODULES_TO_AUTOLOAD.dup
193+
RSpec::MODULES_TO_AUTOLOAD.clear
194+
ex.run
195+
RSpec::MODULES_TO_AUTOLOAD.replace(orig_autoloads)
196+
end
197+
198+
before { expect_with :stdlib }
191199

192-
it "does not attempt to get the generated description from RSpec::Matchers" do
193-
expect(RSpec::Matchers).not_to receive(:generated_description)
194-
example_group.example { assert 5 == 5 }
200+
it "does not attempt to get the generated description from RSpec::Matchers when not loaded" do
201+
# Hide the constant while the example runs to simulate it being unloaded.
202+
example_group.before { hide_const("RSpec::Matchers") }
203+
204+
ex = example_group.example { assert 5 == 5 }
195205
example_group.run
206+
207+
# We rescue errors that occur while generating the description and append it,
208+
# so this ensures that no error mentioning `RSpec::Matchers` occurred while
209+
# generating the description.
210+
expect(ex.description).not_to include("RSpec::Matchers")
211+
expect(ex).to pass
196212
end
197213

198214
it "uses the file and line number" do

0 commit comments

Comments
 (0)