模块: RSpec::Expectations::ExpectationTarget::InstanceMethods

包含于
RSpec::Expectations::ExpectationTarget
定义于
lib/rspec/expectations/expectation_target.rb

概述

定义实例 RSpec::Expectations::ExpectationTarget 实例方法。这些方法在模块中定义,因此我们可以将其包含在 Minitest::Expectation 中,当加载 rspec/expectations/minitest_integration 时,以支持与 Minitest 的使用。

实例方法摘要 收起

实例方法详情

#not_to(matcher = nil, message = nil, &block) ⇒Boolean 也称为: to_not

运行给定的期望,如果 matcher 返回 false,则通过。

示例

expect(value).not_to eq(5)

参数

  • matcher (Matcher) (默认为: nil)
  • message (String, Proc) (默认为: nil)

    期望失败时显示的可选消息

返回

  • (Boolean)

    如果负面期望成功则为 false(否则抛出异常)

另请参见

76
77
78
79
# File 'lib/rspec/expectations/expectation_target.rb', line 76
def not_to(matcher=nil, message=nil, &block)
  prevent_operator_matchers(:not_to) unless matcher
  RSpec::Expectations::NegativeExpectationHandler.handle_matcher(target, matcher, message, &block)
end

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

运行给定的期望,如果 matcher 返回 true,则通过。

示例

expect(value).to eq(5)
expect { perform }.to raise_error

参数

  • matcher (Matcher) (默认为: nil)
  • message (String, Proc) (默认为: nil)

    期望失败时显示的可选消息

返回

  • (Boolean)

    如果期望成功则为 true(否则抛出异常)

另请参见

63
64
65
66
# File 'lib/rspec/expectations/expectation_target.rb', line 63
def to(matcher=nil, message=nil, &block)
  prevent_operator_matchers(:to) unless matcher
  RSpec::Expectations::PositiveExpectationHandler.handle_matcher(target, matcher, message, &block)
end