<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Shlrm.org Blag &#187; Ruby</title>
	<atom:link href="http://shlrm.org/wordpress/category/coding/ruby/feed/" rel="self" type="application/rss+xml" />
	<link>http://shlrm.org/wordpress</link>
	<description>Linux, Java, Ruby, and Politics.</description>
	<lastBuildDate>Mon, 10 Oct 2011 18:50:48 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Using cuke4duke and working around rubygems issues</title>
		<link>http://shlrm.org/wordpress/2011/09/13/using-cuke4duke-and-working-around-rubygems-issues/</link>
		<comments>http://shlrm.org/wordpress/2011/09/13/using-cuke4duke-and-working-around-rubygems-issues/#comments</comments>
		<pubDate>Tue, 13 Sep 2011 21:05:13 +0000</pubDate>
		<dc:creator>David Kowis</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[cucumber]]></category>
		<category><![CDATA[jruby]]></category>

		<guid isPermaLink="false">http://shlrm.org/wordpress/?p=471</guid>
		<description><![CDATA[Getting gems installed for use with cuke4duke.]]></description>
			<content:encoded><![CDATA[<p><a href="https://groups.google.com/d/msg/cukes/KZ2U04UA6MM/JEZ58kBtkcgJ">cuke4duke support has been dropped in favor of work on cucumber-jvm.</a> Which is all well and good, except that cucumber-jvm isn&#8217;t fully baked yet. It&#8217;s not quite there regarding features, but it&#8217;s getting there fast.</p>
<p>Unfortunately, that means for those that are still using cuke4duke, you&#8217;ve got problems to deal with. The voodoo magic that is cuke4duke does not install gems very well. I don&#8217;t know precisely why this is, but it ends up with many problems. Things that will install just fine using a jruby command line, or in native ruby barf a horrible death. Often regarding some YAML::Syck thing.</p>
<pre class="brush: text; gutter: false; first-line: 1">ERROR:  While executing gem ... (ArgumentError)
      undefined class/module YAML::Syck::DefaultKey</pre>
<p>Really sucks and makes it difficult to actually use cuke4duke unless you&#8217;ve already got all the gems you need installed.</p>
<p>After much investigation, I discovered that cuke4duke uses a GEM_HOME of ~/.m2/repository/.jruby . So a simple command can get the gems you want installed into that folder:</p>
<pre class="brush: text; gutter: false; first-line: 1">java -jar jruby-complete-1.6.4.jar -S gem install json --version=1.5.4 --no-rdoc --no-ri -i /home/dkowis/.m2/repository/.jruby</pre>
<p>Unfortunately, if there&#8217;s another &#8220;gem&#8221; command in your path, it will use that instead of the one in your jar file, so you have to munge your path as well to prevent it from doing so.</p>
<p>Finally, I needed a way to get this into our project&#8217;s Maven POM so that we could easily set up other peoples boxes and the configuration isn&#8217;t lost in some terribly manual process of running that command over and over.</p>
<p>This is the solution I came up with:</p>
<pre class="brush:xml wp_syntax">        &lt;profile&gt;
            &lt;id&gt;install-gems&lt;/id&gt;
            &lt;build&gt;
                &lt;plugins&gt;
                    &lt;plugin&gt;
                        &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                        &lt;artifactId&gt;maven-antrun-plugin&lt;/artifactId&gt;
                        &lt;version&gt;1.6&lt;/version&gt;
                        &lt;executions&gt;
                            &lt;execution&gt;
                                &lt;phase&gt;generate-test-resources&lt;/phase&gt;
                                &lt;configuration&gt;
                                    &lt;target&gt;
                                        &lt;property file="gems.properties"/&gt;
                                        &lt;macrodef name="install-gem"&gt;
                                            &lt;attribute name="gem"/&gt;
                                            &lt;attribute name="version"/&gt;
                                            &lt;sequential&gt;
                                                &lt;java jar="${maven.dependency.org.jruby.jruby-complete.jar.path}"
                                                      fork="true"
                                                      failonerror="true"
                                                      maxmemory="64m"
                                                      newenvironment="true"&gt;
                                                    &lt;arg value="-S"/&gt;
                                                    &lt;arg value="gem"/&gt;
                                                    &lt;arg value="install"/&gt;
                                                    &lt;arg value="@{gem}"/&gt;
                                                    &lt;arg value="--version=@{version}"/&gt;
                                                    &lt;arg value="-i"/&gt;
                                                    &lt;arg value="${user.home}/.m2/repository/.jruby"/&gt;
                                                    &lt;env key="PATH" path="${java.home}/bin"/&gt;
                                                &lt;/java&gt;
                                            &lt;/sequential&gt;
                                        &lt;/macrodef&gt;
                                        &lt;install-gem gem="json" version="1.5.4"/&gt; &lt;!-- needed to get json to behave with jruby --&gt;
                                        &lt;install-gem gem="cucumber" version="1.0.3"/&gt;
                                        &lt;install-gem gem="cuke4duke" version="${gem.cuke4duke.version}"/&gt;
                                        &lt;install-gem gem="nokogiri" version="${gem.nokogiri.version}"/&gt;
                                        &lt;install-gem gem="rspec" version="${gem.rspec.version}"/&gt;
                                        &lt;install-gem gem="rest-client" version="${gem.restclient.version}"/&gt;
                                        &lt;install-gem gem="jruby-openssl" version="${gem.jrubyopenssl.version}"/&gt;
                                    &lt;/target&gt;
                                &lt;/configuration&gt;
                                &lt;goals&gt;
                                    &lt;goal&gt;run&lt;/goal&gt;
                                &lt;/goals&gt;
                            &lt;/execution&gt;
                        &lt;/executions&gt;
                    &lt;/plugin&gt;
                &lt;/plugins&gt;
            &lt;/build&gt;
        &lt;/profile&gt;</pre>
<p>One can then run the command &#8216;mvn test -Pinstall-gems&#8217; and the gems will be installed as part of the test-resource-generation phase. This only has to be done once whenever new gems are added, or on initial setup. Once it&#8217;s done, you&#8217;re good to go with the normal cuke4duke workflow.</p>
<p>Hopefully this will save other people some time :)</p>
]]></content:encoded>
			<wfw:commentRss>http://shlrm.org/wordpress/2011/09/13/using-cuke4duke-and-working-around-rubygems-issues/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Adding additional recipes to your Capistrano deploy.rb</title>
		<link>http://shlrm.org/wordpress/2011/08/21/adding-additional-recipes-to-your-capistrano-deploy-rb/</link>
		<comments>http://shlrm.org/wordpress/2011/08/21/adding-additional-recipes-to-your-capistrano-deploy-rb/#comments</comments>
		<pubDate>Mon, 22 Aug 2011 00:23:07 +0000</pubDate>
		<dc:creator>David Kowis</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[capistrano]]></category>

		<guid isPermaLink="false">http://shlrm.org/wordpress/?p=451</guid>
		<description><![CDATA[This was unbelievably difficult to find on the internet. Perhaps I didn&#8217;t know the right things to look for. I wanted to figure out how to require/load/import additional files into the deploy.rb file so that I would be able to drop recipes in to a config/recipes directory. Turns out this is the solution. I ended <a href='http://shlrm.org/wordpress/2011/08/21/adding-additional-recipes-to-your-capistrano-deploy-rb/'>[...]</a>]]></description>
			<content:encoded><![CDATA[<p>This was unbelievably difficult to find on the internet. Perhaps I didn&#8217;t know the right things to look for.</p>
<p>I wanted to figure out how to require/load/import additional files into the deploy.rb file so that I would be able to drop recipes in to a config/recipes directory.</p>
<p>Turns out <a href="http://stackoverflow.com/questions/5365950/require-in-capistrano-deploy-rb-cannot-find-file">this is the solution</a>.</p>
<p>I ended up using this to simply load all the recipes in the recipes directory:</p>
<pre class="brush:ruby">#load in all the other recipes
$LOAD_PATH.unshift File.join(File.dirname(__FILE__), 'recipes')
Dir['config/recipes/**/*.rb'].each { |recipe| require  File.basename(recipe, '.rb') }
</pre>
]]></content:encoded>
			<wfw:commentRss>http://shlrm.org/wordpress/2011/08/21/adding-additional-recipes-to-your-capistrano-deploy-rb/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>It&#8217;s dangerous to code alone</title>
		<link>http://shlrm.org/wordpress/2011/05/25/its-dangerous-to-code-alone/</link>
		<comments>http://shlrm.org/wordpress/2011/05/25/its-dangerous-to-code-alone/#comments</comments>
		<pubDate>Wed, 25 May 2011 22:58:22 +0000</pubDate>
		<dc:creator>David Kowis</dc:creator>
				<category><![CDATA[Coding!]]></category>
		<category><![CDATA[Funneh!]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://shlrm.org/wordpress/?p=448</guid>
		<description><![CDATA[Take this]]></description>
			<content:encoded><![CDATA[<p>Take this</p>
<p><img class="alignnone" title="Master Ruby" src="http://i.imgur.com/RGH7El.jpg" alt="" width="640" height="400" /></p>
]]></content:encoded>
			<wfw:commentRss>http://shlrm.org/wordpress/2011/05/25/its-dangerous-to-code-alone/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Testing API calls using Cucumber and Rails 3</title>
		<link>http://shlrm.org/wordpress/2011/04/30/testing-api-calls-using-cucumber-and-rails-3/</link>
		<comments>http://shlrm.org/wordpress/2011/04/30/testing-api-calls-using-cucumber-and-rails-3/#comments</comments>
		<pubDate>Sun, 01 May 2011 02:23:14 +0000</pubDate>
		<dc:creator>David Kowis</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[capybara]]></category>
		<category><![CDATA[cucumber]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[rails3]]></category>
		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">http://shlrm.org/wordpress/?p=443</guid>
		<description><![CDATA[After many hours of searching, found a solution to Cucumber testing of API calls with Cucumber-rails Capybara backend.]]></description>
			<content:encoded><![CDATA[<p>As it turns out, in Rails 3.x, webrat and cucumber don&#8217;t play along so well. You start getting horribly annoying, and <a href="http://stackoverflow.com/questions/3546011/undefined-webrat-methods-in-cucumber-step-definitions">difficult to solve error messages</a>. The solution in that link is to change the testing method from Rails to Rack. That works, for things like visiting pages, but it broke all of my API tests, where I verify the response code of the body and the JSON that I get back.</p>
<p>I looked into upgrading cucumber-rails, and apparently they <a href="https://github.com/aslakhellesoy/cucumber-rails">recommend using Capybara instead of webrat</a> for Rails 3. So I make the necessary changes. Unfortunately Capybara <strong>only</strong> has a get method. You can only visit pages. Any posts should be exercised by the web forms. This is far less than useful. It has proven to be a huge pain the butt. Hours of trying to find how people do this to no avail. Until I find an <a href="http://stackoverflow.com/questions/1182377/testing-restful-api-with-cucumber-in-a-front-end-less-application/5788530#5788530">obscure answer</a>, at the bottom of a <a href="http://stackoverflow.com/questions/1182377/testing-restful-api-with-cucumber-in-a-front-end-less-application">StackOverflow posting</a>.</p>
<p>That <a href="https://github.com/jayzes/cucumber-api-steps">code on github</a> is the key to testing APIs. It appears to use some of the more internal guts of the Capybara page drivers to accomplish it&#8217;s goal. Works for me.</p>
<p>I am surprised to see that there are few integration test frameworks that support this kind of web service test. Especially since where I work, this is what we build. Having Cucumber features describing those API calls makes everyone&#8217;s job easier. I find it unfortunate that it seems to be somewhat ignored by the testing community. Hopefully this will contain the necessary words for other people that are searching for the same thing I spent hours searching for, and will find it in far less time.</p>
]]></content:encoded>
			<wfw:commentRss>http://shlrm.org/wordpress/2011/04/30/testing-api-calls-using-cucumber-and-rails-3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>I made a Ruby gem</title>
		<link>http://shlrm.org/wordpress/2011/04/01/i-made-a-ruby-gem/</link>
		<comments>http://shlrm.org/wordpress/2011/04/01/i-made-a-ruby-gem/#comments</comments>
		<pubDate>Fri, 01 Apr 2011 19:47:51 +0000</pubDate>
		<dc:creator>David Kowis</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[gem]]></category>

		<guid isPermaLink="false">http://shlrm.org/wordpress/?p=440</guid>
		<description><![CDATA[I forked an xmpp4-simple gem that had some issues, and figured out which they were, and then committed the fixes in my own github repo. It appears that the original gem is unmaintained, and so I just forked it and updated some parts.]]></description>
			<content:encoded><![CDATA[<p>I forked an <a href="https://rubygems.org/gems/dkowis-xmpp4r-simple">xmpp4-simple gem</a> that had some issues, and figured out which they were, and then committed the fixes in my own github repo.</p>
<p>It appears that the original gem is unmaintained, and so I just forked it and updated some parts.</p>
]]></content:encoded>
			<wfw:commentRss>http://shlrm.org/wordpress/2011/04/01/i-made-a-ruby-gem/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Building ruby 1.9 on Fedora 13</title>
		<link>http://shlrm.org/wordpress/2010/06/19/building-ruby-1-9-on-fedora-13/</link>
		<comments>http://shlrm.org/wordpress/2010/06/19/building-ruby-1-9-on-fedora-13/#comments</comments>
		<pubDate>Sat, 19 Jun 2010 18:19:23 +0000</pubDate>
		<dc:creator>David Kowis</dc:creator>
				<category><![CDATA[fedora]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://shlrm.org/wordpress/?p=378</guid>
		<description><![CDATA[Was harder than it should&#8217;ve been. I got annoyed. You need to install openssl-devel, zlib-devel, bison, gcc, make, patch, tar, and maybe gcc-c++ (although I don&#8217;t think this one is needed). Go get the latest ruby 1.9 source, as of this writing 1.9-p378, and extract it somewhere. Then go get the patches on this bug, <a href='http://shlrm.org/wordpress/2010/06/19/building-ruby-1-9-on-fedora-13/'>[...]</a>]]></description>
			<content:encoded><![CDATA[<p>Was harder than it should&#8217;ve been. I got annoyed.</p>
<p>You need to install openssl-devel, zlib-devel, bison, gcc, make, patch, tar, and maybe gcc-c++ (although I don&#8217;t think this one is needed).</p>
<p>Go get the <a href="ftp://ftp.ruby-lang.org//pub/ruby/1.9/ruby-1.9.1-p378.tar.gz">latest ruby 1.9 source</a>, as of this writing 1.9-p378, and extract it somewhere. Then go get the patches on <a href="http://redmine.ruby-lang.org/issues/show/2022#note-11">this bug, at the specific comment</a>. You will need to apply at least the openssl-build-fix patch, since fedora uses openssl 1.0 and it&#8217;s not yet into ruby 1.9. Then follow your typical ./cofnigure, make, and make install stuff. I installed mine into a prefix of /opt/ruby so that it wouldn&#8217;t affect any fedora ruby stuff that it might want. I then added ruby&#8217;s path to the end of my user&#8217;s PATH variable.</p>
<p>That&#8217;ll get you a working ruby 1.9 in Fedora.</p>
]]></content:encoded>
			<wfw:commentRss>http://shlrm.org/wordpress/2010/06/19/building-ruby-1-9-on-fedora-13/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>vim syntax hilighting for ruby/rails</title>
		<link>http://shlrm.org/wordpress/2010/05/18/vim-syntax-hilighting-for-rubyrails/</link>
		<comments>http://shlrm.org/wordpress/2010/05/18/vim-syntax-hilighting-for-rubyrails/#comments</comments>
		<pubDate>Wed, 19 May 2010 02:10:13 +0000</pubDate>
		<dc:creator>David Kowis</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[W00t!]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[vim]]></category>

		<guid isPermaLink="false">http://shlrm.org/wordpress/?p=369</guid>
		<description><![CDATA[http://www.vim.org/scripts/script.php?script_id=1567 Woot. EDIT: Man, this guy has all sorts of good stuff: http://www.vim.org/account/profile.php?user_id=9012 cucumber, rails, ruby, git-vim integration. VIM FTW!]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.vim.org/scripts/script.php?script_id=1567">http://www.vim.org/scripts/script.php?script_id=1567</a></p>
<p>Woot.</p>
<p>EDIT:</p>
<p>Man, this guy has all sorts of good stuff: <a href="http://www.vim.org/account/profile.php?user_id=9012">http://www.vim.org/account/profile.php?user_id=9012</a></p>
<p>cucumber, rails, ruby, git-vim integration. VIM FTW!</p>
]]></content:encoded>
			<wfw:commentRss>http://shlrm.org/wordpress/2010/05/18/vim-syntax-hilighting-for-rubyrails/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Groovy!</title>
		<link>http://shlrm.org/wordpress/2009/01/12/groovy/</link>
		<comments>http://shlrm.org/wordpress/2009/01/12/groovy/#comments</comments>
		<pubDate>Mon, 12 Jan 2009 17:09:36 +0000</pubDate>
		<dc:creator>David Kowis</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[grails]]></category>
		<category><![CDATA[groovy]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[rant]]></category>

		<guid isPermaLink="false">http://shlrm.org/wordpress/?p=175</guid>
		<description><![CDATA[Reading about groovy. It&#8217;s got some really interesting things. It brings the magic of dynamic typing and such (like ruby and python have) to java. But it doesn&#8217;t replace java, it simply adds it to java. So when you&#8217;re writing a groovy script, you can actually just write pure java and it&#8217;ll still work. That&#8217;s <a href='http://shlrm.org/wordpress/2009/01/12/groovy/'>[...]</a>]]></description>
			<content:encoded><![CDATA[<p>Reading about groovy. It&#8217;s got some really interesting things. It brings the magic of dynamic typing and such (like ruby and python have) to java. But it doesn&#8217;t replace java, it simply adds it to java. So when you&#8217;re writing a groovy script, you can actually just write pure java and it&#8217;ll still work. That&#8217;s a very interesting (and potentially evil) feature. Imagine code with groovy and java intermingled. Yikes.</p>
<p>Anyway, there&#8217;s also something called grails. It&#8217;s groovy&#8217;s rails application framework. I&#8217;m hoping that it&#8217;ll be more useful to me than ruby on rails was. Whilst I was able to get some stuff done in rails, I wasn&#8217;t able to do quite what I wanted to do. Things didn&#8217;t interoperate the way I wanted them to. Building things to be completely REST-ful was a pain. It may simply be that I don&#8217;t know enough to do fully RESTful applications.</p>
<p>Also, testing was a pain in rails. I found several testing frameworks, but none quite fit what I wanted to do. That may have had something to do with my insistence upon using constraints in my database. Rails isn&#8217;t built to handle constraints, it wants your database to be dumb. I don&#8217;t really think that&#8217;s a good thing; having constraints in your database allows the database to make more intelligent optimizations regarding the data. Since rails assumes there aren&#8217;t any constraints on the database, it generates tests that break databases that use constraints. There are a few work-arounds, but none that exist well enough to actually run all my tests at once. I can piecemeal them and if I do them in the correct order, everything works just fine.</p>
<p>Regarding ruby itself, I miss the ability to create threads. I&#8217;ve finally understood threading in java, and how to efficiently and effectively use threads to handle things. Lacking a similar threading operation in ruby (at least an obvious one) I had a lot of trouble trying to implement some of the things I wanted to do. I love the dynamic-ness of ruby, and I like the ability to just write code and it does mostly what I think it should. There is probably a good way to do threading in ruby, I mean, people have written webservers entirely in ruby, I just haven&#8217;t figured it out. I&#8217;ll probably still use ruby for things, I&#8217;ve got a project or two churning around in the back of my mind to use ruby on, but for now, I think I&#8217;ll stick with Java.</p>
<p>This has turned more into a rant about what I don&#8217;t like about ruby and rails. I guess I&#8217;m hoping that grails will live up to my expectations more than rails did, and that groovy will give me the dynamic fun that I enjoyed with ruby.</p>
]]></content:encoded>
			<wfw:commentRss>http://shlrm.org/wordpress/2009/01/12/groovy/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>My First Ruby Proggie</title>
		<link>http://shlrm.org/wordpress/2008/07/29/my-first-ruby-proggie/</link>
		<comments>http://shlrm.org/wordpress/2008/07/29/my-first-ruby-proggie/#comments</comments>
		<pubDate>Tue, 29 Jul 2008 18:43:04 +0000</pubDate>
		<dc:creator>David Kowis</dc:creator>
				<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://shlrm.org/wordpress/?p=116</guid>
		<description><![CDATA[I wrote this to provide me a simple wget type program. require 'net/http' require 'uri' proxy_addr = 'localhost' proxy_port = 8118 url = URI.parse('http://shlrm.org/baconflowchartvj8.jpg') Net::HTTP::Proxy(proxy_addr, proxy_port).start(url.host) do &#124;request&#124; puts "Connected to teh proxy" # connected to mah proxy to_save = url.path.split(/\//)[-1] File.open("c:\\" + to_save, 'wb') do &#124;f&#124; puts "opened file" request.request_get(url.path) do &#124;response&#124; content_length = <a href='http://shlrm.org/wordpress/2008/07/29/my-first-ruby-proggie/'>[...]</a>]]></description>
			<content:encoded><![CDATA[<p>I wrote this to provide me a simple wget type program.</p>
<pre class="brush:ruby">
require 'net/http'
require 'uri'

proxy_addr = 'localhost'
proxy_port = 8118

url = URI.parse('http://shlrm.org/baconflowchartvj8.jpg')

Net::HTTP::Proxy(proxy_addr, proxy_port).start(url.host)   do |request|
  puts "Connected to teh proxy"
  # connected to mah proxy
  to_save = url.path.split(/\//)[-1]
  File.open("c:\\" + to_save, 'wb') do |f|
    puts "opened file"
    request.request_get(url.path) do |response|
      content_length = Integer(response['content-length'])
      total_count = 0
      response.read_body do |str|
        if str.length &gt; 0 then
          total_count += str.length
          print "Complete: #{total_count} of #{content_length}:  "
          puts "%4f" % (1.0*total_count/content_length*100)
        end
        f.write str
      end
    end
    puts "Written file"
  end
  puts "done connecting"
end
puts "all done"</pre>
<p>So that&#8217;s it.</p>
]]></content:encoded>
			<wfw:commentRss>http://shlrm.org/wordpress/2008/07/29/my-first-ruby-proggie/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ruby: Unit Tests and Debugging</title>
		<link>http://shlrm.org/wordpress/2008/07/29/ruby-unit-tests-and-debugging/</link>
		<comments>http://shlrm.org/wordpress/2008/07/29/ruby-unit-tests-and-debugging/#comments</comments>
		<pubDate>Tue, 29 Jul 2008 14:49:03 +0000</pubDate>
		<dc:creator>David Kowis</dc:creator>
				<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://shlrm.org/wordpress/?p=114</guid>
		<description><![CDATA[Well, this is all that&#8217;s left for learning the core of the language. How to use ruby&#8217;s built in Unit Testing framework and how to fiddle with the debugger. This post will be very short, because there&#8217;s not a whole lot to unit testing. Going over the debugger is kinda silly too, since it&#8217;s mostly <a href='http://shlrm.org/wordpress/2008/07/29/ruby-unit-tests-and-debugging/'>[...]</a>]]></description>
			<content:encoded><![CDATA[<p>Well, this is all that&#8217;s left for learning the core of the language. How to use ruby&#8217;s built in Unit Testing framework and how to fiddle with the debugger. This post will be very short, because there&#8217;s not a whole lot to unit testing. Going over the debugger is kinda silly too, since it&#8217;s mostly just a command reference. Also, I found an interesting gotcha in the examples listed that I&#8217;ll share with you. There&#8217;s a benchmarking and profiling module worth saying a few words about.<span id="more-114"></span></p>
<p>Unit testing in ruby is just like unit testing in any other language. Assert_* methods abound.</p>
<p>Using the debugger is similar to using gdb or some other debugger as well. There&#8217;s a list of commands, you can set breakpoints and watch variables. Nothing very surprising there.</p>
<p>The author offers up a &#8220;checklist&#8221; for going through your program to ensure that it all works. He firstly reccomends that you run the program with -w. Keep warnings on, so you can resolve issues. He mentions an interesting issue with precendence regarding {} and do&#8230;end. To quote the example source code from the book:</p>
<pre lang="ruby">def one(arg)
  if block_given?
    "block given to 'one' returns #{yield}"
  else
    arg
  end
end
def two
  if block_given?
    "block given to 'two' returns #{yield}"
  end
end
result1 = one two {
  "three"
}
result2 = one two do
  "three"
end
puts "With braces, result = #{result1}"
puts "With do/end, result = #{result2}"</pre>
<p>Which produces:</p>
<pre>With braces, result = block given to 'two' returns three
With do/end, result = block given to 'one' returns three</pre>
<p>So that&#8217;s something to keep in mind. Another gotcha that caught me, is that output may be buffered. I was writing a program to theif images from a website, and I wanted to use print &#8220;.&#8221; to show completion of an image, but the software wouldn&#8217;t show anything. puts &#8220;.&#8221; would work, but that put a newline character. I hacked around it by calling $stdout.flush to force it to put the . to the console. Setting &#8220;sync&#8221; on the thing may have worked better.</p>
<p>Also of note is a benchmark module built into ruby. You can profile and run benchmarks and it&#8217;ll provide you pretty statistics after running. I&#8217;ve used the java profiler before in the past, and it can really help you identify slow parts of your software.</p>
<p>That&#8217;s mostly the core of the language, and how to build programs. Now, I get into more of the grunt work of building ruby software. I&#8217;ll have to look into section two and see if I&#8217;m going to jump directly into rails or not&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://shlrm.org/wordpress/2008/07/29/ruby-unit-tests-and-debugging/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

