Module: RSpec::Expectations::Syntax Private
Relationships & Source Files | |
Defined in: | rspec-expectations/lib/rspec/expectations/syntax.rb |
Overview
Provides methods for enabling and disabling the available syntaxes provided by rspec-expectations.
Class Method Summary
-
.default_should_host
Internal use only
mod_func
Determines where we add
should
andshould_not
. -
.disable_expect(syntax_host = ::RSpec::Matchers)
Internal use only
mod_func
Disables the
expect
syntax. -
.disable_should(syntax_host = default_should_host)
Internal use only
mod_func
Disables the
should
syntax. -
.enable_expect(syntax_host = ::RSpec::Matchers)
Internal use only
mod_func
Enables the
expect
syntax. -
.enable_should(syntax_host = default_should_host)
Internal use only
mod_func
Enables the
should
syntax. -
.expect_enabled?(syntax_host = ::RSpec::Matchers) ⇒ Boolean
Internal use only
mod_func
Indicates whether or not the
expect
syntax is enabled. -
.should_enabled?(syntax_host = default_should_host) ⇒ Boolean
Internal use only
mod_func
Indicates whether or not the
should
syntax is enabled. -
.warn_about_should!
Internal use only
mod_func
Instructs rspec-expectations to warn on first usage of
should
orshould_not
. -
.warn_about_should_unless_configured(method_name)
Internal use only
mod_func
Generates a deprecation warning for the given method if no warning has already been issued.
Class Method Details
.default_should_host (mod_func)
Determines where we add should
and should_not
.
# File 'rspec-expectations/lib/rspec/expectations/syntax.rb', line 11
def default_should_host @default_should_host ||= ::Object.ancestors.last end
.disable_expect(syntax_host = ::RSpec::Matchers) (mod_func)
Disables the expect
syntax.
# File 'rspec-expectations/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) (mod_func)
Disables the should
syntax.
# File 'rspec-expectations/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) (mod_func)
Enables the expect
syntax.
# File 'rspec-expectations/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) (mod_func)
Enables the should
syntax.
# File 'rspec-expectations/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
(mod_func)
Indicates whether or not the expect
syntax is enabled.
.should_enabled?(syntax_host = default_should_host) ⇒ Boolean
(mod_func)
Indicates whether or not the should
syntax is enabled.
# File 'rspec-expectations/lib/rspec/expectations/syntax.rb', line 90
def should_enabled?(syntax_host=default_should_host) syntax_host.method_defined?(:should) end
.warn_about_should! (mod_func)
Instructs rspec-expectations to warn on first usage of should
or should_not
. Enabled by default. This is largely here to facilitate testing.
# File 'rspec-expectations/lib/rspec/expectations/syntax.rb', line 18
def warn_about_should! @warn_about_should = true end
.warn_about_should_unless_configured(method_name) (mod_func)
Generates a deprecation warning for the given method if no warning has already been issued.
# File 'rspec-expectations/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