<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress/2.2.2" -->
<rss version="2.0" 
	xmlns:content="http://purl.org/rss/1.0/modules/content/">
<channel>
	<title>Comments on: BDD Model Validation using RSpec and extensions to Hash</title>
	<link>http://www.peterryan.net/2007/08/08/bdd-model-validation-using-rspec-and-extensions-to-hash/</link>
	<description>1 4 8 9 27</description>
	<pubDate>Thu, 11 Mar 2010 03:57:49 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.2.2</generator>

	<item>
		<title>By: trauro</title>
		<link>http://www.peterryan.net/2007/08/08/bdd-model-validation-using-rspec-and-extensions-to-hash/#comment-268</link>
		<author>trauro</author>
		<pubDate>Wed, 29 Apr 2009 18:28:24 +0000</pubDate>
		<guid>http://www.peterryan.net/2007/08/08/bdd-model-validation-using-rspec-and-extensions-to-hash/#comment-268</guid>
		<description>Вот решил вам немного помочь и послал этот пост в социальные закладки. Очень надеюсь ваш рейтинг возрастет.</description>
		<content:encoded><![CDATA[<p>Вот решил вам немного помочь и послал этот пост в социальные закладки. Очень надеюсь ваш рейтинг возрастет.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: peter</title>
		<link>http://www.peterryan.net/2007/08/08/bdd-model-validation-using-rspec-and-extensions-to-hash/#comment-95</link>
		<author>peter</author>
		<pubDate>Tue, 18 Sep 2007 22:09:31 +0000</pubDate>
		<guid>http://www.peterryan.net/2007/08/08/bdd-model-validation-using-rspec-and-extensions-to-hash/#comment-95</guid>
		<description>I think the 'only' method has its uses and I initially had it defined but when I posted I realized I wasn't using it in practice. I found starting from a golden object that I stripped as needed to conform to the validation I was testing. I could see the only method being used in other cases.

As to extending the hash instance instead of extending the Hash class within the spec_helper or somewhere with similar effect was I didn't want to extend all my Hash instances in non test code. I wasn't planning on adding except/only to the application and extending the Hash class would make the functionality present and potentially used. So I guess I was protecting myself from Ruby's extensibility by limiting the extension to explicit declarations.

That said on a subsequent rails project I ended up adopting 'except' and 'only' for the entire application as I wanted to use the extension and ended up extending Hash in the environment.rb.

This is starting to lead me to &lt;a href="http://facets.rubyforge.org/" rel="nofollow"&gt;Ruby Facets&lt;/a&gt; which provides numerous useful core extensions.</description>
		<content:encoded><![CDATA[<p>I think the &#8216;only&#8217; method has its uses and I initially had it defined but when I posted I realized I wasn&#8217;t using it in practice. I found starting from a golden object that I stripped as needed to conform to the validation I was testing. I could see the only method being used in other cases.</p>
<p>As to extending the hash instance instead of extending the Hash class within the spec_helper or somewhere with similar effect was I didn&#8217;t want to extend all my Hash instances in non test code. I wasn&#8217;t planning on adding except/only to the application and extending the Hash class would make the functionality present and potentially used. So I guess I was protecting myself from Ruby&#8217;s extensibility by limiting the extension to explicit declarations.</p>
<p>That said on a subsequent rails project I ended up adopting &#8216;except&#8217; and &#8216;only&#8217; for the entire application as I wanted to use the extension and ended up extending Hash in the environment.rb.</p>
<p>This is starting to lead me to <a href="http://facets.rubyforge.org/" rel="nofollow">Ruby Facets</a> which provides numerous useful core extensions.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Chris Pratt</title>
		<link>http://www.peterryan.net/2007/08/08/bdd-model-validation-using-rspec-and-extensions-to-hash/#comment-94</link>
		<author>Chris Pratt</author>
		<pubDate>Tue, 18 Sep 2007 20:04:00 +0000</pubDate>
		<guid>http://www.peterryan.net/2007/08/08/bdd-model-validation-using-rspec-and-extensions-to-hash/#comment-94</guid>
		<description>I implemented this in my specs as well along with the 'only' method John Barton mentioned above.

However, I used an instance class in spec_helper.rb instead of going the module/extend approach, ie:

class Hash

   def except(*keys)  
     self.reject do &#124;k,v&#124;  
       keys.include? k.to_sym  
     end  
   end

   def only(*keys)
     self.dup.reject do &#124;k,v&#124;
       !keys.include? k.to_sym
     end
   end

 end

This way, it's no longer necessary to extend every hash you want to use these functions on, the functionality is just there.

I'm not criticizing your approach, but I am curious if there was a particular reason you decided to go the route you did with it?</description>
		<content:encoded><![CDATA[<p>I implemented this in my specs as well along with the &#8216;only&#8217; method John Barton mentioned above.</p>
<p>However, I used an instance class in spec_helper.rb instead of going the module/extend approach, ie:</p>
<p>class Hash</p>
<p>   def except(*keys)<br />
     self.reject do |k,v|<br />
       keys.include? k.to_sym<br />
     end<br />
   end</p>
<p>   def only(*keys)<br />
     self.dup.reject do |k,v|<br />
       !keys.include? k.to_sym<br />
     end<br />
   end</p>
<p> end</p>
<p>This way, it&#8217;s no longer necessary to extend every hash you want to use these functions on, the functionality is just there.</p>
<p>I&#8217;m not criticizing your approach, but I am curious if there was a particular reason you decided to go the route you did with it?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John Barton</title>
		<link>http://www.peterryan.net/2007/08/08/bdd-model-validation-using-rspec-and-extensions-to-hash/#comment-24</link>
		<author>John Barton</author>
		<pubDate>Tue, 21 Aug 2007 10:39:21 +0000</pubDate>
		<guid>http://www.peterryan.net/2007/08/08/bdd-model-validation-using-rspec-and-extensions-to-hash/#comment-24</guid>
		<description>Thanks for that snippet. I was just seeing a bunch of duplication in my specs and was about to write exactly that. lucky i googled first :)
My preference with the hash extension is just to open up hash and add the methods there. 
I also include an only method:
def only(*keys)
    self.dup.reject do &#124;k,v&#124;
      !keys.include? k.to_sym
    end
  end</description>
		<content:encoded><![CDATA[<p>Thanks for that snippet. I was just seeing a bunch of duplication in my specs and was about to write exactly that. lucky i googled first <img src='http://www.peterryan.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /><br />
My preference with the hash extension is just to open up hash and add the methods there.<br />
I also include an only method:<br />
def only(*keys)<br />
    self.dup.reject do |k,v|<br />
      !keys.include? k.to_sym<br />
    end<br />
  end</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: peter</title>
		<link>http://www.peterryan.net/2007/08/08/bdd-model-validation-using-rspec-and-extensions-to-hash/#comment-7</link>
		<author>peter</author>
		<pubDate>Mon, 13 Aug 2007 12:52:42 +0000</pubDate>
		<guid>http://www.peterryan.net/2007/08/08/bdd-model-validation-using-rspec-and-extensions-to-hash/#comment-7</guid>
		<description>Using this HashExtension I do not use fixtures at all. The purpose of this is to specify the behavior of the model and that is it. In terms of data for the development database that would have to come from a separate source. Generally I will only use data in development on an as needed basis and do not manage development data.

Still even if you were to maintain fixtures for a common development data they need not interfer with using this technique to validate the model's correct behavior. The fixtures written for model validation will be invalid and wouldn't be used for a controller specification.

That said when writing controller specs I hardly ever use the actual model to test and keep them as lean as possible. I avoid loading fixtures in the database (due to the performance drag plus after the fact adjustments) whenever possible.</description>
		<content:encoded><![CDATA[<p>Using this HashExtension I do not use fixtures at all. The purpose of this is to specify the behavior of the model and that is it. In terms of data for the development database that would have to come from a separate source. Generally I will only use data in development on an as needed basis and do not manage development data.</p>
<p>Still even if you were to maintain fixtures for a common development data they need not interfer with using this technique to validate the model&#8217;s correct behavior. The fixtures written for model validation will be invalid and wouldn&#8217;t be used for a controller specification.</p>
<p>That said when writing controller specs I hardly ever use the actual model to test and keep them as lean as possible. I avoid loading fixtures in the database (due to the performance drag plus after the fact adjustments) whenever possible.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Priit Tamboom</title>
		<link>http://www.peterryan.net/2007/08/08/bdd-model-validation-using-rspec-and-extensions-to-hash/#comment-6</link>
		<author>Priit Tamboom</author>
		<pubDate>Mon, 13 Aug 2007 08:18:19 +0000</pubDate>
		<guid>http://www.peterryan.net/2007/08/08/bdd-model-validation-using-rspec-and-extensions-to-hash/#comment-6</guid>
		<description>I like the hash way but where do you hold data for development then? Right now I'm holding everything in fixtures and both development and test will get populated from the same source. 

Does the hash way start duplicating fixtures too much? or I miss something?</description>
		<content:encoded><![CDATA[<p>I like the hash way but where do you hold data for development then? Right now I&#8217;m holding everything in fixtures and both development and test will get populated from the same source. </p>
<p>Does the hash way start duplicating fixtures too much? or I miss something?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kerry Buckley</title>
		<link>http://www.peterryan.net/2007/08/08/bdd-model-validation-using-rspec-and-extensions-to-hash/#comment-4</link>
		<author>Kerry Buckley</author>
		<pubDate>Thu, 09 Aug 2007 06:35:29 +0000</pubDate>
		<guid>http://www.peterryan.net/2007/08/08/bdd-model-validation-using-rspec-and-extensions-to-hash/#comment-4</guid>
		<description>I started writing a helper to remove some of the repetition from testing validations this way. It's described &lt;a href="http://www.kerrybuckley.com/2007/03/11/drying-out-model-specs/" rel="nofollow"&gt;here&lt;/a&gt; if you want to borrow any of the code.</description>
		<content:encoded><![CDATA[<p>I started writing a helper to remove some of the repetition from testing validations this way. It&#8217;s described <a href="http://www.kerrybuckley.com/2007/03/11/drying-out-model-specs/" rel="nofollow">here</a> if you want to borrow any of the code.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
