Well, I kinda like the word given, however I feel it&#39;s competing with the Context in&nbsp; describe Class, &quot;Context&quot; do<br><br>Maybe before should be replaced with some givens and expectations, like so:<br><br>describe Class, &quot;Context&quot; do 
<br><br>&nbsp; given do<br><br>&nbsp; end<br><br>&nbsp; always_expect do<br><br>&nbsp; end<br><br>&nbsp; it &quot;should ...&quot; do <br><br>&nbsp; end<br><br>end<br><br>Stefan<br><br><div><span class="gmail_quote">2007/11/29, Daniel Tenner &lt;<a href="mailto:daniel.ruby@tenner.org">
daniel.ruby@tenner.org</a>&gt;:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">What are people&#39;s opinions on which of these two styles is better to
<br>use?<br><br>1) before<br>---------------------------<br>module UserSpecHelper<br>&nbsp;&nbsp; include GenericSpecHelper<br><br>&nbsp;&nbsp; def valid_sms_attributes(phone_number=&quot;12345&quot;)<br>&nbsp;&nbsp;&nbsp;&nbsp; { :phone_number =&gt; phone_number }
<br>&nbsp;&nbsp; end<br>end<br><br>describe User, &quot;with phone number&quot; do<br>&nbsp;&nbsp; include UserSpecHelper<br><br>&nbsp;&nbsp; before(:each) do<br>&nbsp;&nbsp;&nbsp;&nbsp; @user = User.new(valid_sms_attributes)<br>&nbsp;&nbsp; end<br><br>&nbsp;&nbsp; it &quot;should be valid&quot; do
<br>&nbsp;&nbsp;&nbsp;&nbsp; @user.should be_valid<br>&nbsp;&nbsp; end<br><br>&nbsp;&nbsp; it &quot;should reject duplicate phone number&quot; do<br>&nbsp;&nbsp;&nbsp;&nbsp; @user.save<br>&nbsp;&nbsp;&nbsp;&nbsp; @user_2 = User.new(valid_sms_attributes)<br>&nbsp;&nbsp;&nbsp;&nbsp; @user_2.should_not be_valid<br>&nbsp;&nbsp; end<br>
<br>&nbsp;&nbsp; it &quot;should be possible to disable the number&quot; do<br>&nbsp;&nbsp;&nbsp;&nbsp; @user.save<br>&nbsp;&nbsp;&nbsp;&nbsp; @user.disable_number<br>&nbsp;&nbsp;&nbsp;&nbsp; @user.should be_disabled<br>&nbsp;&nbsp; end<br>end<br><br><br>------------------------<br>2) given/yield<br>
---------------------------<br>module GenericSpecHelper<br>&nbsp;&nbsp; def given(thing)<br>&nbsp;&nbsp;&nbsp;&nbsp; yield thing if block_given?<br>&nbsp;&nbsp;&nbsp;&nbsp; thing<br>&nbsp;&nbsp; end<br><br>end<br><br><br>module UserSpecHelper<br>&nbsp;&nbsp; include GenericSpecHelper<br>&nbsp;&nbsp; def valid_sms_attributes(phone_number=&quot;12345&quot;)
<br>&nbsp;&nbsp;&nbsp;&nbsp; { :phone_number =&gt; phone_number }<br>&nbsp;&nbsp; end<br><br>&nbsp;&nbsp; def valid_sms_user(phone_number=&quot;12345&quot;)<br>&nbsp;&nbsp;&nbsp;&nbsp; User.new(valid_sms_attributes(phone_number))<br>&nbsp;&nbsp; end<br>end<br><br><br>describe User, &quot;unconfirmed&quot; do
<br>&nbsp;&nbsp; include UserSpecHelper<br><br>&nbsp;&nbsp; it &quot;should be valid&quot; do<br>&nbsp;&nbsp;&nbsp;&nbsp; valid_sms_user.should be_valid<br>&nbsp;&nbsp; end<br><br>&nbsp;&nbsp; it &quot;should reject duplicate phone number&quot; do<br>&nbsp;&nbsp;&nbsp;&nbsp; valid_sms_user(&quot;1&quot;).save
<br>&nbsp;&nbsp;&nbsp;&nbsp; valid_sms_user(&quot;1&quot;).should_not be_valid<br>&nbsp;&nbsp; end<br><br>&nbsp;&nbsp; it &quot;should be possible to disable the number&quot; do<br>&nbsp;&nbsp;&nbsp;&nbsp; given(valid_sms_user) do |user|<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; user.save<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; user.disable_number
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; user.should be_disabled<br>&nbsp;&nbsp;&nbsp;&nbsp; end<br>&nbsp;&nbsp; end<br><br><br>end<br>-------------------<br><br>My thoughts: the second style is more readable sometimes, less other<br>times. More importantly, with the first style, my specs tend to be
<br>split alongside the lines of whether they can use the same before<br>(:each), rather than whether they belong together, whereas with the<br>second one, one &quot;description&quot; can have several different &quot;starting
<br>points&quot;, and I group them by whether I feel they belong together<br>logically. So at the moment I&#39;m more comfortable with the second style.<br><br>What do you think?<br><br>Daniel<br><br>PS: I know these specs themselves are trivial... I&#39;ve used both
<br>approaches in less trivial specs, I hope these illustrate the idea<br>though<br>_______________________________________________<br>rspec-users mailing list<br><a href="mailto:rspec-users@rubyforge.org">rspec-users@rubyforge.org
</a><br><a href="http://rubyforge.org/mailman/listinfo/rspec-users">http://rubyforge.org/mailman/listinfo/rspec-users</a><br></blockquote></div><br><br clear="all"><br>-- <br>Bekk Open Source<br><a href="http://boss.bekk.no">
http://boss.bekk.no</a>