Module: RSpec::Expectations::Syntax Private
Overview
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
Provides methods for enabling and disabling the available syntaxes provided by rspec-expectations.
Defined Under Namespace
Modules: ExpectExpressionGenerator, ShouldExpressionGenerator
Instance Method Summary collapse
-
#default_should_host ⇒ Object
private
Determines where we add
shouldandshould_not. -
#disable_expect(syntax_host = ::RSpec::Matchers) ⇒ Object
private
Disables the
expectsyntax. -
#disable_should(syntax_host = default_should_host) ⇒ Object
private
Disables the
shouldsyntax. -
#enable_expect(syntax_host = ::RSpec::Matchers) ⇒ Object
private
Enables the
expectsyntax. -
#enable_should(syntax_host = default_should_host) ⇒ Object
private
Enables the
shouldsyntax. -
#expect ⇒ ExpectationTarget
Supports
expect(actual).to matchersyntax by wrappingactualin anExpectationTarget. -
#expect_enabled?(syntax_host = ::RSpec::Matchers) ⇒ Boolean
private
Indicates whether or not the
expectsyntax is enabled. -
#expression_generator ⇒ Object
private
Selects which expression generator to use based on the configured syntax.
-
#negative_expression(target_expression, matcher_expression) ⇒ Object
private
Generates a negative expectation expression.
-
#positive_expression(target_expression, matcher_expression) ⇒ Object
private
Generates a positive expectation expression.
-
#should ⇒ Boolean
Passes if
matcherreturns true. -
#should_enabled?(syntax_host = default_should_host) ⇒ Boolean
private
Indicates whether or not the
shouldsyntax is enabled. -
#should_not ⇒ Boolean
Passes if
matcherreturns false.
Instance Method Details
#default_should_host ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Determines where we add should and should_not.
42 43 44 |
# 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) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Disables the expect syntax.
95 96 97 98 99 100 101 102 103 |
# 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) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Disables the should syntax.
66 67 68 69 70 71 72 73 74 75 |
# 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) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Enables the expect syntax.
79 80 81 82 83 84 85 86 87 88 89 90 91 |
# 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) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Enables the should syntax.
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# 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, =nil, &block) ::RSpec::Expectations::PositiveExpectationHandler.handle_matcher(self, matcher, , &block) end def should_not(matcher=nil, =nil, &block) ::RSpec::Expectations::NegativeExpectationHandler.handle_matcher(self, matcher, , &block) end end ::RSpec::Expectations::ExpectationTarget.enable_deprecated_should if expect_enabled? end |
#expect ⇒ ExpectationTarget
Supports expect(actual).to matcher syntax by wrapping actual in an
ExpectationTarget.
|
|
# File 'lib/rspec/expectations/syntax.rb', line 30
|
#expect_enabled?(syntax_host = ::RSpec::Matchers) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Indicates whether or not the expect syntax is enabled.
113 114 115 |
# File 'lib/rspec/expectations/syntax.rb', line 113 def expect_enabled?(syntax_host = ::RSpec::Matchers) syntax_host.method_defined?(:expect) end |
#expression_generator ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Selects which expression generator to use based on the configured syntax.
131 132 133 134 135 136 137 |
# 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) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Generates a negative expectation expression.
125 126 127 |
# 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) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Generates a positive expectation expression.
119 120 121 |
# 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 ⇒ Boolean
Passes if matcher returns true. Available on every Object.
|
|
# File 'lib/rspec/expectations/syntax.rb', line 9
|
#should_enabled?(syntax_host = default_should_host) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Indicates whether or not the should syntax is enabled.
107 108 109 |
# File 'lib/rspec/expectations/syntax.rb', line 107 def should_enabled?(syntax_host = default_should_host) syntax_host.method_defined?(:should) end |
#should_not ⇒ Boolean
Passes if matcher returns false. Available on every Object.
|
|
# File 'lib/rspec/expectations/syntax.rb', line 20
|