模块: RSpec::Expectations::Syntax 私有
- 定义于
- lib/rspec/expectations/syntax.rb
概述
此模块属于私有 API。 尽可能避免使用此模块,因为它可能会在将来被移除或更改。
提供用于启用和禁用 rspec-expectations 提供的可用语法的函数。
类方法概要 收起
-
.default_should_host ⇒ Object 私有
确定我们添加
should
和should_not
的位置。 -
.disable_expect(syntax_host = ::RSpec::Matchers) ⇒ Object 私有
禁用
expect
语法。 -
.disable_should(syntax_host = default_should_host) ⇒ Object 私有
禁用
should
语法。 -
.enable_expect(syntax_host = ::RSpec::Matchers) ⇒ Object 私有
启用
expect
语法。 -
.enable_should(syntax_host = default_should_host) ⇒ Object 私有
启用
should
语法。 -
.expect_enabled?(syntax_host = ::RSpec::Matchers) ⇒ Boolean 私有
指示
expect
语法是否启用。 -
.should_enabled?(syntax_host = default_should_host) ⇒ Boolean 私有
指示
should
语法是否启用。 -
.warn_about_should! ⇒ Object 私有
指示 rspec-expectations 在首次使用
should
或should_not
时发出警告。默认情况下启用。这主要用于方便测试。 -
.warn_about_should_unless_configured(method_name) ⇒ Object 私有
如果尚未发出警告,则为给定方法生成弃用警告。
类方法详情
.default_should_host ⇒Object
此方法属于私有 API。 尽可能避免使用此方法,因为它可能会在将来被移除或更改。
确定我们添加 should
和 should_not
的位置。
11 12 13 |
# File 'lib/rspec/expectations/syntax.rb', line 11 def default_should_host @default_should_host ||= ::Object.ancestors.last end |
.disable_expect(syntax_host = ::RSpec::Matchers) ⇒Object
此方法属于私有 API。 尽可能避免使用此方法,因为它可能会在将来被移除或更改。
禁用 expect
语法。
80 81 82 83 84 85 86 |
# File 'lib/rspec/expectations/syntax.rb', line 80 def disable_expect(syntax_host=::RSpec::Matchers) return unless expect_enabled?(syntax_host) syntax_host.module_exec do undef expect end end |
.disable_should(syntax_host = default_should_host) ⇒Object
此方法属于私有 API。 尽可能避免使用此方法,因为它可能会在将来被移除或更改。
禁用 should
语法。
57 58 59 60 61 62 63 64 |
# File 'lib/rspec/expectations/syntax.rb', line 57 def disable_should(syntax_host=default_should_host) return unless should_enabled?(syntax_host) syntax_host.module_exec do undef should undef should_not end end |
.enable_expect(syntax_host = ::RSpec::Matchers) ⇒Object
此方法属于私有 API。 尽可能避免使用此方法,因为它可能会在将来被移除或更改。
启用 expect
语法。
68 69 70 71 72 73 74 75 76 |
# File 'lib/rspec/expectations/syntax.rb', line 68 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) end end end |
.enable_should(syntax_host = default_should_host) ⇒Object
此方法属于私有 API。 尽可能避免使用此方法,因为它可能会在将来被移除或更改。
启用 should
语法。
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/rspec/expectations/syntax.rb', line 38 def enable_should(syntax_host=default_should_host) @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, =nil, &block) ::RSpec::Expectations::Syntax.warn_about_should_unless_configured(::Kernel.__method__) ::RSpec::Expectations::PositiveExpectationHandler.handle_matcher(self, matcher, , &block) end def should_not(matcher=nil, =nil, &block) ::RSpec::Expectations::Syntax.warn_about_should_unless_configured(::Kernel.__method__) ::RSpec::Expectations::NegativeExpectationHandler.handle_matcher(self, matcher, , &block) end end end |
.expect_enabled?(syntax_host = ::RSpec::Matchers) ⇒Boolean
此方法属于私有 API。 尽可能避免使用此方法,因为它可能会在将来被移除或更改。
指示 expect
语法是否启用。
96 97 98 |
# File 'lib/rspec/expectations/syntax.rb', line 96 def expect_enabled?(syntax_host=::RSpec::Matchers) syntax_host.method_defined?(:expect) end |
.should_enabled?(syntax_host = default_should_host) ⇒Boolean
此方法属于私有 API。 尽可能避免使用此方法,因为它可能会在将来被移除或更改。
指示 should
语法是否启用。
90 91 92 |
# File 'lib/rspec/expectations/syntax.rb', line 90 def should_enabled?(syntax_host=default_should_host) syntax_host.method_defined?(:should) end |
.warn_about_should! ⇒Object
此方法属于私有 API。 尽可能避免使用此方法,因为它可能会在将来被移除或更改。
指示 rspec-expectations 在首次使用 should
或 should_not
时发出警告。默认情况下启用。这主要用于方便测试。
18 19 20 |
# File 'lib/rspec/expectations/syntax.rb', line 18 def warn_about_should! @warn_about_should = true end |
.warn_about_should_unless_configured(method_name) ⇒Object
此方法属于私有 API。 尽可能避免使用此方法,因为它可能会在将来被移除或更改。
如果尚未发出警告,则为给定方法生成弃用警告。
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/rspec/expectations/syntax.rb', line 25 def warn_about_should_unless_configured(method_name) return unless @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` with `config.expect_with(:rspec) { |c| c.syntax = :should }`" ) @warn_about_should = false end |