lib/rspec/expectations/syntax.rb in rspec-expectations-2.99.2 vs lib/rspec/expectations/syntax.rb in rspec-expectations-3.0.0.beta1

- old
+ new

@@ -41,21 +41,39 @@ # Determines where we add `should` and `should_not`. def default_should_host @default_should_host ||= ::Object.ancestors.last end + def self.warn_about_should! + @warn_about_should = true + end + + def self.warn_about_should_unless_configured(method_name) + if @warn_about_should + RSpec.deprecate( + "Using `#{method_name}` from rspec-expectations' old `:should` syntax without explicitly enabling the syntax", + :replacement => "the new `:expect` syntax or explicitly enable `:should`" + ) + + @warn_about_should = false + end + end + # @api private # Enables the `should` syntax. def enable_should(syntax_host = default_should_host) + @warn_about_should = false return if should_enabled?(syntax_host) - syntax_host.module_eval do + syntax_host.module_exec do def should(matcher=nil, message=nil, &block) + ::RSpec::Expectations::Syntax.warn_about_should_unless_configured(__method__) ::RSpec::Expectations::PositiveExpectationHandler.handle_matcher(self, matcher, message, &block) end def should_not(matcher=nil, message=nil, &block) + ::RSpec::Expectations::Syntax.warn_about_should_unless_configured(__method__) ::RSpec::Expectations::NegativeExpectationHandler.handle_matcher(self, matcher, message, &block) end end ::RSpec::Expectations::ExpectationTarget.enable_deprecated_should if expect_enabled? @@ -64,11 +82,11 @@ # @api private # Disables the `should` syntax. def disable_should(syntax_host = default_should_host) return unless should_enabled?(syntax_host) - syntax_host.module_eval do + syntax_host.module_exec do undef should undef should_not end ::RSpec::Expectations::ExpectationTarget.disable_deprecated_should @@ -78,12 +96,14 @@ # Enables the `expect` syntax. def enable_expect(syntax_host = ::RSpec::Matchers) return if expect_enabled?(syntax_host) syntax_host.module_exec do - def expect(value=::RSpec::Expectations::ExpectationTarget::UndefinedValue, &block) - ::RSpec::Expectations::ExpectationTarget.for(value, block) + def expect(*target, &target_block) + target << target_block if block_given? + raise ArgumentError.new("You must pass an argument or a block to #expect but not both.") unless target.size == 1 + ::RSpec::Expectations::ExpectationTarget.new(target.first) end end ::RSpec::Expectations::ExpectationTarget.enable_deprecated_should if should_enabled? end @@ -91,10 +111,10 @@ # @api private # Disables the `expect` syntax. def disable_expect(syntax_host = ::RSpec::Matchers) return unless expect_enabled?(syntax_host) - syntax_host.module_eval do + syntax_host.module_exec do undef expect end ::RSpec::Expectations::ExpectationTarget.disable_deprecated_should end