<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Keep Calm And Carry On</title>
	<atom:link href="http://keep12on.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://keep12on.com</link>
	<description>Just another WordPress.com weblog</description>
	<lastBuildDate>Wed, 03 Jun 2009 09:27:53 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<cloud domain='keep12on.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://www.gravatar.com/blavatar/f6accd9d01b68524ffa5027ebf909d06?s=96&#038;d=http://s2.wp.com/i/buttonw-com.png</url>
		<title>Keep Calm And Carry On</title>
		<link>http://keep12on.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://keep12on.com/osd.xml" title="Keep Calm And Carry On" />
	<atom:link rel='hub' href='http://keep12on.com/?pushpress=hub'/>
		<item>
		<title>Javascript testing in Ruby with Selenium</title>
		<link>http://keep12on.com/2009/06/03/javascript-testing-in-ruby-with-selenium/</link>
		<comments>http://keep12on.com/2009/06/03/javascript-testing-in-ruby-with-selenium/#comments</comments>
		<pubDate>Wed, 03 Jun 2009 09:20:13 +0000</pubDate>
		<dc:creator>54bottles</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[js]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[selenium]]></category>
		<category><![CDATA[test]]></category>

		<guid isPermaLink="false">http://keep12on.com/?p=19</guid>
		<description><![CDATA[InvisibleHand, a Firefox plugin that checks alternative prices as you are shopping online and alerts you if a bargain is found, consists of client part (the extension itself, in Javascript) and server part (the database of products, in Ruby). In order for the extension to always stay up-to-date it downloads pieces of JS code with [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=keep12on.com&blog=6666530&post=19&subd=keep12on&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.getinvisiblehand.com/">InvisibleHand</a>, a Firefox plugin that checks alternative prices as you are shopping online and alerts you if a bargain is found, consists of client part (the extension itself, in Javascript) and server part (the database of products, in Ruby). In order for the extension to always stay up-to-date it downloads pieces of JS code with price scraping logic from the server when it starts. I look after the JS code updating it whenever the layout of pages on retailers&#8217; websites changes.</p>
<p>The challenge was to test this stuff automatically because the JS code makes part of a Ruby project and I want to &#8216;rake test&#8217; it all. Getting a JS engine in my project would be an overkill, so I resorted to <a href="http://www.seleniumhq.com/">Selenium</a>.</p>
<p>So, how to test a piece of Javascript code stored in your Ruby project?</p>
<p>First, download Selenium <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Then, launch the server<br />
<code>java -jar selenium-server.jar</code></p>
<p>Then, install selenium client<br />
<code>sudo gem install selenium-client</code></p>
<p>In your unit test, launch Selenium:<br />
<code><br />
attr_reader :browser</code></p>
<p><code>def setup<br />
  @browser = Selenium::Client::Driver.new "localhost", 4444, "*firefox", "http://www.google.com/", 10000<br />
  browser.start_new_browser_session<br />
end</p>
<p>def teardown<br />
  browser.close_current_browser_session<br />
end</p>
<p> </p>
<p>The base address that you use to launch Selenium (google in this example) doesn't matter as long as your code isn't doing cross-domain requests.</p>
<p>Then, in your test:<br />
<code><br />
def test_js<br />
  str = "Ah, Satan sees Natasha".to_json<br />
  js = %Q[<br />
    function reverseString(str) {<br />
      var rstr = '';<br />
      for (var i=str.length-1; i&gt;=0; i--)<br />
        rstr += str.charAt(i);<br />
      return rstr;<br />
    } <br />
    reverseString(#{str});<br />
  ]<br />
  result = browser.js_eval(js)<br />
  assert_equal 'ahsataN sees nataS ,hA', result<br />
end<br />
</code></p>
<p>A few comments:</p>
<ol>
<li>The conversion to json is not necessary in this example but if you are sending an array of data or strings with characters which should be escaped, use json.</li>
<li>js_eval() function returns the result of the last line in the script.</li>
<li>If you need to return anything more complex than a string or a number, consider converting your data to json before returning and then parsing it in ruby (that's what I'm doing in my tests but I omitted it here for clarity)</li>
</ol>
<p>The problem with this code is that is damn slow because a new instance of Firefox is started for this test and it's not fast. However, it's better than no tests at all and if you don't need to start a new instance of firefox for every test, it's actually tolerable.<br />
<code>Loaded suite /Users/evgeny/invisiblehand/test/selenium/js_test<br />
Started<br />
.<br />
Finished in 7.403807 seconds.</code></p>
<p><code> </code></p>
<p><code>1 tests, 1 assertions, 0 failures, 0 errors<br />
</code></p>
<p>Good luck!</p>
<p></code></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/keep12on.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/keep12on.wordpress.com/19/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/keep12on.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/keep12on.wordpress.com/19/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/keep12on.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/keep12on.wordpress.com/19/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/keep12on.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/keep12on.wordpress.com/19/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/keep12on.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/keep12on.wordpress.com/19/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=keep12on.com&blog=6666530&post=19&subd=keep12on&ref=&feed=1" />]]></content:encoded>
			<wfw:commentRss>http://keep12on.com/2009/06/03/javascript-testing-in-ruby-with-selenium/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/32863b249d1e5627b4574f6a380cd2ec?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">54bottles</media:title>
		</media:content>
	</item>
		<item>
		<title>libxml Extra content at the end of the document</title>
		<link>http://keep12on.com/2009/05/13/libxml-extra-content-at-the-end-of-the-document/</link>
		<comments>http://keep12on.com/2009/05/13/libxml-extra-content-at-the-end-of-the-document/#comments</comments>
		<pubDate>Wed, 13 May 2009 08:07:13 +0000</pubDate>
		<dc:creator>54bottles</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://keep12on.com/?p=15</guid>
		<description><![CDATA[Ruby libxml parser that I use to process large xml files in SAX mode refused to process a file that looked perfectly valid, throwing &#8216;Extra content at the end of the document&#8217; error somewhere in the middle of the file. It turned out that it disliked control character \x0B (vertical tab), which is not allowed [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=keep12on.com&blog=6666530&post=15&subd=keep12on&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<p>Ruby libxml parser that I use to process large xml files in SAX mode refused to process a file that looked perfectly valid, throwing &#8216;Extra content at the end of the document&#8217; error somewhere in the middle of the file. It turned out that it disliked control character \x0B (vertical tab), which is not allowed in XML according to the spec.</p>
<p>To simply remove the vertical tabs from the file (or, rather, replace them with spaces), I tried using sed like this</p>
<p><code>sed s/\x0B/\ /g file.xml</code></p>
<p>but I found out that \xXX syntax is not supported by OSX sed version, which is a shame, so I used a ruby script, which, to my surprise, was quick enough to process a 800 MB file.</p>
<p><code>output = File.open("out.xml", 'w+')<br />
File.open('file.xml').each{|p| output.puts p.gsub(/\x0B/, ' ')}<br />
</code></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/keep12on.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/keep12on.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/keep12on.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/keep12on.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/keep12on.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/keep12on.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/keep12on.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/keep12on.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/keep12on.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/keep12on.wordpress.com/15/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=keep12on.com&blog=6666530&post=15&subd=keep12on&ref=&feed=1" />]]></content:encoded>
			<wfw:commentRss>http://keep12on.com/2009/05/13/libxml-extra-content-at-the-end-of-the-document/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/32863b249d1e5627b4574f6a380cd2ec?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">54bottles</media:title>
		</media:content>
	</item>
		<item>
		<title>TextMate: lstat &#8211; No such file or directory</title>
		<link>http://keep12on.com/2009/05/10/textmate-lstat-no-such-file-or-directory/</link>
		<comments>http://keep12on.com/2009/05/10/textmate-lstat-no-such-file-or-directory/#comments</comments>
		<pubDate>Sun, 10 May 2009 11:46:27 +0000</pubDate>
		<dc:creator>54bottles</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[textmate]]></category>

		<guid isPermaLink="false">http://keep12on.com/?p=6</guid>
		<description><![CDATA[A hack for System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/pathname.rb:420:in `lstat': No such file or directory exception in textmate.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=keep12on.com&blog=6666530&post=6&subd=keep12on&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<p>Sometimes in TextMate I get exceptions like this when trying to run unit tests:</p>
<p><code>/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/pathname.rb:420:in `lstat': No such file or directory - /Users/evgeny/Projects/project/test/unit/test (Errno::ENOENT) from<br />
&lt;... stack trace skipped ...&gt; </code></p>
<p>The exception above is caused by the call to realpath() in path_to_url_chunk() in Bundles/Ruby.tmbundle/Support/RubyMate/run_script.rb.</p>
<p><code>def path_to_url_chunk(path)<br />
  unless path == "untitled"<br />
    file = Pathname.new(path).realpath.to_s<br />
    "url=file://#{e_url(path)}&amp;"<br />
  else<br />
    ''<br />
  end<br />
end</code></p>
<p>There are two problems here. First, the file variable is not used, so the hyperlink to the failed method in textmate output would be broken as a result. Second, realpath() raises an exception because for some reason (I didn&#8217;t dig deeper) the current directory is &#8216;/path/to/test/unit&#8217; and path is &#8216;test/unit/my_test.rb&#8217;, so realpath() can&#8217;t find the test.</p>
<p>The modified version of the function works better:</p>
<p><code>def path_to_url_chunk(path)<br />
  unless path == "untitled"<br />
    Dir.chdir "../.."<br />
    file = Pathname.new(path).realpath.to_s<br />
    "url=file://#{e_url(file)}&amp;"<br />
  else<br />
    ''<br />
  end<br />
end<br />
</code></p>
<p>It&#8217;s not a proper solution because the either the file path or the working directory should be corrected before this function is called. If you know a better solution to this problem, please leave a comment.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/keep12on.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/keep12on.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/keep12on.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/keep12on.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/keep12on.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/keep12on.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/keep12on.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/keep12on.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/keep12on.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/keep12on.wordpress.com/6/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=keep12on.com&blog=6666530&post=6&subd=keep12on&ref=&feed=1" />]]></content:encoded>
			<wfw:commentRss>http://keep12on.com/2009/05/10/textmate-lstat-no-such-file-or-directory/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/32863b249d1e5627b4574f6a380cd2ec?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">54bottles</media:title>
		</media:content>
	</item>
	</channel>
</rss>