module RSpec::Expectations::Syntax
@api private Provides methods for enabling and disabling the available syntaxes provided by rspec-expectations.
Public Instance Methods
default_should_host()
click to toggle source
@api private Determines where we add ‘should` and `should_not`.
# File lib/rspec/expectations/syntax.rb, line 42 def default_should_host @default_should_host ||= ::Object.ancestors.last end
disable_expect(syntax_host = ::RSpec::Matchers)
click to toggle source
@api private Disables the ‘expect` syntax.
# File lib/rspec/expectations/syntax.rb, line 95 def disable_expect(syntax_host = ::RSpec::Matchers) return unless expect_enabled?(syntax_host) syntax_host.module_eval do undef expect end ::RSpec::Expectations::ExpectationTarget.disable_deprecated_should end
disable_should(syntax_host = default_should_host)
click to toggle source
@api private Disables the ‘should` syntax.
# File lib/rspec/expectations/syntax.rb, line 66 def disable_should(syntax_host = default_should_host) return unless should_enabled?(syntax_host) syntax_host.module_eval do undef should undef should_not end ::RSpec::Expectations::ExpectationTarget.disable_deprecated_should end
enable_expect(syntax_host = ::RSpec::Matchers)
click to toggle source
@api private Enables the ‘expect` syntax.
# File lib/rspec/expectations/syntax.rb, line 79 def enable_expect(syntax_host = ::RSpec::Matchers) return if expect_enabled?(syntax_host) syntax_host.module_eval do 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
enable_should(syntax_host = default_should_host)
click to toggle source
@api private Enables the ‘should` syntax.
# File lib/rspec/expectations/syntax.rb, line 48 def enable_should(syntax_host = default_should_host) return if should_enabled?(syntax_host) syntax_host.module_eval do def should(matcher=nil, message=nil, &block) ::RSpec::Expectations::PositiveExpectationHandler.handle_matcher(self, matcher, message, &block) end def should_not(matcher=nil, message=nil, &block) ::RSpec::Expectations::NegativeExpectationHandler.handle_matcher(self, matcher, message, &block) end end ::RSpec::Expectations::ExpectationTarget.enable_deprecated_should if expect_enabled? end
expect(*target, &target_block)
click to toggle source
# File lib/rspec/expectations/syntax.rb, line 83 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
expect_enabled?(syntax_host = ::RSpec::Matchers)
click to toggle source
@api private Indicates whether or not the ‘expect` syntax is enabled.
# File lib/rspec/expectations/syntax.rb, line 113 def expect_enabled?(syntax_host = ::RSpec::Matchers) syntax_host.method_defined?(:expect) end
expression_generator()
click to toggle source
@api private Selects which expression generator to use based on the configured syntax.
# File lib/rspec/expectations/syntax.rb, line 131 def expression_generator if expect_enabled? ExpectExpressionGenerator else ShouldExpressionGenerator end end
negative_expression(target_expression, matcher_expression)
click to toggle source
@api private Generates a negative expectation expression.
# File lib/rspec/expectations/syntax.rb, line 125 def negative_expression(target_expression, matcher_expression) expression_generator.negative_expression(target_expression, matcher_expression) end
positive_expression(target_expression, matcher_expression)
click to toggle source
@api private Generates a positive expectation expression.
# File lib/rspec/expectations/syntax.rb, line 119 def positive_expression(target_expression, matcher_expression) expression_generator.positive_expression(target_expression, matcher_expression) end
should(matcher=nil, message=nil, &block)
click to toggle source
# File lib/rspec/expectations/syntax.rb, line 52 def should(matcher=nil, message=nil, &block) ::RSpec::Expectations::PositiveExpectationHandler.handle_matcher(self, matcher, message, &block) end
should_enabled?(syntax_host = default_should_host)
click to toggle source
@api private Indicates whether or not the ‘should` syntax is enabled.
# File lib/rspec/expectations/syntax.rb, line 107 def should_enabled?(syntax_host = default_should_host) syntax_host.method_defined?(:should) end
should_not(matcher=nil, message=nil, &block)
click to toggle source
# File lib/rspec/expectations/syntax.rb, line 56 def should_not(matcher=nil, message=nil, &block) ::RSpec::Expectations::NegativeExpectationHandler.handle_matcher(self, matcher, message, &block) end