LoginSignup
6

More than 5 years have passed since last update.

rspec カスタムマッチャー

Posted at

以下のようなことがしたいときに使う。

it { 1.should greater_than 0 }

RSpec::Matchers::defineを利用する。

RSpec::Matchers.define :greater_than do |expected|
  match {|actual| actual > expected }
end

see: https://www.relishapp.com/rspec/rspec-expectations/v/2-12/docs/custom-matchers/define-matcher

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
6