Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

clean up the expectation framework configuration

  • Loading branch information...
commit cd5bbec5d405a8ee0abb5fa75d6ae42fb1468167 1 parent 1f93c36
@dchelimsky dchelimsky authored
View
52 lib/rspec/core/configuration.rb
@@ -37,7 +37,8 @@ def self.add_setting(name, opts={})
add_setting :backtrace_clean_patterns
add_setting :tty
add_setting :treat_symbols_as_metadata_keys_with_true_values, :default => false
- add_setting :expecting_with_rspec
+ add_setting :expectation_frameworks
+
CONDITIONAL_FILTERS = {
:if => lambda { |value, metadata| metadata.has_key?(:if) && !value },
@@ -52,12 +53,15 @@ def self.add_setting(name, opts={})
/lib\/rspec\/(core|expectations|matchers|mocks)/
]
+ DEFAULT_EXPECTATION_FRAMEWORKS = [:rspec]
+
def initialize
@color_enabled = false
self.include_or_extend_modules = []
self.files_to_run = []
self.backtrace_clean_patterns = DEFAULT_BACKTRACE_PATTERNS.dup
self.exclusion_filter = CONDITIONAL_FILTERS.dup
+ self.expectation_frameworks = DEFAULT_EXPECTATION_FRAMEWORKS.dup
end
def reset
@@ -179,43 +183,24 @@ def mock_framework=(framework)
end
end
- # Returns the configured expectation framework adapter module(s)
- def expectation_frameworks
- expect_with :rspec unless settings[:expectation_frameworks]
- settings[:expectation_frameworks]
- end
-
- # Delegates to expect_with([framework])
- def expectation_framework=(framework)
- expect_with([framework])
- end
-
# Sets the expectation framework module(s).
#
- # +frameworks+ can be :rspec, :stdlib, or both
+ # +frameworks+ can be :rspec, :stdlib, or both
#
# Given :rspec, configures rspec/expectations.
# Given :stdlib, configures test/unit/assertions
# Given both, configures both
def expect_with(*frameworks)
- settings[:expectation_frameworks] = []
+ expectation_frameworks.clear
frameworks.each do |framework|
- case framework
- when Symbol
- case framework
- when :rspec
- require 'rspec/core/expecting/with_rspec'
- self.expecting_with_rspec = true
- when :stdlib
- require 'rspec/core/expecting/with_stdlib'
- else
- raise ArgumentError, "#{framework.inspect} is not supported"
- end
- settings[:expectation_frameworks] << RSpec::Core::ExpectationFrameworkAdapter
- end
+ settings[:expectation_frameworks] << framework
end
end
+ def expecting_with_rspec?
+ expectation_frameworks.include?(:rspec)
+ end
+
def full_backtrace=(true_or_false)
settings[:backtrace_clean_patterns] = true_or_false ? [] : DEFAULT_BACKTRACE_PATTERNS
end
@@ -360,6 +345,7 @@ def inclusion_filter=(filter)
def inclusion_filter
settings[:inclusion_filter] || {}
end
+
def filter_run_including(*args)
force_overwrite = if args.last.is_a?(Hash) || args.last.is_a?(Symbol)
false
@@ -411,7 +397,17 @@ def configure_mock_framework
def configure_expectation_framework
expectation_frameworks.each do |framework|
- RSpec::Core::ExampleGroup.send(:include, framework)
+ case framework
+ when :rspec
+ require 'rspec/core/expecting/with_rspec'
+ when :stdlib
+ require 'rspec/core/expecting/with_stdlib'
+ else
+ raise ArgumentError, "#{framework.inspect} is not supported"
+ end
+ end
+ unless expectation_frameworks.empty?
+ RSpec::Core::ExampleGroup.send(:include, RSpec::Core::ExpectationFrameworkAdapter)
end
end
View
18 spec/rspec/core/configuration_spec.rb
@@ -82,15 +82,9 @@ module RSpec::Core
describe "#expectation_framework" do
it "defaults to :rspec" do
+ config.expectation_frameworks = [:rspec]
config.should_receive(:require).with('rspec/core/expecting/with_rspec')
- config.expectation_frameworks
- end
- end
-
- describe "#expectation_framework=" do
- it "delegates to expect_with=" do
- config.should_receive(:expect_with).with([:rspec])
- config.expectation_framework = :rspec
+ config.configure_expectation_framework
end
end
@@ -98,8 +92,9 @@ module RSpec::Core
[:rspec, :stdlib].each do |framework|
context "with #{framework}" do
it "requires the adapter for #{framework.inspect}" do
- config.should_receive(:require).with("rspec/core/expecting/with_#{framework}")
config.expect_with framework
+ config.should_receive(:require).with("rspec/core/expecting/with_#{framework}")
+ config.configure_expectation_framework
end
end
end
@@ -107,6 +102,7 @@ module RSpec::Core
it "raises ArgumentError if framework is not supported" do
expect do
config.expect_with :not_supported
+ config.configure_expectation_framework
end.to raise_error(ArgumentError)
end
end
@@ -118,8 +114,8 @@ module RSpec::Core
config.stub(:require)
end
- it "returns false by default" do
- config.should_not be_expecting_with_rspec
+ it "returns true by default" do
+ config.should be_expecting_with_rspec
end
it "returns true when `expect_with :rspec` has been configured" do
Please sign in to comment.
Something went wrong with that request. Please try again.