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)
-
- (Object) default_should_host
private
Determines where we add
should
andshould_not
. -
- (Object) disable_expect(syntax_host = ::RSpec::Matchers)
private
Disables the
expect
syntax. -
- (Object) disable_should(syntax_host = default_should_host)
private
Disables the
should
syntax. -
- (Object) enable_expect(syntax_host = ::RSpec::Matchers)
private
Enables the
expect
syntax. -
- (Object) enable_should(syntax_host = default_should_host)
private
Enables the
should
syntax. -
- (ExpectationTarget) expect
Supports
expect(actual).to matcher
syntax by wrappingactual
in anExpectationTarget
. -
- (Boolean) expect_enabled?(syntax_host = ::RSpec::Matchers)
private
Indicates whether or not the
expect
syntax is enabled. -
- (Object) expression_generator
private
Selects which expression generator to use based on the configured syntax.
-
- (Object) negative_expression(target_expression, matcher_expression)
private
Generates a negative expectation expression.
-
- (Object) positive_expression(target_expression, matcher_expression)
private
Generates a positive expectation expression.
-
- (Boolean) should
Passes if
matcher
returns true. -
- (Boolean) should_enabled?(syntax_host = default_should_host)
private
Indicates whether or not the
should
syntax is enabled. -
- (Boolean) should_not
Passes if
matcher
returns false.
Instance Method Details
- (Object) default_should_host
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 |
- (Object) disable_expect(syntax_host = ::RSpec::Matchers)
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 |
- (Object) disable_should(syntax_host = default_should_host)
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 |
- (Object) enable_expect(syntax_host = ::RSpec::Matchers)
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 |
- (Object) enable_should(syntax_host = default_should_host)
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 |
- (ExpectationTarget) expect
Supports expect(actual).to matcher
syntax by wrapping actual
in an
ExpectationTarget
.
|
# File 'lib/rspec/expectations/syntax.rb', line 30
|
- (Boolean) expect_enabled?(syntax_host = ::RSpec::Matchers)
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 |
- (Object) expression_generator
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 |
- (Object) negative_expression(target_expression, matcher_expression)
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 |
- (Object) positive_expression(target_expression, matcher_expression)
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 |
- (Boolean) should
Passes if matcher
returns true. Available on every Object
.
|
# File 'lib/rspec/expectations/syntax.rb', line 9
|
- (Boolean) should_enabled?(syntax_host = default_should_host)
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 |
- (Boolean) should_not
Passes if matcher
returns false. Available on every Object
.
|
# File 'lib/rspec/expectations/syntax.rb', line 20
|