<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="/stylesheets/rss.css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>has_many :thoughts: Tag rspec</title>
    <link>http://blog.kineticweb.com/articles/tag/rspec</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>Musings from a Ruby on Rails development team</description>
    <item>
      <title>Request To All Tutorial Writers</title>
      <description>From now on, if your writing this&amp;#8230;
&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_shell "&gt;git clone git://github.com/sam/extlib.git  
git clone git://github.com/sam/do.git

cd extlib
rake install ; cd ..
cd do
cd data_objects
rake install ; cd ..
cd do_mysql  # || do_postgres || do_sqlite3
rake install&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;p&gt;Instead, tell your readers to do this&amp;#8230;&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_shell "&gt;git clone git://github.com/sam/extlib.git  
git clone git://github.com/sam/do.git

cd extlib
***rake spec***
rake install ; cd ..
cd do
cd data_objects
***rake spec***
rake install ; cd ..
cd do_mysql  # || do_postgres || do_sqlite3
rake install&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;p&gt;Make sure that your running specs that are passing before installing edge software.&lt;/p&gt;


	&lt;p&gt;Here&amp;#8217;s another tip, if your trying to learn new software&amp;#8230; or wondering why something isn&amp;#8217;t working for you&amp;#8230; check the specs! They are a great place to learn just exactly how the author approaches using the libraries they write.&lt;/p&gt;</description>
      <pubDate>Wed, 09 Jul 2008 21:09:00 -0400</pubDate>
      <guid isPermaLink="false">urn:uuid:fe6aa9b9-56dd-4902-bc07-5d6a5a15f283</guid>
      <author>Justin Reagor</author>
      <link>http://blog.kineticweb.com/articles/2008/07/09/request-to-all-tutorial-writers</link>
      <category>gems</category>
      <category>rspec</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Automagical RSpec: Sake Spec for your Scripts</title>
      <description>&lt;p&gt;I&amp;#8217;ve been trying to attempt at spec&amp;#8217;ing every single tiny lil script and bit of code I write a long the way. This means I needed a quick, cross directory/app/project script that would run specs from the current directory.&lt;/p&gt;


	&lt;p&gt;I love Rake, and I love Sake even more.. and Sake was born to do this sort of system-wide task&amp;#8230; so lets get to the code!&lt;/p&gt;


	&lt;p&gt;Throw this in your ~/.sake and smoke it:&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_shell "&gt;desc 'runs specs in the current project, with its own SpecHelper setup'
