<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <title>Dream Pixel :: Weblog</title>
    <link>http://www.dreampixel.co.uk/</link>
    <description>Blog articles from Dream Pixel, home of Developer Dan Hunter. Thoughts on Java, Spring, Ruby, Ruby on Rails and developing on Macs</description>
    <language>en-us</language>
    <item>
      <title>Validate JavaScript variables with WATIR</title>
      <description>&lt;p&gt;Recently I was required to add 3rd party JavaScript Tracking Tags to an order confirmation page. The JavaScript passed the quantities of products purchased onto the 3rd party.&lt;/p&gt;

&lt;p&gt;I wanted to validate the tags using &lt;a href="http://wiki.seleniumhq.org/display/WTR/Project+Home" target="_blank"&gt;Watir&lt;/a&gt;. It is easy enough to access the DOM using &lt;a href="http://wiki.seleniumhq.org/display/WTR/Project+Home" target="_blank"&gt;Watir&lt;/a&gt; and previously I have validated tracking tags placed in an iFrame url using xpath:&lt;/p&gt;

Access the iframe element using xpath (returns an array):&lt;br /&gt;
&lt;div class="code"&gt;frame = @ie.elements_by_xpath("//[@id='my_iframe_id']")&lt;/div&gt;

&lt;br/&gt;
Access the src of the iframe:&lt;br /&gt;
&lt;div class="code"&gt;frame[0].src&lt;/div&gt;

&lt;p&gt;Then simply assert the src to ensure the right data was been passed via the URL.&lt;/p&gt;

&lt;p&gt;This time I wanted to actually validate variables set up in the JavaScript. At first I was thinking about how I could access the script tag, then a much simpler idea came to me:&lt;/p&gt;

