[rspec-users] understanding rspec predicates

Pat Maddox patmaddox at me.com
Tue Oct 11 22:09:47 EDT 2011


On Oct 11, 2011, at 6:19 PM, David Chelimsky wrote:

> 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".

Totally agree. I was going to let him come to that conclusion on his own ;)

Pat


More information about the rspec-users mailing list