ブログ

読んで思い出す。忘れるために書く

Q. RSpec で定数定義の有無を確認したい

A. (subject を定義して) it { is_expected.to be_const_defined :FOO } と記述する

回答の例 にあるように、be_have_ で柔軟なテストが可能になっている

The reason is that Rspec has "magic" matchers for methods starting with be_ and have_. For example, it { should have_green_pants } would assert that the has_green_pants? method on the subject returns true.

In the same fashion, an example such as it { should be_happy } would assert that the happy? method on the subject returns true.

So, the example it { should be_const_defined(:VERSION) } asserts that const_defined?(:VERSION) returns true.

Links