Retrieve the source code!&lt;br/&gt;
&lt;div class="code"&gt;html = @ie.html&lt;br /&gt;&lt;/div&gt;
&lt;br /&gt;
Assert the contents using a regular expression:&lt;br/&gt;
&lt;div class="code"&gt;assert(html.match(/SOME_PRODUCT="\+escape\(1\)/), "SOME_PRODUCT quantity should be: 1")&lt;/div&gt;&lt;br /&gt;

&lt;h3&gt;Watir resources&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="http://wiki.seleniumhq.org/display/WTR/Project+Home" target="_blank"&gt;Watir home page&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://wiki.seleniumhq.org/display/WTR/Tutorial" target="_blank"&gt;Watir tutorial&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://wtr.rubyforge.org/rdoc/" target="_blank"&gt;Watir API&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</description>
      <author>Dan Hunter</author>
      <pubDate>Sun, 23 Nov 2008 00:00:00 +0000</pubDate>
      <link>http://www.dreampixel.co.uk/weblog/more/16</link>
    </item>
    <item>
      <title>JAX-WS Tutorial</title>
      <description>&lt;p&gt;Developer and fellow colleague Paul Taylor, has taken the time to write an excellent and easy to follow JAX-WS tutorial.&lt;/p&gt; 

&lt;p&gt;&lt;a href="http://www.javacoda.com/blog/?p=22" target="_blank"&gt;Check it out at JavaCoda&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;
Lessons covered:
&lt;/p&gt;
&lt;ol&gt;
   &lt;li&gt;Basic JaxWs service with defaults &amp; simple client.&lt;/li&gt;
   &lt;li&gt;Generated client.&lt;/li&gt;
   &lt;li&gt;Annotations &amp; mapping.&lt;/li&gt;
   &lt;li&gt;XmlJavaAdapters&lt;/li&gt;
   &lt;li&gt;SOAPFaults. Handlers.&lt;/li&gt;
   &lt;li&gt;JaxWsPortFactory with timeouts.&lt;/li&gt;
   &lt;li&gt;Asynchronous calls.&lt;/li&gt;
   &lt;li&gt;Spring injection&lt;/li&gt;
   &lt;li&gt;Field/Property mapping quick examples. Marshalling tests.&lt;/li&gt;
&lt;/ol&gt;
</description>
      <author>Dan Hunter</author>
      <pubDate>Sun, 31 Aug 2008 00:00:00 +0100</pubDate>
      <link>http://www.dreampixel.co.uk/weblog/more/15</link>
    </item>
    <item>
      <title>NetBeans has TextMate style code templates</title>
      <description>&lt;p&gt;Since owning a mac, I have been an avid user of TextMate. Therefore I have picked up some of the TextMate shortcuts for Ruby.&lt;/p&gt;
&lt;p&gt;I mostly develop on Windows in the workplace (not out of choice) so I use NetBeans as my main Ruby IDE on both platforms. So I was surprised to find  NetBeans contains many of the TextMate code template shortcuts (Known as Bundles in TextMate).&lt;/p&gt;
&lt;p&gt;Here are some of the most useful ones:&lt;/p&gt;
&lt;p&gt;To activate a code template type the shortcut name followed by the -&gt;| (TAB key)&lt;/p&gt;

&lt;table class="code"&gt;
&lt;tr&gt;
&lt;th&gt;&lt;strong&gt;Shortcut&lt;/strong&gt;&lt;/th&gt;
&lt;th&gt;&lt;strong&gt;Result&lt;/strong&gt;&lt;/th&gt;
&lt;tr&gt;
&lt;td width="30%"&gt;rb&lt;/td&gt;
&lt;td&gt;#!/usr/bin/env ruby -wKU&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;req&lt;/td&gt;&lt;td&gt; require ""&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;rw&lt;/td&gt; &lt;td&gt;attr_accessor :attr_names&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;r&lt;/td&gt;&lt;td&gt;attr_reader :attr_names&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;w&lt;/td&gt;
&lt;td&gt;attr_writer :attr_names&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;ea&lt;/td&gt;&lt;td&gt;each { |1|  }&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;eai&lt;/td&gt;&lt;td&gt;each_index { |1| }&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;eak&lt;/td&gt;&lt;td&gt;each_key { |1|  }&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;deli&lt;/td&gt;&lt;td&gt;delete_if { |e|  }&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;:&lt;/td&gt;&lt;td&gt;:key =&gt; "value",&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;do&lt;/td&gt;&lt;td&gt;do |1|&lt;br /&gt;end&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;def&lt;/td&gt;
&lt;td&gt;def method_name&lt;br /&gt;&lt;br /&gt;end
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;if&lt;/td&gt;
&lt;td&gt;if condition&lt;br /&gt;&lt;br /&gt;end&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;unless&lt;/td&gt;
&lt;td&gt;unless condition&lt;br /&gt;&lt;br /&gt;end&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;while&lt;/td&gt;
&lt;td&gt;while condition&lt;br /&gt;&lt;br /&gt;end&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;until&lt;/td&gt;
&lt;td&gt;until condition&lt;br /&gt;&lt;br /&gt;end&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Dir&lt;/td&gt;&lt;td&gt;Dir.glob() { |3| }&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;File&lt;/td&gt;&lt;td&gt;File.foreach("path/to/file") { |3| }&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;begin&lt;/td&gt;&lt;td&gt;begin
&lt;br /&gt;&lt;br /&gt;
rescue Exception =&gt; 1&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;code&lt;br /&gt;
end&lt;/td&gt;
&lt;/tr&gt;
&lt;td&gt;cla&lt;/td&gt;&lt;td&gt;ClassName = Struct.new(:attr_names) do&lt;br /&gt;
  &amp;nbsp;&amp;nbsp;&amp;nbsp;def method_name&lt;br /&gt;	
  &amp;nbsp;&amp;nbsp;&amp;nbsp;end&lt;br /&gt;	
end&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;

&lt;p&gt;
Unit Test code templates:&lt;/p&gt;
&lt;table class="code"&gt;
&lt;tr&gt;
&lt;th&gt;&lt;strong&gt;Shortcut&lt;/strong&gt;&lt;/th&gt;
&lt;th&gt;&lt;strong&gt;Result&lt;/strong&gt;&lt;/th&gt;
&lt;tr&gt;
&lt;td width="30%"&gt;ts&lt;/td&gt;&lt;td&gt;require "test/unit"&lt;br /&gt;
&lt;br /&gt;
require "tc_test_case_file"&lt;br /&gt;
require "tc_test_case_file"&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;tc&lt;/td&gt;&lt;td&gt;require "test/unit"&lt;br/&gt;
require "library_file_name"&lt;br /&gt;
&lt;br /&gt;
class Test &lt; Test::Unit::TestCase&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;def test_case_name&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;end&lt;br /&gt;
end&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;as&lt;/td&gt;&lt;td&gt;assert(test, "Failure message.")&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;ase&lt;/td&gt;&lt;td&gt;assert_equal(expected, actual)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;asne&lt;/td&gt;&lt;td&gt;assert_not_equal(unexpected, actual)&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;

&lt;p&gt;The main shortcut that is different is 'cla' in NetBeans this creates a new Struct, but in TextMate it gives you a choice of class options.&lt;/p&gt;
&lt;p&gt;Fear not! NetBeans lets you add new code templates by going to: Preferences &gt; Editor &gt; Code Templates.&lt;/p&gt;

&lt;p&gt;They're loads more unit test code templates too.&lt;/p&gt;</description>
      <author>Dan Hunter</author>
      <pubDate>Sat, 09 Aug 2008 00:00:00 +0100</pubDate>
      <link>http://www.dreampixel.co.uk/weblog/more/14</link>
    </item>
    <item>
      <title>Macs n stuff</title>
      <description>A couple of guys I work with have started a new blog about mac tips and hints:

&lt;br /&gt;
&lt;p&gt;
&lt;a href="http://www.macsnstuff.com/" target="_blank"&gt;www.macsnstuff.com&lt;/a&gt;
&lt;/p&gt;

&lt;p&gt;These guys really do live and breath macs.&lt;/p&gt;</description>
      <author>Dan Hunter</author>
      <pubDate>Mon, 04 Aug 2008 00:00:00 +0100</pubDate>
      <link>http://www.dreampixel.co.uk/weblog/more/13</link>
    </item>
    <item>
      <title>Online, on rails</title>
      <description>At last my new site is online, knocked together with Ruby on Rails.
&lt;p&gt;
I feel it's still in experimentation mode. I may change the design, besides I am continually tweaking the Ruby code :)&lt;/p&gt;
&lt;p&gt;
Never the less dreampixel is online again, this time with a blog flavour to keep me amused whilst I work on the rest of the site.
&lt;/p&gt;
&lt;p&gt;
Although it has taken a while to get the site online, the actual coding took no time at all with Ruby and Rails.&lt;/p&gt;
&lt;p&gt;Resources that guided me in my quest:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="http://www.pragprog.com/titles/rails2/agile-web-development-with-rails" target="_blank"&gt;Agile Web Development with Rails&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.pragprog.com/titles/ruby/programming-ruby" target="_blank"&gt;Programming Ruby&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://poignantguide.net/ruby/" target="_blank"&gt;Why's (Poignant) Guide to Ruby&lt;/a&gt; (chunky bacon)&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.rubyonrails.org/" target="_blank"&gt;The Rails website&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;</description>
      <author>Dan Hunter</author>
      <pubDate>Sun, 03 Aug 2008 00:00:00 +0100</pubDate>
      <link>http://www.dreampixel.co.uk/weblog/more/4</link>
    </item>
  </channel>
</rss>
