# Shouldn't this spec fail?

**URL:** <https://www.ruby-forum.com/t/shouldnt-this-spec-fail/93064>\
**Category:** Rails\
**Created:** [April 27, 2007, 1:36am UTC](https://www.ruby-forum.com/t/shouldnt-this-spec-fail/93064 "2007-04-27T01:36:50Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [April 27, 2007, 1:36am UTC](https://www.ruby-forum.com/t/shouldnt-this-spec-fail/93064/1 "2007-04-27T01:36:50Z")

</div>

Shouldn’t the second spec fail? I’m trying to provide a default value in  
the  
model (I’m well aware this is normally the job of the controller, but it  
seems right to be the model in this case). Also, after\_initialize  
doesn’t  
seem to be the right way of doing this, but before\_create or any of the  
other things don’t make the first test pass.

specify “should provide a default name when none is given” do  
@emailer.attributes = valid\_emailer\_attributes.except(:name)  
@emailer.name.should\_not\_be\_nil  
@emailer.should\_be\_valid  
end

specify “should not replace name if one is given” do  
@emailer.attributes = valid\_emailer\_attributes # valid name attribute  
is  
“bill”  
(@emailer.name==“bill”).should\_be\_true  
end

class Emailer \< ActiveRecord::Base  
def after\_initialize  
self.name = “joe”  
end  
end

I know how to code what I’m trying to do, but I want to make sure I only  
do  
the minimum to make the specs pass, in proper TDD/BDD style.

-Nathan
