<?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>The Lucid &#187; Rails</title>
	<atom:link href="http://thelucid.com/category/rails/feed/" rel="self" type="application/rss+xml" />
	<link>http://thelucid.com</link>
	<description>The Lightweight Ramblings of Jamie Hill</description>
	<lastBuildDate>Sun, 11 Mar 2012 19:52:46 +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 both Pow and Apache on OSX Lion</title>
		<link>http://thelucid.com/2012/03/11/using-both-pow-and-apache-on-osx-lion/</link>
		<comments>http://thelucid.com/2012/03/11/using-both-pow-and-apache-on-osx-lion/#comments</comments>
		<pubDate>Sun, 11 Mar 2012 19:33:17 +0000</pubDate>
		<dc:creator>Jamie</dc:creator>
				<category><![CDATA[Bash]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[pow]]></category>

		<guid isPermaLink="false">http://thelucid.com/?p=787</guid>
		<description><![CDATA[I have written previously about using Pow for Ruby/Rails development. Pow is great if you are purely developing in Ruby, however I&#8217;ve recently found myself needing to edit a WordPress site. Pow intercepts requests to port 80 by default meaning that no requests can make it through to the default Apache installation on OSX. I&#8217;ve [...]]]></description>
			<content:encoded><![CDATA[<p>I have written previously about <a href="http://thelucid.com/2012/01/01/using-pow-when-developing-rails-applications-on-osx/">using Pow for Ruby/Rails development</a>. Pow is great if you are purely developing in Ruby, however I&#8217;ve recently found myself needing to edit a WordPress site.</p>
<p>Pow intercepts requests to port 80 by default meaning that no requests can make it through to the default Apache installation on OSX. I&#8217;ve found the best way around this is to disable Pow whenever developing in PHP. The <a href="https://github.com/rodreegez/powder">powder gem</a> handles this nicely, so:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">gem <span style="color: #c20cb9; font-weight: bold;">install</span> powder</pre></div></div>

<p>Now you can now disable Pow with the following, therefore letting requests through to Apache (assuming you have it enabled):</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">powder down</pre></div></div>

<p>And once you&#8217;re done with the PHP development, enable it again with:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">powder up</pre></div></div>

<p>As a side note, I usually leave Apache disabled by default i.e. uncheck &#8220;Web Sharing&#8221; within the &#8220;Sharing&#8221; section of System Preferences until I am going to be doing some PHP development.</p>
<p>Hope this saves someone some time figuring out how to disable/enable Pow.</p>
]]></content:encoded>
			<wfw:commentRss>http://thelucid.com/2012/03/11/using-both-pow-and-apache-on-osx-lion/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Loving MongoDB but Missing Transactions</title>
		<link>http://thelucid.com/2012/01/26/loving-mongodb-but-missing-transactions/</link>
		<comments>http://thelucid.com/2012/01/26/loving-mongodb-but-missing-transactions/#comments</comments>
		<pubDate>Thu, 26 Jan 2012 13:52:28 +0000</pubDate>
		<dc:creator>Jamie</dc:creator>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[MongoDB]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[mongodb]]></category>
		<category><![CDATA[mongoid]]></category>
		<category><![CDATA[schema]]></category>
		<category><![CDATA[transactions]]></category>

		<guid isPermaLink="false">http://thelucid.com/?p=783</guid>
		<description><![CDATA[I&#8217;ve been venturing into the world of MongoDB via Mongoid in a Rails app. On one hand it&#8217;s a breath of fresh air (no migrations, flexible schemas etc.) but on the other hand I really, really miss transactions. If somebody asked me if I used transactions much in MySQL, I would probably have said no&#8230; [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been venturing into the world of <a href="http://www.mongodb.org">MongoDB</a> via <a href="http://mongoid.org/">Mongoid</a> in a Rails app. On one hand it&#8217;s a breath of fresh air (no migrations, flexible schemas etc.) but on the other hand I really, really miss transactions.</p>
<p>If somebody asked me if I used transactions much in MySQL, I would probably have said no&#8230; however, now that I don&#8217;t have them I realise just how much I used them. Things that just work when using <a href="http://api.rubyonrails.org/classes/ActiveRecord/Base.html">ActiveRecord</a> such as creating a record and ensuring that an associated record gets created is sooo much harder.</p>
<p>MongoDB has &#8220;<a href="http://www.mongodb.org/display/DOCS/Atomic+Operations">Atomic Operations</a>&#8221; which means if you have an embedded relationship, all is good and the database will be rolled back if the entire document does not save. As soon as you have two top level collections and need to ensure that a record is created in both, things get a little hairy.</p>
<p>There seems to be a great deal of &#8220;if you need transactions just use a RDBMS&#8221; talk but what if you need a flexible schema and transactions, the last thing you want to manage is some kind of <a href="http://www.magentocommerce.com/wiki/2_-_magento_concepts_and_architecture/magento_database_diagram">EAV system like Magento</a>.</p>
<p>I&#8217;ve created <a href="http://groups.google.com/group/mongodb-user/browse_thread/thread/10da4c2571142671">a thread on the Mongo User forum</a> with a typical example so feel free to join in the discussion. I&#8217;d love to hear experienced Mongo user&#8217;s views on how to overcome these kinds of situations and what kind of applications people are running with MongoDB.</p>
]]></content:encoded>
			<wfw:commentRss>http://thelucid.com/2012/01/26/loving-mongodb-but-missing-transactions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using Pow when developing Rails applications on OSX</title>
		<link>http://thelucid.com/2012/01/01/using-pow-when-developing-rails-applications-on-osx/</link>
		<comments>http://thelucid.com/2012/01/01/using-pow-when-developing-rails-applications-on-osx/#comments</comments>
		<pubDate>Sun, 01 Jan 2012 15:17:03 +0000</pubDate>
		<dc:creator>Jamie</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Mac / OS X]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[mac]]></category>
		<category><![CDATA[osx]]></category>
		<category><![CDATA[pow]]></category>
		<category><![CDATA[rack]]></category>
		<category><![CDATA[server]]></category>

		<guid isPermaLink="false">http://thelucid.com/?p=768</guid>
		<description><![CDATA[I heard about Pow a while ago which is &#8220;a zero-config Rack server for Mac OS X&#8221; but never got around to giving it a go. I&#8217;ve just installed it and can instantly see that it is going to make developing with Rails (or any Rack app) a whole lot nicer, especially when dealing with [...]]]></description>
			<content:encoded><![CDATA[<p>I heard about <a href="http://pow.cx" rel="external">Pow</a> a while ago which is &#8220;a zero-config Rack server for Mac OS X&#8221; but never got around to giving it a go. I&#8217;ve just installed it and can instantly see that it is going to make developing with Rails (or any Rack app) a whole lot nicer, especially when dealing with apps that use subdomain account keys.</p>
<p>If you&#8217;ve not tried it yet, head over to <a href="http://pow.cx" rel="external">the Pow website</a> and get it installed with:</p>
<p><code lang="bash">curl get.pow.cx | sh</code></p>
<p>Happy new year everyone!</p>
]]></content:encoded>
			<wfw:commentRss>http://thelucid.com/2012/01/01/using-pow-when-developing-rails-applications-on-osx/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Cucumber&#8217;s &#8220;tableish&#8221; depreciated</title>
		<link>http://thelucid.com/2011/11/22/cucumbers-tableish-depreciated/</link>
		<comments>http://thelucid.com/2011/11/22/cucumbers-tableish-depreciated/#comments</comments>
		<pubDate>Tue, 22 Nov 2011 16:14:41 +0000</pubDate>
		<dc:creator>Jamie</dc:creator>
				<category><![CDATA[Cucumber]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[capybara]]></category>
		<category><![CDATA[tableish]]></category>

		<guid isPermaLink="false">http://thelucid.com/?p=761</guid>
		<description><![CDATA[I was just running some cucumber features on an old project and came across a problem whereby &#8220;tableish&#8221; has been depreciated in Cucumber. Dennis Reimann has posted a nice alternative here using Capybara&#8230; thanks Dennis.]]></description>
			<content:encoded><![CDATA[<p>I was just running some cucumber features on an old project and came across a problem whereby <a href="https://github.com/cucumber/cucumber-rails/issues/145">&#8220;tableish&#8221; has been depreciated in Cucumber</a>.</p>
<p>Dennis Reimann has posted a <a href="http://dennisreimann.de/blog/capybara-finder-for-cucumber-rails-deprecated-tableish/">nice alternative here using Capybara</a>&#8230; thanks Dennis.</p>
]]></content:encoded>
			<wfw:commentRss>http://thelucid.com/2011/11/22/cucumbers-tableish-depreciated/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Rails 3 and the little known :enable_starttls_auto option</title>
		<link>http://thelucid.com/2011/01/17/rails-3-and-the-little-known-enable_starttls_auto-option/</link>
		<comments>http://thelucid.com/2011/01/17/rails-3-and-the-little-known-enable_starttls_auto-option/#comments</comments>
		<pubDate>Mon, 17 Jan 2011 15:01:39 +0000</pubDate>
		<dc:creator>Jamie</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[actionmailer]]></category>
		<category><![CDATA[rails 3]]></category>

		<guid isPermaLink="false">http://thelucid.com/?p=725</guid>
		<description><![CDATA[I just got the following error from ActionMailer when trying to send to a Gmail address: OpenSSL::SSL::SSLError (hostname was not match with the server certificate) After some Googling I found the &#8220;enable_starttls_auto&#8221; option in ActionMailer, setting this to &#8220;false&#8221; in the relevant environment file fixed the problem: config.action_mailer.smtp_settings = &#123; :address =&#62; '...', :user_name =&#62; [...]]]></description>
			<content:encoded><![CDATA[<p>I just got the following error from ActionMailer when trying to send to a Gmail address:</p>
<pre>
OpenSSL::SSL::SSLError (hostname was not match with the server certificate)
</pre>
<p>After some Googling I found the &#8220;enable_starttls_auto&#8221; option in ActionMailer, setting this to &#8220;false&#8221; in the relevant environment file fixed the problem:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">  config.<span style="color:#9900CC;">action_mailer</span>.<span style="color:#9900CC;">smtp_settings</span> = <span style="color:#006600; font-weight:bold;">&#123;</span>
    <span style="color:#ff3333; font-weight:bold;">:address</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'...'</span>,
    <span style="color:#ff3333; font-weight:bold;">:user_name</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'...'</span>,
    <span style="color:#ff3333; font-weight:bold;">:domain</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'...'</span>,
    <span style="color:#ff3333; font-weight:bold;">:password</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'...'</span>,
    <span style="color:#ff3333; font-weight:bold;">:authentication</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:login</span>,
    <span style="color:#ff3333; font-weight:bold;">:enable_starttls_auto</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">false</span>
  <span style="color:#006600; font-weight:bold;">&#125;</span></pre></div></div>

<p>This option apparently &#8220;Enables SMTP/TLS (STARTTLS) for this object if server accepts&#8221;. Not being up on my &#8220;SMTP/TLS&#8221;&#8216;s, I have no idea what this means but it solves the problem.</p>
<p>Hope this saves someone some time.</p>
]]></content:encoded>
			<wfw:commentRss>http://thelucid.com/2011/01/17/rails-3-and-the-little-known-enable_starttls_auto-option/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Fixing {{model}} placeholders in Rails 2.3 when Rails 3 is installed</title>
		<link>http://thelucid.com/2011/01/14/fixing-model-placeholders-in-rails-2-3-when-rails-3-is-installed/</link>
		<comments>http://thelucid.com/2011/01/14/fixing-model-placeholders-in-rails-2-3-when-rails-3-is-installed/#comments</comments>
		<pubDate>Fri, 14 Jan 2011 15:13:19 +0000</pubDate>
		<dc:creator>Jamie</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[SonicIQ]]></category>
		<category><![CDATA[bug]]></category>
		<category><![CDATA[internationalization]]></category>
		<category><![CDATA[rack]]></category>
		<category><![CDATA[rails 2.3]]></category>
		<category><![CDATA[rails 3]]></category>

		<guid isPermaLink="false">http://thelucid.com/?p=721</guid>
		<description><![CDATA[This was causing me all kinds of grief. I am running Rails 2.3 and Rails 3 apps on the same server and on installing Rails 3, the Rails 2.3 apps started displaying {{model}} and similar strings in views. It turns out that Rails 3 uses i18n version 0.5.0 and with this version as far as [...]]]></description>
			<content:encoded><![CDATA[<p>This was causing me all kinds of grief. I am running Rails 2.3 and Rails 3 apps on the same server and on installing Rails 3, the Rails 2.3 apps started displaying {{model}} and similar strings in views.</p>
<p>It turns out that Rails 3 uses i18n version 0.5.0 and with this version as far as I can see, the placeholder text in translations follow the %{text} format instead of the {{text}} format in 0.4.2 which Rails 2.3 was using. The only way I found to fix this was to declare the specific i18n version before the Rails gem gets required in the &#8220;load_rails_gem&#8221; method of &#8220;config/boot.rb&#8221; in my Rails 2.3 apps:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">def</span> load_rails_gem
  gem <span style="color:#996600;">'i18n'</span>, <span style="color:#996600;">'0.4.2'</span> <span style="color:#008000; font-style:italic;"># Add this line</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">if</span> version...
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>Doing this specifies that we want i18n 0.4.2 exactly, whereas Rails 2.3 specifies version &#8220;>= 0.1.3&#8243; which would obviously includes &#8220;0.5.0&#8243;.</p>
<p>In running Rails 2.3 and Rails 3 apps side by side, I also ran into <a href="https://rails.lighthouseapp.com/projects/8994/tickets/3685-actionpack-235-gem-declares-incompatibility-with-rack-110">this problem</a> and overcame it with the fixes by &#8220;<a href="https://rails.lighthouseapp.com/projects/8994/tickets/3685-actionpack-235-gem-declares-incompatibility-with-rack-110#ticket-3685-8">bct</a>&#8221; and &#8220;<a href="https://rails.lighthouseapp.com/projects/8994/tickets/3685-actionpack-235-gem-declares-incompatibility-with-rack-110#ticket-3685-14">ronin-95281</a>&#8221; in the comments&#8230; apparently Rails Core <a href="https://rails.lighthouseapp.com/projects/8994/tickets/3685-actionpack-235-gem-declares-incompatibility-with-rack-110#ticket-3685-9">won&#8217;t fix this</a>.</p>
<p>If anyone else has a cleaner fix for this I would love to hear about it.</p>
]]></content:encoded>
			<wfw:commentRss>http://thelucid.com/2011/01/14/fixing-model-placeholders-in-rails-2-3-when-rails-3-is-installed/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Ruby Causing MacBook Pro to Run Hot</title>
		<link>http://thelucid.com/2011/01/06/ruby-causing-macbook-pro-to-run-hot/</link>
		<comments>http://thelucid.com/2011/01/06/ruby-causing-macbook-pro-to-run-hot/#comments</comments>
		<pubDate>Thu, 06 Jan 2011 08:24:14 +0000</pubDate>
		<dc:creator>Jamie</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Mac / OS X]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[fan]]></category>
		<category><![CDATA[hot]]></category>
		<category><![CDATA[mac]]></category>
		<category><![CDATA[osx]]></category>

		<guid isPermaLink="false">http://thelucid.com/?p=704</guid>
		<description><![CDATA[The past couple of days the fan on my MacBook Pro has been constantly on and battery usage down to around a third. Launching Activity Monitor, it showed 3 Ruby processes all at 100% CPU usage. The solution was to force quit these processes and within seconds, the fan slowed up and the battery indicator [...]]]></description>
			<content:encoded><![CDATA[<p>The past couple of days the fan on my MacBook Pro has been constantly on and battery usage down to around a third. Launching Activity Monitor, it showed 3 Ruby processes all at 100% CPU usage. The solution was to force quit these processes and within seconds, the fan slowed up and the battery indicator went up. Force quitting these processes didn&#8217;t affect anything I was doing with Rails or IRB so I guess they were just stray processes.</p>
<p>If anyone else gets the same problem, just launch Activity Monitor which lives in the /Applications/Utilities folder, click the CPU tab if not already selected, select processes with a process name of &#8220;ruby&#8221;, click &#8220;Quit Process&#8221; and then select &#8220;Force Quit&#8221;. Just selecting &#8220;Quit&#8221; wouldn&#8217;t work for me hence the &#8220;Force Quit&#8221;.</p>
<p>I hope this saves someone else the head-scratching as to why their Mac is running hot.</p>
]]></content:encoded>
			<wfw:commentRss>http://thelucid.com/2011/01/06/ruby-causing-macbook-pro-to-run-hot/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Using Artifice to Stub Server Responses</title>
		<link>http://thelucid.com/2011/01/04/using-artifice-to-stub-server-responses/</link>
		<comments>http://thelucid.com/2011/01/04/using-artifice-to-stub-server-responses/#comments</comments>
		<pubDate>Tue, 04 Jan 2011 19:29:59 +0000</pubDate>
		<dc:creator>Jamie</dc:creator>
				<category><![CDATA[Cucumber]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[artifice]]></category>
		<category><![CDATA[mocking]]></category>
		<category><![CDATA[stubbing]]></category>
		<category><![CDATA[test]]></category>
		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">http://thelucid.com/?p=700</guid>
		<description><![CDATA[In a recent project I needed a way to fake a response from a server in my Cucumber features. Specifically, I was testing integration with a payment gateway and wanted to stub it&#8217;s responses based on different requests. In the past I have used FakeWeb, however it becomes a little hairy when you need to [...]]]></description>
			<content:encoded><![CDATA[<p>In a recent project I needed a way to fake a response from a server in my Cucumber features. Specifically, I was testing integration with a payment gateway and wanted to stub it&#8217;s responses based on different requests.</p>
<p>In the past I have used <a href="http://fakeweb.rubyforge.org/">FakeWeb</a>, however it becomes a little hairy when you need to stub a response based on request body. I came across a couple of alternatives, firstly <a href="https://github.com/bblimke/webmock">WebMock</a> which looks promising but then <a href="https://github.com/wycats/artifice">Artifice</a> from the mighty <a href="http://yehudakatz.com/">Yehuda Katz</a> caught my eye&#8230;</p>
<p>Artifice lets you &#8220;replace the Net::HTTP subsystem of Ruby with an equivalent that routes all requests to a Rack application&#8221;. I like the simplicity of this solution as you can in essence use a <a href="https://github.com/rack/rack">Rack</a> application to replace the responses of the service you are testing.</p>
<h3>An Example</h3>
<p>First we create a simple Rack application to stand in for the server we are interacting with.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">app = <span style="color:#CC0066; font-weight:bold;">proc</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>env<span style="color:#006600; font-weight:bold;">|</span>
  <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">200</span>, <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#996600;">&quot;Content-Type&quot;</span>  <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;text/html&quot;</span> <span style="color:#006600; font-weight:bold;">&#125;</span>,
    <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">&quot;Hello world: #{env.inspect}&quot;</span><span style="color:#006600; font-weight:bold;">&#93;</span>
  <span style="color:#006600; font-weight:bold;">&#93;</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>Then we simply use Artifice&#8217;s &#8220;activate_with&#8221; method to wrap any requests.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">Artifice.<span style="color:#9900CC;">activate_with</span><span style="color:#006600; font-weight:bold;">&#40;</span>app<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">do</span>
  response = <span style="color:#6666ff; font-weight:bold;">Net::HTTP</span>.<span style="color:#9900CC;">start</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;google.com&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>http<span style="color:#006600; font-weight:bold;">|</span>
    http.<span style="color:#9900CC;">post</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;/the_url&quot;</span>, <span style="color:#996600;">&quot;foo=bar&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#CC0066; font-weight:bold;">puts</span> response.<span style="color:#9900CC;">body</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>This allows for a Rack app to be used as a stand in for a complete API, it could be a Sinatra app for example allowing for easy route handling. We could go so far as to have a series of Rack apps that can be used as stand-ins for common API&#8217;s.</p>
]]></content:encoded>
			<wfw:commentRss>http://thelucid.com/2011/01/04/using-artifice-to-stub-server-responses/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>&#8220;Ramble&#8221;, the Javascript Cucumber Port (work in progress)</title>
		<link>http://thelucid.com/2010/07/04/ramble-the-javascript-cucumber-port/</link>
		<comments>http://thelucid.com/2010/07/04/ramble-the-javascript-cucumber-port/#comments</comments>
		<pubDate>Sun, 04 Jul 2010 02:27:12 +0000</pubDate>
		<dc:creator>Jamie</dc:creator>
				<category><![CDATA[Ajax]]></category>
		<category><![CDATA[Cucumber]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://thelucid.com/?p=608</guid>
		<description><![CDATA[I am a great fan of Cucumber when it comes to integration testing, however testing heavy use of Javascript can be a little tedious. I have looked into the different solutions out there such as Selenium but found them all to be fiddly to setup, however Capybara helps on this front. I was thinking, what [...]]]></description>
			<content:encoded><![CDATA[<p>I am a great fan of <a href="http://cukes.info/">Cucumber</a> when it comes to integration testing, however testing heavy use of Javascript can be a little tedious.</p>
<p>I have looked into the different solutions out there such as <a href="http://seleniumhq.org/">Selenium</a> but found them all to be fiddly to setup, however <a href="http://github.com/jnicklas/capybara">Capybara</a> helps on this front. I was thinking, what if Cucumber could run in the browser? No need for Javascript adapters or XML parsers, Safari/Chrome/Firefox already do a great job of this. Manipulating the page such as filling in forms, clicking links etc. could all be done with jQuery, in a very concise manor.</p>
<p>I decided to create a proof-of-concept while it was still fresh in my head. This is by no means a fully working release and the code leaves a lot to be desired in it&#8217;s current state, however it shows the benefits of a &#8220;Cucumber in the browser&#8221;. The main benefits I can see so far (for both javascript and non javascript apps) are:</p>
<ul>
<li><strong>Speed</strong> &#8211; browsers are getting extremely quick at this DOM stuff.</li>
<li><strong>Flexibility</strong> &#8211; everything happens client-side meaning you can easily test with any server technology.</li>
<li><strong>Simplicity</strong> &#8211; no need for complex javascript adapters, XML parsers etc.</li>
</ul>
<p>The basic file structure is very similar to Cucumber:</p>
<pre>
  - features
    index.html
    - js
        ramble.js
        jquery-1.4.2.js
      my.feature
    - steps
        web-steps.js
    - support
        paths.js
</pre>
<p>Step definitions can be defined in plain old javascript files with plain old jQuery, in this case web-steps.js. Currently the step definition are expected to throw an error if they cannot be fulfilled, this may change when a solid API is nailed down:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">  <span style="color: #006600; font-style: italic;">// The value of 'this' is the current document as a jQuery object.</span>
  ramble.<span style="color: #660066;">match</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/^I follow &quot;(.+)&quot;$/</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>link_text<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> link <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">find</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'a'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">filter</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000066; font-weight: bold;">return</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">text</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> link_text<span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>link.<span style="color: #660066;">length</span><span style="color: #009900;">&#41;</span> <span style="color: #000066; font-weight: bold;">throw</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Can't find link: &quot;</span> <span style="color: #339933;">+</span> link_text<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    link.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Scenarios are exactly the same as in Cucumber, so you can do something like the following:</p>
<pre>
  Scenario: User fill out a form
    Given I am on the homepage
    And I follow "Tell us your name"
    And I fill in "First name" with "Jamie"
    And I fill in "Last name" with "Hill"
    And I press "Submit"
    Then I should see "Thank you for your details."
</pre>
<p>You can now simply drop the features folder into the public area of your app and visit the url in your browser. You should see the relevant steps go green or red as the app is navigated in an iFrame.</p>
<p>I plan to first tidy up the API (and unit test) and then aid the writing of scenarios by adding the ability to record them within the browser (Selenium style).</p>
<p>I&#8217;d like to hear peoples views on this&#8230; please don&#8217;t be too hard on the code, it&#8217;s more of a mind-dump than anything else at this stage (around 100 lines). There is an example of testing a static site included so just load the features/index.html file in your browser to see it run.</p>
<p>  <a href="http://github.com/soniciq/ramble">http://github.com/soniciq/ramble</a></p>
<p><strong>Update 04/07/10:</strong> As noted by Andrew in the comments, you will need a server running in order for browsers to get access to the pages for testing.</p>
<p>I have added a simple server script allowing the features to be run locally (requires Ruby). If you want to see it in action, just run:</p>
<pre>
cd /path/to/ramble/checkout
ruby server.rb
</pre>
<p>&#8230;and then visit <a href="http://localhost:1234/features">http://localhost:1234/features</a> in your browser (tested in Firefox, Chrome and Safari). Note that Ramble is not at all dependent on Ruby, it is just used for running a local test server.</p>
<h3>Screenshot</h3>
<p><a href="http://thelucid.com/files/ramble-in-action.png"><img src="http://thelucid.com/files/ramble-in-action-300x241.png" alt="Ramble in action" title="Ramble in action" width="300" height="241" class="aligncenter size-medium wp-image-620" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://thelucid.com/2010/07/04/ramble-the-javascript-cucumber-port/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Nokogiri for Cucumber steps that need to compare HTML attributes</title>
		<link>http://thelucid.com/2010/02/14/nokogiri-for-cucumber-steps-that-need-to-compare-html-attributes/</link>
		<comments>http://thelucid.com/2010/02/14/nokogiri-for-cucumber-steps-that-need-to-compare-html-attributes/#comments</comments>
		<pubDate>Sun, 14 Feb 2010 18:07:07 +0000</pubDate>
		<dc:creator>Jamie</dc:creator>
				<category><![CDATA[Cucumber]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[rails cucumber nokogiri ruby]]></category>

		<guid isPermaLink="false">http://thelucid.com/?p=564</guid>
		<description><![CDATA[I have found on numerous occasions that I need to look at HTML attributes when diffing tables etc. in Cucumber. My current need for this arrises as I have a gallery of thumbnails that all have alt tags who&#8217;s values I need to compare as there is not a text equivalent. A feature statement like [...]]]></description>
			<content:encoded><![CDATA[<p>I have found on numerous occasions that I need to look at HTML attributes when diffing tables etc. in Cucumber. My current need for this arrises as I have a gallery of thumbnails that all have alt tags who&#8217;s values I need to compare as there is not a text equivalent.</p>
<p>A feature statement like this:</p>
<pre>
Then I should see the following thumbnails
  | Mona Lisa  |
  | Sunflowers |
</pre>
<p>Could be achieved with the following step:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">Then</span> <span style="color:#006600; font-weight:bold;">/</span>^I should see the following thumbnails$<span style="color:#006600; font-weight:bold;">/</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>table<span style="color:#006600; font-weight:bold;">|</span>
  nodes = <span style="color:#6666ff; font-weight:bold;">Nokogiri::HTML</span><span style="color:#006600; font-weight:bold;">&#40;</span>response.<span style="color:#9900CC;">body</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">css</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'ul#gallery li img'</span><span style="color:#006600; font-weight:bold;">&#41;</span>
  table.<span style="color:#9900CC;">diff</span>!<span style="color:#006600; font-weight:bold;">&#40;</span>nodes.<span style="color:#9900CC;">map</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#006600; font-weight:bold;">|</span>img<span style="color:#006600; font-weight:bold;">|</span> <span style="color:#006600; font-weight:bold;">&#91;</span>img.<span style="color:#9900CC;">attributes</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'alt'</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">to_s</span><span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://thelucid.com/2010/02/14/nokogiri-for-cucumber-steps-that-need-to-compare-html-attributes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

