<?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>Richard Lawrence &#187; Ruby</title>
	<atom:link href="http://www.richardlawrence.info/tag/ruby/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.richardlawrence.info</link>
	<description>On making software teams happier and more productive</description>
	<lastBuildDate>Fri, 27 Jan 2012 18:41:27 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Cucumber Tip: IRB From Inside a Step Definition</title>
		<link>http://www.richardlawrence.info/2011/12/07/cucumber-tip-irb-from-inside-a-step-definition/</link>
		<comments>http://www.richardlawrence.info/2011/12/07/cucumber-tip-irb-from-inside-a-step-definition/#comments</comments>
		<pubDate>Wed, 07 Dec 2011 20:05:35 +0000</pubDate>
		<dc:creator>Richard Lawrence</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Cucumber]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://www.richardlawrence.info/?p=401</guid>
		<description><![CDATA[Most Ruby programmers know about Ruby&#8217;s interactive console, IRB. (If you don&#8217;t, stop right here, open up a command window and run irb. Type some Ruby code. See how it returns the result of each line right away.) IRB is great for poking around with unfamiliar libraries. Suppose you&#8217;re using Capybara with Cucumber for the [...]


Related posts:<ol><li><a href='http://www.richardlawrence.info/2010/01/12/debugging-cuke4nuke-step-definitions/' rel='bookmark' title='Permanent Link: Debugging Cuke4Nuke Step Definitions'>Debugging Cuke4Nuke Step Definitions</a></li>
<li><a href='http://www.richardlawrence.info/2011/08/20/getting-started-with-ruby-cucumber-and-capybara-on-windows/' rel='bookmark' title='Permanent Link: Getting Started with Ruby, Cucumber, and Capybara on Windows'>Getting Started with Ruby, Cucumber, and Capybara on Windows</a></li>
<li><a href='http://www.richardlawrence.info/2011/10/27/cucumber-tip-key-value-tables/' rel='bookmark' title='Permanent Link: Cucumber Tip: Key-Value Tables'>Cucumber Tip: Key-Value Tables</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p></p><p>Most Ruby programmers know about Ruby&#8217;s interactive console, IRB. (If you don&#8217;t, stop right here, open up a command window and run <code class="codecolorer text default"><span class="text">irb</span></code>. Type some Ruby code. See how it returns the result of each line right away.) IRB is great for poking around with unfamiliar libraries.</p>
<p>Suppose you&#8217;re using Capybara with Cucumber for the first time. It would be nice to use IRB to experiment with what Capybara can do on a particular page. You could launch an IRB session and duplicate all the Capybara setup from your Cucumber <code class="codecolorer text default"><span class="text">support/env.rb</span></code> file. But wouldn&#8217;t it be nice if you could just fire up IRB in the context of a step definition so you know everything in your IRB session matches what you&#8217;d get in the step def? Turns out you can. Here&#8217;s how&#8230;<span id="more-401"></span></p>
<p>Install the ruby-debug gem. If you&#8217;re using Ruby 1.9 like me, you need the ruby-debug19 gem. In Rails 3, just add <code class="codecolorer text default"><span class="text">gem ruby-debug19</span></code> to your Gemfile, probably in the test group, and run <code class="codecolorer text default"><span class="text">bundle install</span></code>.</p>
<p>Require ruby-debug in <code class="codecolorer text default"><span class="text">support/env.rb</span></code>.</p>
<p>Add <code class="codecolorer text default"><span class="text">breakpoint</span></code> where you want to jump into IRB. For example:</p>
<div class="codecolorer-container ruby default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Given <span style="color:#006600; font-weight:bold;">/</span>^I am on the advanced search page$<span style="color:#006600; font-weight:bold;">/</span> <span style="color:#9966CC; font-weight:bold;">do</span><br />
&nbsp; visit <span style="color:#996600;">'http://http://www.google.com/advanced_search'</span><br />
&nbsp; breakpoint<br />
&nbsp; <span style="color:#006666;">0</span><br />
<span style="color:#9966CC; font-weight:bold;">end</span></div></td></tr></tbody></table></div>
<p>(Note the extra line after <code class="codecolorer text default"><span class="text">breakpoint</span></code> with <code class="codecolorer text default"><span class="text">0</span></code> on it. <code class="codecolorer text default"><span class="text">breakpoint</span></code> breaks before executing the next line, so if it&#8217;s the last thing in a block, you won&#8217;t jump into the debugger in the context you expect; <code class="codecolorer text default"><span class="text">0</span></code> is a dummy line to keep us in the right context.)</p>
<p>Run Cucumber like normal. When it reaches <code class="codecolorer text default"><span class="text">breakpoint</span></code>, ruby-debug will take over, and you&#8217;ll see a prompt like this: <code class="codecolorer text default"><span class="text">(rdb:1)</span></code>.</p>
<p>You can do a lot of different things at this prompt, but we only care about one right now: type <code class="codecolorer text default"><span class="text">irb</span></code> and hit Enter. Now you should see a an IRB prompt. You&#8217;re in the context of a Cucumber step definition. Type <code class="codecolorer text default"><span class="text">self</span></code> and hit Enter. You&#8217;ll see that <code class="codecolorer text default"><span class="text">self</span></code> is an instance of Cucumber&#8217;s World with various things mixed in. From here, you can do anything you would do inside that step definition.</p>
<p>When you&#8217;re done, run <code class="codecolorer text default"><span class="text">quit</span></code> to get out of IRB and <code class="codecolorer text default"><span class="text">continue</span></code> to get out of the debugger. Cucumber execution will continue like normal. Keep in mind, though, that if you change the state of your system from IRB, you might not get the test results you expect.</p>
<p>Enhancements and variations for you to explore:</p>
<ul>
<li>Make IRB nicer to use with gems such as irbtools</li>
<li>Create a step definition just for launching the debugger</li>
<li>Create a tagged scenario just for launching the debugger</li>
</ul>


<p>Related posts:<ol><li><a href='http://www.richardlawrence.info/2010/01/12/debugging-cuke4nuke-step-definitions/' rel='bookmark' title='Permanent Link: Debugging Cuke4Nuke Step Definitions'>Debugging Cuke4Nuke Step Definitions</a></li>
<li><a href='http://www.richardlawrence.info/2011/08/20/getting-started-with-ruby-cucumber-and-capybara-on-windows/' rel='bookmark' title='Permanent Link: Getting Started with Ruby, Cucumber, and Capybara on Windows'>Getting Started with Ruby, Cucumber, and Capybara on Windows</a></li>
<li><a href='http://www.richardlawrence.info/2011/10/27/cucumber-tip-key-value-tables/' rel='bookmark' title='Permanent Link: Cucumber Tip: Key-Value Tables'>Cucumber Tip: Key-Value Tables</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.richardlawrence.info/2011/12/07/cucumber-tip-irb-from-inside-a-step-definition/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Getting Started with Ruby, Cucumber, and Capybara on Windows</title>
		<link>http://www.richardlawrence.info/2011/08/20/getting-started-with-ruby-cucumber-and-capybara-on-windows/</link>
		<comments>http://www.richardlawrence.info/2011/08/20/getting-started-with-ruby-cucumber-and-capybara-on-windows/#comments</comments>
		<pubDate>Sat, 20 Aug 2011 15:23:20 +0000</pubDate>
		<dc:creator>Richard Lawrence</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Capybara]]></category>
		<category><![CDATA[Cucumber]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://www.richardlawrence.info/?p=348</guid>
		<description><![CDATA[The Ruby version of Cucumber isn&#8217;t just for Rails developers. If you have a .NET or Java web or service app, Ruby can be a great language for testing. With libraries like Capybara for driving web apps and JSON, RestClient, SOAP, and others for interacting with service apps, you&#8217;ll find testing in Ruby requires much [...]


Related posts:<ol><li><a href='http://www.richardlawrence.info/2009/12/30/the-latest-on-cuke4nuke/' rel='bookmark' title='Permanent Link: The Latest on Cuke4Nuke'>The Latest on Cuke4Nuke</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p></p><p>The Ruby version of Cucumber isn&#8217;t just for Rails developers. If you have a .NET or Java web or service app, Ruby can be a great language for testing. With libraries like Capybara for driving web apps and JSON, RestClient, SOAP, and others for interacting with service apps, you&#8217;ll find testing in Ruby requires much less code than in C# or Java.</p>
<p>It can be hard to find instructions for setting up Ruby and Cucumber on Windows, though, so I&#8217;ve compiled these to help my clients get started, and I thought they might be useful to others. I&#8217;ve tested this on a clean Windows 7 VM, and everything works. Your mileage may vary, but let me know if you have any issues. <span id="more-348"></span></p>
<ol>
<li>You&#8217;re going to be working in a command window quite a bit with Cucumber. You may want to customize your command window to make it more pleasant to use. I like the following settings (right click on the top left corner of the command window and choose Properties to set these):<br />
Font: Consolas, 20pt<br />
Screen Buffer: 120&#215;3000<br />
Window Size: 120&#215;60</p>
<p>On a smaller screen, you&#8217;ll of course want a smaller window size and screen buffer. If you&#8217;re on an earlier version of Windows, you won&#8217;t be able to choose Consolas for the font, but Lucida Console is still better than the default.</p>
<p>I also like to set a PROMPT environment variable to <code class="codecolorer text default"><span class="text">$P$_$+$G</span></code> (right click on My Computer and choose Properties, then Advanced, then Environment Variables).</li>
<li> Download and install Ruby. For Windows, <a href="http://rubyinstaller.org/">http://rubyinstaller.org/</a> is the best option. Install the latest release of version 1.9.2. Make sure you check the option to &#8220;Add Ruby executables to your PATH.&#8221;</li>
<li> Also install the Ruby Development Kit from the same place, which will allow Ruby to build native extensions for libraries. Instructions are available here: <a href="https://github.com/oneclick/rubyinstaller/wiki/Development-Kit">https://github.com/oneclick/rubyinstaller/wiki/Development-Kit</a>.</li>
<li> Confirm that the installation worked by opening a command window and running <code class="codecolorer text default"><span class="text">ruby -v</span></code>. You should see a description of the Ruby version installed. If you see an error, something went wrong with the installation.</li>
<li> Make sure you have RubyGems installed by running <code class="codecolorer text default"><span class="text">gem -v</span></code> on a command line. RubyGems is the package manager for Ruby and should come with the standard Ruby installation.</li>
<li> Run <code class="codecolorer text default"><span class="text">gem install cucumber</span></code> to download and install Cucumber. Run <code class="codecolorer text default"><span class="text">cucumber --help</span></code> to confirm that it worked.</li>
<li> Cucumber complains that you need ANSICON to get console colors because Windows doesn&#8217;t understand ANSI color escape sequences. Download ANSICON from <a href="http://adoxa.110mb.com/ansicon/index.html">http://adoxa.110mb.com/ansicon/index.html</a>. Extract it somewhere (I put it in c:\utils\). In your command window, <code class="codecolorer text default"><span class="text">cd</span></code> to either the x86 or x64 directory where you extracted ANSICON, depending on your OS, and run <code class="codecolorer text default"><span class="text">ansicon -i</span></code>. Exit that command window and open a new one. Now, when you run <code class="codecolorer text default"><span class="text">cucumber --help</span></code>, you should no longer see the message in the output about needing ANSICON.</li>
<li> Run <code class="codecolorer text default"><span class="text">gem install capybara</span></code> to download and install the Capybara web automation library.</li>
<li> Run <code class="codecolorer text default"><span class="text">gem install rspec</span></code> to download and install a nice library for readable assertions (among other things).</li>
<li> You&#8217;ll want <a href="http://www.getfirefox.com/">Firefox</a> with the <a href="http://www.getfirebug.com/">Firebug</a> plugin to do UI-related tests. If you haven&#8217;t already, install those.</li>
<li> You can edit Cucumber tests and automation code in Notepad, Visual Studio, or any other text editor. But I like having an editor that knows about Cucumber and provides Cucumber-oriented features, so I use <a href="http://www.jetbrains.com/ruby/">JetBrains RubyMine</a> to work with my Cucumber tests. There&#8217;s a free 30 day trial available.</li>
<li> To make sure Cucumber and Capybara are working nicely together, download and extract this <a href="http://www.richardlawrence.info/wp-content/uploads/2011/08/ruby-capybara.zip">Ruby, Cucumber, and Capybara Starter Project</a> somewhere on your machine. Open a command window at the root of the folder (if you run <code class="codecolorer text default"><span class="text">dir</span></code> or <code class="codecolorer text default"><span class="text">ls</span></code> there, you should see a &#8220;features&#8221; folder). Run <code class="codecolorer text default"><span class="text">cucumber</span></code>, and you should see all the tests run and pass.</li>
</ol>


<p>Related posts:<ol><li><a href='http://www.richardlawrence.info/2009/12/30/the-latest-on-cuke4nuke/' rel='bookmark' title='Permanent Link: The Latest on Cuke4Nuke'>The Latest on Cuke4Nuke</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.richardlawrence.info/2011/08/20/getting-started-with-ruby-cucumber-and-capybara-on-windows/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Another Look at WatiN</title>
		<link>http://www.richardlawrence.info/2009/01/24/another-look-at-watin/</link>
		<comments>http://www.richardlawrence.info/2009/01/24/another-look-at-watin/#comments</comments>
		<pubDate>Sat, 24 Jan 2009 16:29:50 +0000</pubDate>
		<dc:creator>Richard Lawrence</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[agile]]></category>
		<category><![CDATA[Agile 2009]]></category>
		<category><![CDATA[patterns]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[testing]]></category>
		<category><![CDATA[WatiN]]></category>
		<category><![CDATA[Watir]]></category>

		<guid isPermaLink="false">http://www.richardlawrence.info/?p=115</guid>
		<description><![CDATA[At my current client, we&#8217;ve decided to use WatiN, largely for the C# vs. Ruby reason I discussed earlier this week. After spending a week working with WatiN (following a year of rarely using it), I&#8217;m impressed. Ruby and the active Watir community still have their advantages. But WatiN has really come into its own [...]


Related posts:<ol><li><a href='http://www.richardlawrence.info/2009/01/19/web-testing-for-net-teams-watin-or-watir/' rel='bookmark' title='Permanent Link: Web Testing for .NET Teams: WatiN or Watir?'>Web Testing for .NET Teams: WatiN or Watir?</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p></p><p>At my current client, we&#8217;ve decided to use <a href="http://watin.sourceforge.net/">WatiN</a>, largely for the C# vs. Ruby reason I <a href="/2009/01/19/web-testing-for-net-teams-watin-or-watir/">discussed earlier this week</a>. After spending a week working with WatiN (following a year of rarely using it), I&#8217;m impressed. Ruby and the active Watir community still have their advantages. But WatiN has really come into its own with C# 3.0 features like lambdas. I&#8217;m pleased with the test code we&#8217;re producing in terms of readability, speed, flexibility, and maintainability. I&#8217;ve proposed an <a href="http://agile2009.agilealliance.org/">Agile 2009</a> tutorial <a title="Please log in and add comments on my session proposal." href="http://agile2009.agilealliance.org/node/505">session</a> on the patterns I&#8217;m using to get those results, and I&#8217;ll post more on that topic here soon. (Which will hopefully help with one of WatiN&#8217;s shortcomings—documentation.)</p>


<p>Related posts:<ol><li><a href='http://www.richardlawrence.info/2009/01/19/web-testing-for-net-teams-watin-or-watir/' rel='bookmark' title='Permanent Link: Web Testing for .NET Teams: WatiN or Watir?'>Web Testing for .NET Teams: WatiN or Watir?</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.richardlawrence.info/2009/01/24/another-look-at-watin/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
	</channel>
</rss>

