LoginSignup
1
2

More than 5 years have passed since last update.

rspecでbe_includedマッチャを自作した

Last updated at Posted at 2017-09-06

a1 2 3のいずれかであることをテストしたく、

expect(a).to be_included([1, 2, 3])

と書きたかったのだが、調べてもそのようなマッチャが見つからなかったので自作した。
すでにあったらスマン。

# actualがexpectedに含まれているか
RSpec::Matchers.define :be_included do |expected|
  match do |actual|
    expected.include?(actual)
  end
  description do
    "be included in #{expected}"
  end
end
1
2
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2