rspecでこんな風な検証パターンを入れたときのこと
it { is_expected.to eq -5_000 }
そうするとrubocopでwarningが出てしまう。
W: Ambiguous negative number operator. Parenthesize the method arguments if it's surely a negative number operator, or add a whitespace to the right of the - if it should be a subtraction.
Parenthesize = かっこ ということでカッコが必要だ。
この投稿のコメントをいただいた知ったのですが () で囲んであげれば解決!
it { is_expected.to eq(-5_000) }
eqと-5_000の間に何もスペースを入れないのがよい。eq (-5_000)だとこんな風に言われてしまう。
W: (...) interpreted as grouped expression.
あとは、rubocopの設定を調整してもいいんだけど、結果、一旦変数に入れてしまえばOK
it do
expectation = -5_000
is_expected.to eq expectation
end
毎回上記のような記載をするのもコード的には長くなってしまうのでshared_examplesにしてもいいですね。大体この手のパターンは多数使うこともあるでしょうし。
shared_examples do |expectation|
is_expected.to eq expectation
end