Skip to content

Loading…

Deprecate integration with T::U and minitest < 5.x. #431

Merged
merged 2 commits into from

2 participants

@myronmarston
RSpec member

This is a follow up to #426.

/cc @JonRowe

@JonRowe JonRowe merged commit b6faacd into 2-99-maintenance

1 check passed

Details default The Travis CI build passed
@JonRowe
RSpec member

Nice :)

@JonRowe JonRowe deleted the deprecate-tu-integration branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 22, 2014
  1. @myronmarston
  2. @myronmarston

    On 1.9.2 it's MiniTest::TestCase, with no Unit module in there.

    myronmarston committed
    This appears to work on 1.9.3 as well.
View
3 Changelog.md
@@ -16,6 +16,9 @@ Deprecations:
in favor of `matcher === value`. (Myron Marston)
* Deprecate `RSpec::Matchers::OperatorMatcher` in favor of
`RSpec::Matchers::BuiltIn::OperatorMatcher`. (Myron Marston)
+* Deprecate auto-integration with Test::Unit and minitest.
+ Instead, include `RSpec::Matchers` in the appropriate test case
+ base class yourself. (Myron Marston)
### 2.99.0.beta1 / 2013-11-07
[full changelog](http://github.com/rspec/rspec-expectations/compare/v2.14.4...v2.99.0.beta1)
View
10 features/step_definitions/additional_cli_steps.rb
@@ -20,3 +20,13 @@
step %q{the output should contain "1 failure"}
step %q{the exit status should not be 0}
end
+
+deprecation_message = /rspec-expectations' built-in integration with (Test::Unit|minitest < 5.x) is deprecated/
+
+Then /^the output should contain a deprecation warning about rspec\-expecations' built\-in integration$/ do
+ expect(all_output).to match(deprecation_message)
+end
+
+Then /^the output should not contain a deprecation warning about rspec\-expecations' built\-in integration$/ do
+ expect(all_output).not_to match(deprecation_message)
+end
View
40 features/test_frameworks/test_unit.feature
@@ -42,3 +42,43 @@ Feature: Test::Unit integration
Then the output should contain "3 tests, 0 assertions, 0 failures, 1 errors" or "3 tests, 0 assertions, 1 failures, 0 errors"
And the output should contain "expected empty? to return true, got false"
And the output should contain "be_an_int is deprecated"
+ And the output should contain a deprecation warning about rspec-expecations' built-in integration
+
+ Scenario: use rspec/expectations with Test::Unit
+ Given a file named "rspec_expectations_with_manual_integration_test.rb" with:
+ """
+ require 'test/unit'
+ require "rspec/expectations"
+
+ class RSpecExpectationsTest < Test::Unit::TestCase
+ include ::RSpec::Matchers
+
+ RSpec::Matchers.define :be_an_integer do
+ match { |actual| Integer === actual }
+ end
+
+ def be_an_int
+ # This is actually an internal rspec-expectations API, but is used
+ # here to demonstrate that deprecation warnings from within
+ # rspec-expectations work correcty without depending on rspec-core
+ RSpec.deprecate(:be_an_int, :replacement => :be_an_integer)
+ be_an_integer
+ end
+
+ def test_passing_expectation
+ expect(1 + 3).to eq 4
+ end
+
+ def test_failing_expectation
+ expect([1,2]).to be_empty
+ end
+
+ def test_custom_matcher_with_deprecation_warning
+ expect(1).to be_an_int
+ end
+ end
+ """
+ When I run `ruby rspec_expectations_with_manual_integration_test.rb`
+ Then the output should contain "3 tests, 0 assertions, 0 failures, 1 errors" or "3 tests, 0 assertions, 1 failures, 0 errors"
+ And the output should not contain a deprecation warning about rspec-expecations' built-in integration
+
View
27 lib/rspec/matchers/test_unit_integration.rb
@@ -3,9 +3,26 @@
# and a 1.9 bug can lead to infinite recursion from the `super` call in our
# method_missing hook. See this gist for more info:
# https://gist.github.com/845896
-if defined?(MiniTest::Unit::TestCase)
- MiniTest::Unit::TestCase.send(:include, RSpec::Matchers)
-end
-if defined?(Test::Unit::TestCase)
- Test::Unit::TestCase.send(:include, RSpec::Matchers)
+if defined?(MiniTest::TestCase)
+ MiniTest::TestCase.add_setup_hook do |instance|
+ unless ::RSpec::Matchers === instance
+ ::RSpec.deprecate("rspec-expectations' built-in integration with minitest < 5.x",
+ :replacement => "`include RSpec::Matchers` from within `Minitest::TestCase`")
+
+ MiniTest::TestCase.send(:include, RSpec::Matchers)
+ end
+ end
+elsif defined?(Test::Unit::TestCase)
+ Test::Unit::TestCase.class_eval do
+ def setup
+ unless ::RSpec::Matchers === self
+ ::RSpec.deprecate("rspec-expectations' built-in integration with Test::Unit",
+ :replacement => "`include RSpec::Matchers` from within `Test::Unit::TestCase`")
+
+ Test::Unit::TestCase.send(:include, RSpec::Matchers)
+ end
+
+ super if defined?(super)
+ end
+ end
end
View
37 spec/rspec/matchers/matchers_spec.rb
@@ -1,37 +0,0 @@
-require 'spec_helper'
-
-module RSpec
- describe Matchers do
-
- let(:sample_matchers) do
- [:be,
- :be_close,
- :be_instance_of,
- :be_kind_of]
- end
-
- context "once required" do
- include TestUnitIntegrationSupport
-
- it "includes itself in Test::Unit::TestCase" do
- with_test_unit_loaded do
- test_unit_case = Test::Unit::TestCase.allocate
- sample_matchers.each do |sample_matcher|
- expect(test_unit_case).to respond_to(sample_matcher)
- end
- end
- end
-
- it "includes itself in MiniTest::Unit::TestCase", :if => defined?(MiniTest) do
- with_test_unit_loaded do
- minitest_case = MiniTest::Unit::TestCase.allocate
- sample_matchers.each do |sample_matcher|
- expect(minitest_case).to respond_to(sample_matcher)
- end
- end
- end
-
- end
-
- end
-end
Something went wrong with that request. Please try again.