模块: RSpec::Matchers::FailMatchers

定义于
lib/rspec/matchers/fail_matchers.rb

概述

用于测试 RSpec 匹配器的匹配器。使用以下方法包含它们

require 'rspec/matchers/fail_matchers'
RSpec.configure do |config|
  config.include RSpec::Matchers::FailMatchers
end

实例方法摘要 折叠

实例方法详情

#fail(&block) ⇒Object

如果期望失败则匹配

示例

expect { some_expectation }.to fail
17
18
19
# File 'lib/rspec/matchers/fail_matchers.rb', line 17
def fail(&block)
  raise_error(RSpec::Expectations::ExpectationNotMetError, &block)
end

#fail_including(*snippets) ⇒Object

如果期望失败包括提供的消息则匹配

示例

expect { some_expectation }.to fail_including("portion of some failure message")
34
35
36
37
38
39
# File 'lib/rspec/matchers/fail_matchers.rb', line 34
def fail_including(*snippets)
  raise_error(
    RSpec::Expectations::ExpectationNotMetError,
    a_string_including(*snippets)
  )
end

#fail_with(message) ⇒Object

如果期望失败并使用提供的消息则匹配

示例

expect { some_expectation }.to fail_with("some failure message")
expect { some_expectation }.to fail_with(/some failure message/)
26
27
28
# File 'lib/rspec/matchers/fail_matchers.rb', line 26
def fail_with(message)
  raise_error(RSpec::Expectations::ExpectationNotMetError, message)
end