123456789_123456789_123456789_123456789_123456789_

Class: RSpec::Expectations::ValueExpectationTarget Private

Do not use. This class is for internal use only.
Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
Instance Chain:
Inherits: RSpec::Expectations::ExpectationTarget
Defined in: rspec-expectations/lib/rspec/expectations/expectation_target.rb

Overview

Validates the provided matcher to ensure it supports block expectations, in order to avoid user confusion when they use a block thinking the expectation will be on the return value of the block rather than the block itself.

Constant Summary

ExpectationTarget - Inherited

UndefinedValue

Class Method Summary

ExpectationTarget - Inherited

Instance Attribute Summary

Instance Method Summary

ExpectationTarget::InstanceMethods - Included

#not_to

Runs the given expectation, passing if ‘matcher` returns false.

#to

Runs the given expectation, passing if ‘matcher` returns true.

#to_not
#prevent_operator_matchers

Instance Method Details

#enforce_value_expectation(matcher) (private)

[ GitHub ]

  
# File 'rspec-expectations/lib/rspec/expectations/expectation_target.rb', line 111

def enforce_value_expectation(matcher)
  return if supports_value_expectations?(matcher)

  RSpec.deprecate(
    "expect(value).to #{RSpec::Support::ObjectFormatter.format(matcher)}",
    :message =>
      "The implicit block expectation syntax is deprecated, you should pass " \
      "a block rather than an argument to `expect` to use the provided " \
      "block expectation matcher or the matcher must implement " \
      "`supports_value_expectations?`. e.g  `expect { value }.to " \
      "#{RSpec::Support::ObjectFormatter.format(matcher)}` not " \
      "`expect(value).to #{RSpec::Support::ObjectFormatter.format(matcher)}`"
  )
end

#not_to(matcher = nil, message = nil, &block)

[ GitHub ]

  
# File 'rspec-expectations/lib/rspec/expectations/expectation_target.rb', line 104

def not_to(matcher=nil, message=nil, &block)
  enforce_value_expectation(matcher)
  super
end

#supports_value_expectations?(matcher) ⇒ Boolean (private)

[ GitHub ]

  
# File 'rspec-expectations/lib/rspec/expectations/expectation_target.rb', line 126

def supports_value_expectations?(matcher)
  !matcher.respond_to?(:supports_value_expectations?) || matcher.supports_value_expectations?
end

#to(matcher = nil, message = nil, &block)

[ GitHub ]

  
# File 'rspec-expectations/lib/rspec/expectations/expectation_target.rb', line 99

def to(matcher=nil, message=nil, &block)
  enforce_value_expectation(matcher)
  super
end