Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Simplify how the expect_with configuration works.

- There's no need to include RSpec::Matchers or Test::Unit::Assertions into an adapter module when we can just include them directly.
- It makes it possible to interrogate @expectation_frameworks to see what was already configured and included.  Before, @expectation_frameworks contained [RSpec::Core::ExpectationFrameworkAdapter], regardless of what was configured.
  • Loading branch information...
commit 511f4ba47ff1a62507324878191c646559f1015d 1 parent cb975e0
@myronmarston myronmarston authored
View
12 lib/rspec/core/configuration.rb
@@ -223,18 +223,22 @@ def expectation_framework=(framework)
def expect_with(*frameworks)
assert_no_example_groups_defined(:expect_with)
@expectation_frameworks.clear
- frameworks.each do |framework|
+
+ modules = frameworks.map do |framework|
case framework
when :rspec
- require 'rspec/core/expecting/with_rspec'
+ require 'rspec/expectations'
self.expecting_with_rspec = true
+ ::RSpec::Matchers
when :stdlib
- require 'rspec/core/expecting/with_stdlib'
+ require 'test/unit/assertions'
+ ::Test::Unit::Assertions
else
raise ArgumentError, "#{framework.inspect} is not supported"
end
- @expectation_frameworks << RSpec::Core::ExpectationFrameworkAdapter
end
+
+ @expectation_frameworks.push(*modules)
end
def full_backtrace=(true_or_false)
View
9 lib/rspec/core/expecting/with_rspec.rb
@@ -1,9 +0,0 @@
-require 'rspec/expectations'
-
-module RSpec
- module Core
- module ExpectationFrameworkAdapter
- include RSpec::Matchers
- end
- end
-end
View
9 lib/rspec/core/expecting/with_stdlib.rb
@@ -1,9 +0,0 @@
-require 'test/unit/assertions'
-
-module RSpec
- module Core
- module ExpectationFrameworkAdapter
- include Test::Unit::Assertions
- end
- end
-end
View
14 spec/rspec/core/configuration_spec.rb
@@ -1,6 +1,9 @@
require 'spec_helper'
require 'tmpdir'
+# so the stdlib module is available...
+module Test; module Unit; module Assertions; end; end; end
+
module RSpec::Core
describe Configuration do
@@ -91,7 +94,7 @@ module RSpec::Core
describe "#expectation_framework" do
it "defaults to :rspec" do
- config.should_receive(:require).with('rspec/core/expecting/with_rspec')
+ config.should_receive(:require).with('rspec/expectations')
config.expectation_frameworks
end
end
@@ -104,10 +107,13 @@ module RSpec::Core
end
describe "#expect_with" do
- [:rspec, :stdlib].each do |framework|
+ [
+ [:rspec, 'rspec/expectations'],
+ [:stdlib, 'test/unit/assertions']
+ ].each do |(framework, required_file)|
context "with #{framework}" do
- it "requires the adapter for #{framework.inspect}" do
- config.should_receive(:require).with("rspec/core/expecting/with_#{framework}")
+ it "requires #{required_file}" do
+ config.should_receive(:require).with(required_file)
config.expect_with framework
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.