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

- old
+ new

@@ -2,11 +2,11 @@ module Expectations # @api private # Provides methods for enabling and disabling the available # syntaxes provided by rspec-expectations. module Syntax - extend self + module_function # @method should # Passes if `matcher` returns true. Available on every `Object`. # @example # actual.should eq expected @@ -41,15 +41,15 @@ # Determines where we add `should` and `should_not`. def default_should_host @default_should_host ||= ::Object.ancestors.last end - def self.warn_about_should! + def warn_about_should! @warn_about_should = true end - def self.warn_about_should_unless_configured(method_name) + def 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`" ) @@ -59,11 +59,11 @@ end # @api private # Enables the `should` syntax. def enable_should(syntax_host = default_should_host) - @warn_about_should = false + @warn_about_should = false if syntax_host == default_should_host return if should_enabled?(syntax_host) syntax_host.module_exec do def should(matcher=nil, message=nil, &block) ::RSpec::Expectations::Syntax.warn_about_should_unless_configured(__method__) @@ -73,12 +73,10 @@ 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? end # @api private # Disables the `should` syntax. def disable_should(syntax_host = default_should_host) @@ -86,12 +84,10 @@ syntax_host.module_exec do undef should undef should_not end - - ::RSpec::Expectations::ExpectationTarget.disable_deprecated_should end # @api private # Enables the `expect` syntax. def enable_expect(syntax_host = ::RSpec::Matchers) @@ -102,24 +98,20 @@ 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 # @api private # Disables the `expect` syntax. def disable_expect(syntax_host = ::RSpec::Matchers) return unless expect_enabled?(syntax_host) syntax_host.module_exec do undef expect end - - ::RSpec::Expectations::ExpectationTarget.disable_deprecated_should end # @api private # Indicates whether or not the `should` syntax is enabled. def should_enabled?(syntax_host = default_should_host) @@ -128,55 +120,9 @@ # @api private # Indicates whether or not the `expect` syntax is enabled. def expect_enabled?(syntax_host = ::RSpec::Matchers) syntax_host.method_defined?(:expect) - end - - # @api private - # Generates a positive expectation expression. - def positive_expression(target_expression, matcher_expression) - expression_generator.positive_expression(target_expression, matcher_expression) - end - - # @api private - # Generates a negative expectation expression. - def negative_expression(target_expression, matcher_expression) - expression_generator.negative_expression(target_expression, matcher_expression) - end - - # @api private - # Selects which expression generator to use based on the configured syntax. - def expression_generator - if expect_enabled? - ExpectExpressionGenerator - else - ShouldExpressionGenerator - end - end - - # @api private - # Generates expectation expressions for the `should` syntax. - module ShouldExpressionGenerator - def self.positive_expression(target_expression, matcher_expression) - "#{target_expression}.should #{matcher_expression}" - end - - def self.negative_expression(target_expression, matcher_expression) - "#{target_expression}.should_not #{matcher_expression}" - end - end - - # @api private - # Generates expectation expressions for the `expect` syntax. - module ExpectExpressionGenerator - def self.positive_expression(target_expression, matcher_expression) - "expect(#{target_expression}).to #{matcher_expression}" - end - - def self.negative_expression(target_expression, matcher_expression) - "expect(#{target_expression}).not_to #{matcher_expression}" - end end end end end