[rspec-users] understanding rspec predicates

David Chelimsky dchelimsky at gmail.com
Tue Oct 11 21:19:28 EDT 2011


On Oct 11, 2011, at 7:38 PM, Pat Maddox <patmaddox at me.com> wrote:

> On Oct 11, 2011, at 5:22 PM, Patrick J. Collins wrote:
>> Having a spec that does:
>> 
>>    @my_model.alert_flag?.should be_true
>> 
>> Seemed a little goofy to me...  So I did:
> 
> You can do
> 
> @my_model.should be_alert_flag

That name feels odd to me. The model is not an alert flag, it has one. This is actually a good thing! One point of be_xxx is to make you ask if "xxx?" is a good predicate name. If you wouldn't say "should be xxx" then you shouldnt be asking "xxx?".

I'd rename it to something like "has_alert_flag?" or "flagged_for_alert?" so I could say "model.should have_alert_flag" or "model.should be_flagged_for_alert".

> A custom matcher isn't worth it in this case, in my opinion.

Agreed, as long as the name changes :)

> Pat


More information about the rspec-users mailing list