<?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>SameShirtEveryDay.com &#187; Testing</title>
	<atom:link href="http://sameshirteveryday.com/category/testing/feed/" rel="self" type="application/rss+xml" />
	<link>http://sameshirteveryday.com</link>
	<description>Personal blog of the one called Alex Gorbatchev, from Toronto, Canada.</description>
	<lastBuildDate>Wed, 30 Dec 2009 20:00:32 +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>Missing &#8216;a&#8217; character on Windows with rspec and cucumber</title>
		<link>http://sameshirteveryday.com/2009/04/18/missing-a-character-on-windows-with-rspec-and-cucumber/</link>
		<comments>http://sameshirteveryday.com/2009/04/18/missing-a-character-on-windows-with-rspec-and-cucumber/#comments</comments>
		<pubDate>Sat, 18 Apr 2009 17:21:32 +0000</pubDate>
		<dc:creator>Alex Gorbatchev</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Testing]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[cucumber]]></category>
		<category><![CDATA[windows]]></category>

		<guid isPermaLink="false">http://sameshirteveryday.com/?p=190</guid>
		<description><![CDATA[Trying to get a windows rails environment going this morning I stumbled upon something interesting &#8211; all &#8216;a&#8217; characters were missing from cucumber and rspec output. This has something to do with UTF-8 encoding and there&#8217;s a ticket and wiki post on cucumber about it, but no solution that I found acceptable. Everything comes down [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignnone size-full wp-image-192" title="cucumber_a_characters_missing" src="http://sameshirteveryday.com/wp-content/uploads/2009/04/cucumber_a_characters_missing.png" alt="cucumber_a_characters_missing" width="800" height="127" /></p>
<p>Trying to get a windows rails environment going this morning I stumbled upon something interesting &#8211; all &#8216;a&#8217; characters were missing from cucumber and rspec output.</p>
<p>This has something to do with UTF-8 encoding and there&#8217;s a <a href="https://rspec.lighthouseapp.com/projects/16211/tickets/81-windows-all-the-a-characters-in-the-output-have-gone-on-strike">ticket</a> and <a href="http://wiki.github.com/aslakhellesoy/cucumber/troubleshooting">wiki post</a> on cucumber about it, but no solution that I found acceptable.</p>
<p>Everything comes down to having change encoding in the current cmd window. This is achieved via a simple call to <code>chcp 1252</code>, but nobody want&#8217;s to do this every time, right?</p>
<p>To get this executed automaticaly and without resorting to serious registry editing, simply add this line to your <code>cucmber.bat</code> and any other batch files that are exhibiting this problem. You can find <code>cucumber.bat</code> in your <code>/ruby/bin</code> folder.</p>
<p>Here&#8217;s what it looks like:</p>
<pre>chcp 1252
@ECHO OFF
IF NOT "%~f0" == "~f0" GOTO :WinNT
@"ruby.exe" "c:/ruby/bin/cucumber" %1 %2 %3 %4 %5 %6 %7 %8 %9
GOTO :EOF
:WinNT
@"ruby.exe" "%~dpn0" %*</pre>
]]></content:encoded>
			<wfw:commentRss>http://sameshirteveryday.com/2009/04/18/missing-a-character-on-windows-with-rspec-and-cucumber/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Improve your RSpec with simple custom matchers</title>
		<link>http://sameshirteveryday.com/2007/09/15/rspec-custom-expectation-matcher-example/</link>
		<comments>http://sameshirteveryday.com/2007/09/15/rspec-custom-expectation-matcher-example/#comments</comments>
		<pubDate>Sat, 15 Sep 2007 16:20:15 +0000</pubDate>
		<dc:creator>Alex Gorbatchev</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Testing]]></category>

		<guid isPermaLink="false">http://www.sameshirteveryday.com/2007/09/15/rspec-custom-expectation-matcher-example/</guid>
		<description><![CDATA[RSpec is great: it "should be its own root" do @node.root.should == @node end it "should add a child" do @node.children.size.should == 0 child = @klass.new @node.add_child(child) @node.children.size.should == 1 child.parent.should == @node child.root.should == @node end Looks beautiful. However, look at line #2. What would the output be if that test fails? The message [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://rspec.rubyforge.org/index.html">RSpec</a> is great:</p>
<pre name="code" class="ruby">
it "should be its own root" do
  @node.root.should == @node
end

it "should add a child" do
  @node.children.size.should == 0

  child = @klass.new

  @node.add_child(child)
  @node.children.size.should == 1

  child.parent.should == @node
  child.root.should == @node
end</pre>
<p>Looks beautiful. However, look at line #2. What would the output be if that test fails? The message would be something like this: <code>"expected #{@target.inspect} to the same as #{@expected.inspect}"</code>.</p>
<p>Inspecting an object like a tree node could result in multiple pages worth of data and the output basically becomes unreadable if there&#8217;s an array of objects.</p>
<p>This problem could easily be fixed with a <a href="http://www.noobkit.com/rspec-spec-matchers#custom-expectation-matchers">custom expectation matcher</a>.</p>
<pre name="code" class="ruby">
module BeTheSameAsMatcher
  class BeTheSameAs
    def initialize(expected)
      @expected = expected
    end

    def matches?(target)
      @target = target
      @target.eql?(@expected)
    end

    def failure_message
      "expected &lt;#{to_string(@target)}&gt; to " +
      "the same as &lt;#{to_string(@expected)}&gt;"
    end

    def negative_failure_message
      "expected &lt;#{to_string(@target)}&gt; not to " +
      "be the same as &lt;#{to_string(@expected)}&gt;"
    end

    # Returns string representation of an object.
    def to_string(value)
      # indicate a nil
      if value.nil?
        'nil'
      end

      # join arrays
      if value.class == Array
        return value.join(", ")
      end

      # otherwise return to_s() instead of inspect()
      return value.to_s
    end
  end

  # Actual matcher that is exposed.
  def be_the_same_as(expected)
    BeTheSameAs.new(expected)
  end
end</pre>
<p>As you can see, methods <code>failure_message</code> and <code>negative_failure_message</code> define our error messages. Instead of default <code>inspect</code> call, I&#8217;m using a custom <code>to_string</code> method which will either return a <code>join</code> for an <code>Array</code> or <code>to_s</code> for any other object.</p>
<p>To make this available in all of your specs, the module needs to be added in your `spec_helper.rb` like so:</p>
<pre name="code" class="ruby">
require 'spec/be_the_same_as'

Spec::Runner.configure do |config|
  config.include(BeTheSameAsMatcher)
end</pre>
<p>After this, we can change our line #2 from the original script to this:</p>
<pre name="code" class="ruby">
it "should be its own root" do
  @node.root.should be_the_same_as(@node)
end</pre>
]]></content:encoded>
			<wfw:commentRss>http://sameshirteveryday.com/2007/09/15/rspec-custom-expectation-matcher-example/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Use fixtures for placeholder data</title>
		<link>http://sameshirteveryday.com/2007/05/13/use-fixtures-for-placeholder-data/</link>
		<comments>http://sameshirteveryday.com/2007/05/13/use-fixtures-for-placeholder-data/#comments</comments>
		<pubDate>Sun, 13 May 2007 18:57:57 +0000</pubDate>
		<dc:creator>Alex Gorbatchev</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[Testing]]></category>

		<guid isPermaLink="false">http://www.sameshirteveryday.com/2007/05/13/use-fixtures-for-placeholder-data/</guid>
		<description><![CDATA[Rails allows you to create data fixtures which can contain test data which is used during unit tests and gets loaded into a _test database. It&#8217;s possible to load that data into your _development database so that you can use the same data while looking at your site in the browser. This can be achieved [...]]]></description>
			<content:encoded><![CDATA[<p>Rails allows you to create <a href="http://wiki.rubyonrails.org/rails/pages/ActiveRecordYamlFixtures">data fixtures</a> which can contain test data which is used during unit tests and gets loaded into a <code>_test</code> database.</p>
<p>It&#8217;s possible to load that data into your <code>_development</code> database so that you can use the same data while looking at your site in the browser. This can be achieved using a <code>rake</code> command.<span id="more-9"></span></p>
<pre>rake db:fixtures:load</pre>
<p>Maintaining your fixtures could become realy tiresome, especially in text mode. So, there&#8217;s a way to generate YAML fixtures from the data. I use the following method to so.</p>
<pre name="code" class="ruby">def table_to_yaml(table_name, key_column = 'name')
  return nil if table_name.nil?

  list = ActiveRecord::Base.connection.select_all(
        "SELECT * FROM #{table_name.to_s} ORDER BY id ASC"
  )

  result = ""

  list.each do |record|
    name = record[key_column.to_s].to_permalink
    name = "_#{name}" if name =~ /^[^a-zA-Z]/
    hash = {}
    hash[name] = record
    result &lt; &lt; hash.to_yaml().gsub(/^---s*$/m, '')
  end

  return result
end</pre>
<p><code>key_column</code> is a column name which will be used to name your records in YAML.</p>
<p>This doesn&#8217;t generate the actual files, but you can grab the output and save it in your fixtures.</p>
]]></content:encoded>
			<wfw:commentRss>http://sameshirteveryday.com/2007/05/13/use-fixtures-for-placeholder-data/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

