<?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>Otaqui.Com &#187; ruby</title>
	<atom:link href="http://otaqui.com/blog/tag/ruby/feed/" rel="self" type="application/rss+xml" />
	<link>http://otaqui.com/blog</link>
	<description>Pete Otaqui's blog about web development and everything else</description>
	<lastBuildDate>Wed, 23 Jun 2010 09:55:31 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Custom User Agent with Cucumber Tests and Webrat in Mechanize Mode</title>
		<link>http://otaqui.com/blog/541/custom-user-agent-with-cucumber-tests-and-webrat-in-mechanize-mode/</link>
		<comments>http://otaqui.com/blog/541/custom-user-agent-with-cucumber-tests-and-webrat-in-mechanize-mode/#comments</comments>
		<pubDate>Mon, 08 Mar 2010 12:08:50 +0000</pubDate>
		<dc:creator>pete</dc:creator>
				<category><![CDATA[Professional]]></category>
		<category><![CDATA[cucumber]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[testing]]></category>
		<category><![CDATA[webdev]]></category>

		<guid isPermaLink="false">http://otaqui.com/blog/?p=541</guid>
		<description><![CDATA[It&#8217;s pretty straightforward to set a custom user agent with mechanize if you&#8217;re using it directly, KickAssLabs has a good example. If you&#8217;re using Mechanize through Webrat though, things are a little different. The nice thing though, is that you can do this in a step definition &#8211; allowing features to be based on different [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s pretty straightforward to set a custom user agent with mechanize if you&#8217;re using it directly, <a href="http://www.kickasslabs.com/2009/03/31/quick-hits-setting-the-user-agent-header-in-webrat/">KickAssLabs has a good example</a>.</p>
<p>If you&#8217;re using Mechanize through Webrat though, things are a little different.  The nice thing though, is that you can do this in a step definition &#8211; allowing features to be based on different browser scenarios (this is great if you&#8217;re developing across devices).</p>
<p>First off there are two accessors of interest in mechanize, &#8220;user_agent&#8221; and &#8220;user_agent_alias&#8221;.  The former is fairly self evident and lets you define the user agent at will, the latter gives you shortcut access to a list of common user agents baked into mechanize.  You can see that list in <a href="http://github.com/tenderlove/mechanize/blob/master/lib/mechanize.rb#L48">the mechanize.rb source</a>.  It contains some desktop browsers, the iPhone and the default Mechanize UA strings.</p>
<p>If you&#8217;re happy with the default alias list, you can just write a step definition like this:</p>
<pre class="brush: ruby">
Given /^I am using the &quot;(.*)&quot; browser$/ do |browser|
  webrat.adapter.mechanize.user_agent_alias = browser
end
</pre>
<p>And then you can use this in your features:</p>
<pre class="brush: text">
Given I am using the &quot;iPhone&quot; browser
When I visit the home page
Then I should see &quot;You are using an iPhone!&quot;
</pre>
<p>If you want to be able to specify your own UA strings, and as I said this is especially likely if you are developing cross-device applications where capabilities are important, then you can just use your own hash instead, and set &#8220;user_agent&#8221; rather than &#8220;user_agent_alias&#8221;:</p>
<pre class="brush: ruby">
Given /^I am using the &quot;(.*)&quot; browser$/ do |browser|
  UA_ALIASES = {
    &quot;Nokia N95&quot; =&gt; &quot;Mozilla/5.0 (SymbianOS/9.2; .....&quot;,
    &quot;Palm Pre&quot; =&gt; &quot;Mozilla/5.0 (webOS/1.0; .....&quot;
  }
  webrat.adapter.mechanize.user_agent = UA_ALIASES[browser]
end
</pre>
<p>With a little tweaking you could use both the included list and, if the string from your feature isn&#8217;t there, look in a custom list too.</p>
]]></content:encoded>
			<wfw:commentRss>http://otaqui.com/blog/541/custom-user-agent-with-cucumber-tests-and-webrat-in-mechanize-mode/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using a Proxy with Cucumber, Webrat and Mechanize</title>
		<link>http://otaqui.com/blog/458/using-a-proxy-with-cucumber-webrat-and-mechanize/</link>
		<comments>http://otaqui.com/blog/458/using-a-proxy-with-cucumber-webrat-and-mechanize/#comments</comments>
		<pubDate>Thu, 17 Dec 2009 08:15:36 +0000</pubDate>
		<dc:creator>pete</dc:creator>
				<category><![CDATA[Professional]]></category>
		<category><![CDATA[cucumber]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[webdev]]></category>

		<guid isPermaLink="false">http://otaqui.com/blog/?p=458</guid>
		<description><![CDATA[If you&#8217;re writing Cucumber tests using Webrat and Mechanize to test a site, and you are behind a proxy server, you can do something like this to tell mechanize about it in your webrat_steps.rb file: When /^I am on (.+)$/ do &#124;page_name&#124; webrat.adapter.mechanize.set_proxy('proxy.host.com',8080) visit path_to(page_name) end I&#8217;m sure there&#8217;s a tidier way to do this, [...]]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;re writing Cucumber tests using Webrat and Mechanize to test a site, and you are behind a proxy server, you can do something like this to tell mechanize about it in your webrat_steps.rb file:</p>
<p><code><br />
When /^I am on (.+)$/ do |page_name|<br />
    webrat.adapter.mechanize.set_proxy('proxy.host.com',8080)<br />
    visit path_to(page_name)<br />
end<br />
</code></p>
<p>I&#8217;m sure there&#8217;s a tidier way to do this, but it&#8217;s quick and it works with the following gem versions:</p>
<p>Cucumber 0.3.11<br />
Webrat 0.5.3<br />
Mechanize 0.9.3</p>
]]></content:encoded>
			<wfw:commentRss>http://otaqui.com/blog/458/using-a-proxy-with-cucumber-webrat-and-mechanize/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Cucumber with Webrat and Mechanize on CentOS 5</title>
		<link>http://otaqui.com/blog/449/cucumber-with-webrat-and-mechanize-on-centos-5/</link>
		<comments>http://otaqui.com/blog/449/cucumber-with-webrat-and-mechanize-on-centos-5/#comments</comments>
		<pubDate>Fri, 20 Nov 2009 13:55:38 +0000</pubDate>
		<dc:creator>pete</dc:creator>
				<category><![CDATA[Professional]]></category>
		<category><![CDATA[command-line]]></category>
		<category><![CDATA[cucumber]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://otaqui.com/blog/?p=449</guid>
		<description><![CDATA[Thanks to Chris for this one. The trick is to use JRuby and its gems, and also to install libxml2-devel $ cd ~ $ wget http://jruby.kenai.com/downloads/1.4.0/jruby-bin-1.4.0.tar.gz $ tar -C /usr/local/ -xzvf jruby-bin-1.4.0.tar.gz You should now have Jruby. Add it&#8217;s bin directory to your path, presumably in your ~/.bash_profile file: $ export PATH=$PATH:/usr/local/jruby-1.4.0/bin $ jruby -v [...]]]></description>
			<content:encoded><![CDATA[<p>Thanks to <a href="http://blog.chrislowis.co.uk/">Chris</a> for this one.</p>
<p>The trick is to use JRuby and its gems, and also to install libxml2-devel</p>
<p><code>$ cd ~<br />
$ wget http://jruby.kenai.com/downloads/1.4.0/jruby-bin-1.4.0.tar.gz<br />
$ tar -C /usr/local/ -xzvf jruby-bin-1.4.0.tar.gz</code></p>
<p>You should now have Jruby.  Add it&#8217;s bin directory to your path, presumably in your ~/.bash_profile file:<br />
<code>$ export PATH=$PATH:/usr/local/jruby-1.4.0/bin<br />
$ jruby -v</code></p>
<p>Now install some mechanize requirements:<br />
<code>$ sudo yum install libxml2-devel libxslt-devel</code></p>
<p>If you <strong>don&#8217;t</strong> already have the &#8220;normal&#8221; ruby installed, you can get to the jruby &#8220;gem&#8221; command by just typing &#8220;gem&#8221;.  If you do have ruby, or want to be absolutely sure, type the commands like this:<br />
<code>$ jruby -S gem install cucumber mechanize webrat</code></p>
<p>You&#8217;re good to go!  You should now be able to run your features with:</p>
<p><code>$ cucumber features/</code></p>
]]></content:encoded>
			<wfw:commentRss>http://otaqui.com/blog/449/cucumber-with-webrat-and-mechanize-on-centos-5/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
