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_
andhave_
. For example,it { should have_green_pants }
would assert that thehas_green_pants?
method on thesubject
returnstrue
.In the same fashion, an example such as
it { should be_happy }
would assert that thehappy?
method on thesubject
returnstrue
.So, the example
it { should be_const_defined(:VERSION) }
asserts thatconst_defined?(:VERSION)
returnstrue
.