0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

RSpec include matcherあるのにexclude matcherないのかと思ったら速攻作れた話

Posted at

TL;DR

Negated Matchersを利用して、matcherを作成すれば終わる。

Exlude Matcherを作る(秒で終わる)

sample_spec.rb
RSpec::Matchers.define_negated_matcher :exclude, :include

リファレンスに普通に記載がある

Negated Matchers
Sometimes if you want to test for the opposite using a more descriptive name instead of using not_to, you can use Matchers.define_negated_matcher:

RSpec::Matchers.define_negated_matcher :exclude, :include
include(1, 2).description # => "include 1 and 2"
exclude(1, 2).description # => "exclude 1 and 2"
While the most obvious negated form may be to add a not_ prefix, the failure messages you get with that form can be confusing (e.g. "expected [actual] to not [verb], but did not"). We've found it works best to find a more positive name for the negated form, such as avoid_changing rather than not_change.

rubydoc.infoより転載

0
0
0

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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?