task 'spec' do
  require 'rake'
  require 'spec/rake/spectask'

  module SpecBase
    def self.included(klass)
      Object.class_eval do
        require 'rubygems'
        require 'spec'
        Spec::Runner.configure { |config| config.mock_with(:mocha) }
      end
    end
  end

  Spec::Rake::SpecTask.new(&amp;quot;spec&amp;quot;) do |t|
    t.spec_opts  = [&amp;quot;--format&amp;quot;, &amp;quot;specdoc&amp;quot;, &amp;quot;--colour&amp;quot;]
    t.spec_files = Dir[&amp;quot;spec/**/*_spec.rb&amp;quot;, &amp;quot;./*_spec.rb&amp;quot;].sort
    include SpecBase
  end
end&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;p&gt;As the description string states, this task encapsulates spec_helper.rb and runs any _spec.rb files in the current directory. This makes it very quick for writing specs for small scripts.&lt;/p&gt;


	&lt;p&gt;Of course, I try to maintain a convention of naming my spec&amp;#8217;s just like in Spec::Rails. So if I&amp;#8217;m writing a eat_bacon.rb script, I use eat_bacon_spec.rb as the spec file.&lt;/p&gt;


	&lt;p&gt;Also note: I&amp;#8217;m loading Mocha up there, so make sure to take that out if you don&amp;#8217;t need it.&lt;/p&gt;


	&lt;p&gt;Enjoy, with Sake!&lt;/p&gt;</description>
      <pubDate>Wed, 16 Apr 2008 21:18:00 -0400</pubDate>
      <guid isPermaLink="false">urn:uuid:80b44ade-e540-4673-978a-e85bf302bd7a</guid>
      <author>Justin Reagor</author>
      <link>http://blog.kineticweb.com/articles/2008/04/16/automagical-rspec-sake-spec-for-your-scripts</link>
      <category>rspec</category>
      <category>sake</category>
      <category>tasks</category>
    </item>
    <item>
      <title>Automagical RSpec: Shared Example Loading from Separate Files</title>
      <description>&lt;p&gt;I especially love Ruby because I can quickly customize it to my tastes and likes. With out regard for anyone else&amp;#8217;s feeling but my own. With that said, I do try and use this power for good. For the better of my office mates.&lt;/p&gt;


	&lt;p&gt;Earlier today I was doing some of this&amp;#8230;&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_shell "&gt;describe Admin::ModelsController do
  shared_examples_for 'all admin pages' do
    code code code here...
  end

  describe 'when logged in' do
    more specific controller specs here...
  end
end&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;p&gt;...and I thought to myself that I would really just love to do this&amp;#8230;&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_shell "&gt;describe Admin::ModelsController do
  it_should_behave_like 'all admin pages'

  describe 'when logged in' do
    more specific controller specs here...
  end
end&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;p&gt;Loading it from some separated out module underneath the specific &lt;span class="caps"&gt;MVC&lt;/span&gt; spec/ sub directories.&lt;/p&gt;


	&lt;p&gt;I&amp;#8217;ll explain more in a second&amp;#8230; but using some code I was working on before, thanks to storing it in Yojimbo, I quickly wrote this into my spec_helper.rb&amp;#8230;&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_shell "&gt;Dir[File.dirname(__FILE__)+'/**/shared/*'].each { |group| 
  require group
  include Object.const_get(group.match(/.*[\/]{1}([\w]*)[.rb]./).captures.first.camelize)
}&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;p&gt;As you can tell from the code, it will go through all sub-directories of the current one (RAILS_ROOT/spec in this case) and rummage for &amp;#8220;shared/&amp;#8221; directories. It will then try and load modules, within these files, named after the file&amp;#8217;s file name.&lt;/p&gt;


	&lt;p&gt;Without having to require and include each single file/module throughout your spec files (or the parent spec_helper).&lt;/p&gt;


	&lt;p&gt;Examples:&lt;/p&gt;


spec/controllers/shared/all_admin_pages.rb
&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_shell "&gt;module AllAdminPages
  shared_examples_for 'all admin pages' do
    code code code here...
  end
end&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;p&gt;Of course this is a smallish hack that I think really cleans out my specs. I generally got the idea from app/views/shared or app/views/layouts/shared directories in Rails. Keeping small shared view partials in separate, nicely organized sub-directories.&lt;/p&gt;


	&lt;p&gt;Let the flaming commence! j/k ;)&lt;/p&gt;</description>
      <pubDate>Tue, 15 Apr 2008 21:05:00 -0400</pubDate>
      <guid isPermaLink="false">urn:uuid:f91f1f27-f4a2-4167-b2a1-580d1905bc27</guid>
      <author>Justin Reagor</author>
      <link>http://blog.kineticweb.com/articles/2008/04/15/automagical-rspec-shared-example-loading-from-separate-files</link>
      <category>rspec</category>
      <category>ruby</category>
      <category>hacks</category>
    </item>
    <item>
      <title>Philly on Rails RSpec Presentation</title>
      <description>&lt;p&gt;Last night, I presented about RSpec to the Philly on Rails user group. It was a fun time. Seemed to go well; I hope people found it informative.&lt;/p&gt;


	&lt;p&gt;It was such a great idea to agree to present on it because a couple months ago I had barely used it. Agreeing to speak in front of a few people about it forced me to learn it. And, so far, I love RSpec!&lt;/p&gt;


	&lt;p&gt;Here are &lt;a href="http://blog.kineticweb.com/files/rspec"&gt;my slides&lt;/a&gt;.&lt;/p&gt;


	&lt;p&gt;I wanted to create &lt;span class="caps"&gt;XHTML&lt;/span&gt; ones but didn&amp;#8217;t have time to learn how and just used Keynote. So they&amp;#8217;re just big JPEGs. And they&amp;#8217;re really not that useful unless you were there last night. I tended to use a lot of illustrations that won&amp;#8217;t mean much unless someone is chatting along side them.&lt;/p&gt;


	&lt;p&gt;I will try and post up a few more posts about RSpec in the coming days to supplement the slides.&lt;/p&gt;</description>
      <pubDate>Thu, 13 Sep 2007 07:48:00 -0400</pubDate>
      <guid isPermaLink="false">urn:uuid:5eb965e6-c0f9-4fba-b6bd-a8d20de87985</guid>
      <author>Colin A. Bartlett</author>
      <link>http://blog.kineticweb.com/articles/2007/09/13/philly-on-rails-rspec-presentation</link>
      <category>rspec</category>
      <category>bdd</category>
      <category>Rails</category>
      <trackback:ping>http://blog.kineticweb.com/articles/trackback/57</trackback:ping>
    </item>
    <item>
      <title>Start Specin' the News</title>
      <description>&lt;p&gt;Since Colin came back from RailsConf raving about &lt;span class="caps"&gt;BDD&lt;/span&gt;, I&amp;#8217;ve found myself priming up for what previously seemed inevitable. Behavioral testing as part of a new development process. Through a better testing structure I hope to..&lt;/p&gt;


	&lt;ol&gt;
	&lt;li&gt;better the quality of my code&lt;/li&gt;
		&lt;li&gt;refined organization of development time&lt;/li&gt;
		&lt;li&gt;focus on the task at hand&lt;/li&gt;
		&lt;li&gt;providing well covered documentation&lt;/li&gt;
	&lt;/ol&gt;


	&lt;p&gt;With that said&amp;#8230; and being the &lt;span class="caps"&gt;HUGE&lt;/span&gt; social loser I am&amp;#8230; I&amp;#8217;ve spent the last two days writing Specs and tests using RSpec 1.0. I have to say its almost too easy writing the actual tests, whereas the process of writing some tests, writing the code and making the code pass the test has been a definite shift in the way I develop. But not an unwelcomed one! ;)&lt;/p&gt;


	&lt;p&gt;Since RSpec seems to have a real lack of helpful documentation, I find myself wondering around their &lt;span class="caps"&gt;API&lt;/span&gt;, blog posts and best guesses. I have had great success so far, until I started writing some protected/private methods.&lt;/p&gt;


	&lt;p&gt;I had initially forseen a world of testing every single line and expression of code. Until I found this tidbit of info on the rspec mailing list&amp;#8230;&lt;/p&gt;


&lt;blockquote&gt;
1.  Should you test protected and private methods in your specs?
&lt;br /&gt;&lt;br /&gt;
No. You&amp;#8217;re specifying the behavior of an object as seen by the outside world. Of course protected and private methods aren&amp;#8217;t available to the world, so why would you need to test them? When
you&amp;#8217;re doing state-based testing, just call a method and then verify that it returns the expected value or leaves your object in an expected state.
&lt;/blockquote&gt;

	&lt;p&gt;This was backed up by almost every post after it. Seems that as a developer testing his code, I should stick with testing the main parts of the system that, overall, accomplish my task. Verifying that they are doing what I need them to do.&lt;/p&gt;


	&lt;p&gt;Private and protected methods typically back up other parts of the system that are public. For documentation purposes, I will probably write some tests that validate the functionality of a private/protected method IF they are made public. Just keeping them commented out to satisfy my entire spec.&lt;/p&gt;


	&lt;p&gt;&lt;small&gt;&lt;a href="http://rubyforge.org/pipermail/rspec-users/2007-March/001019.html"&gt;Quoted RSpec mailing list post&lt;/a&gt; and &lt;a href="http://rubyforge.org/pipermail/rspec-users/2007-March/001012.html"&gt;another great post after that&lt;/a&gt;&lt;/small&gt;&lt;/p&gt;</description>
      <pubDate>Sun, 27 May 2007 12:57:00 -0400</pubDate>
      <guid isPermaLink="false">urn:uuid:fd1381b7-c3f3-4928-ad3e-73db16593f0e</guid>
      <author>Justin Reagor</author>
      <link>http://blog.kineticweb.com/articles/2007/05/27/start-specin-the-news</link>
      <category>rspec</category>
      <category>Rails</category>
      <category>bdd</category>
    </item>
  </channel>
</rss>
