<?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>My Other Pants &#187; cucumber</title>
	<atom:link href="http://myotherpants.com/tag/cucumber/feed/" rel="self" type="application/rss+xml" />
	<link>http://myotherpants.com</link>
	<description>I left it in my other pants</description>
	<lastBuildDate>Tue, 24 Jan 2012 18:11:48 +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>Crouching Donny, Iron Cucumber &#8211; An Experiment in Functional Testing</title>
		<link>http://myotherpants.com/2009/09/crouching-donny-iron-cucumber/</link>
		<comments>http://myotherpants.com/2009/09/crouching-donny-iron-cucumber/#comments</comments>
		<pubDate>Tue, 08 Sep 2009 02:00:37 +0000</pubDate>
		<dc:creator>Ball</dc:creator>
				<category><![CDATA[work safe]]></category>
		<category><![CDATA[cucumber]]></category>
		<category><![CDATA[ironruby]]></category>
		<category><![CDATA[testing]]></category>
		<category><![CDATA[wpf]]></category>

		<guid isPermaLink="false">http://myotherpants.com/?p=122</guid>
		<description><![CDATA[I accidentally agreed to give a talk later this month. The subject is IronRuby and it&#8217;s application in the .NET ecosystem. Seems simple enough. So, to jazz things up, I want to have a host of demo applications. This is about one. A while back, I posted an article with an example of using IronRuby [...]]]></description>
			<content:encoded><![CDATA[<p>I accidentally agreed to give a talk later this month.  The subject is IronRuby and it&#8217;s application in the .NET ecosystem.  Seems simple enough.  So, to jazz things up, I want to have a host of demo applications.  This is about one.</p>
<p>A while back, I posted <a href="http://myotherpants.com/2009/06/automatic-for-the-people/">an article with an example of using IronRuby and the White framework</a>.  In it, I appear to have made a promise.  </p>
<blockquote><p>I’ll get to Cucumber. I’ll publish examples. I promise.</p></blockquote>
<p><span id="more-122"></span></p>
<p>I&#8217;m going to talk a lot about Donny.  You&#8217;ll meet Donny, but just be aware, he&#8217;s compiled in Debug, so he&#8217;s a bit shy.  Donny is an app written to give me something to test.  He does nothing of real import, he doesn&#8217;t even save his data to disk.  As for why &#8220;Donny&#8221;, I still don&#8217;t know.  I was in a mood yesterday when outlining my presentation and &#8220;Donny&#8221; stuck.</p>
<p><strong><a href="http://cukes.info/">Cucumber</a></strong> &#8211; n, A functional testing framework for ruby.  Cucumber uses Features and Step Definitions to drive an application via it&#8217;s full stack.</p>
<p>Cucumber does work with IronRuby, but by default it&#8217;s runner has some idiosyncrasies for which you&#8217;ll need to compensate.  The cucumber.bat file lives, for me, in <code>c:\IronRuby\lib\IronRuby\gems\1.8\bin</code>.  Another oddity is that it belives I have a color console.  This is <em>mostly</em> true, but Win32Console doesn&#8217;t work for IronRuby, so you&#8217;ll need to use the <code>--no-color</code> option.  For now.  I have my features in a directory I&#8217;m calling &#8220;features&#8221; with an embedded step definitions directory.  Once I finish the presentation, I&#8217;ll have the whole damn thing published and you can look at it then.  Until then, here&#8217;s the command line I used; <code>cucumber --no-colors features</code>.</p>
<p><strong>Feature</strong> &#8211; n, A tightly formatted Business Natural Language used to describe the preconditions, actions, and expected results in a business scenario.  See also, <a href="http://dannorth.net/whats-in-a-story">Story</a>.</p>
<p>I have two basic scenarios; Donny starts with no data, and Donny moves data from the task form to the task list.</p>
<pre>
Feature: New Task
  In order to correctly bill my client
  as an SEP employee
  I want to add a task to the list

  Scenario: Starting the app
    Then all fields are blank
    And the list contains 0 entries

  Scenario:  Add a new Task
    Given I describe my task as Doing work on the Donny app
    And I'm working on project Academy
    And the day is Monday
    And I worked from 10 to 10:30
    When I press the button
    Then all fields are blank
    And the list contains 1 entry
    And the last entry is Monday 10-10:30 Academy Doing work on the Donny app
</pre>
<p><strong>Step Definition</strong> &#8211; n, a ruby script used to match lines in the Feature BNL to actual executable code.  They can be reused across features.</p>
<p>For each Given, When, or Then I have to have a matching step.  These are essentially ruby functions that use a helper to encapsulate my usage of the White library.  Here is <em>donny_steps.rb</em></p>
<pre name="code" class="ruby">
require 'spec/expectations'
require File.dirname(__FILE__) + "/../../donny_helper.rb"

Before do
  @app = Application.launch "Donny/bin/Debug/donny.exe"
  @win = @app.get_window "Window1"
  @tf = TaskForm.new(@app, @win)
  @tl = TaskList.new(@app, @win)
end

After do
  @win.close
end
Given /I describe my task as (.*)/ do |description|
  @tf.description = description
end

Given "I'm working on project $proj" do |proj|
  @tf.project = proj
end

Given "the day is $day" do |day|
  @tf.day = day
end

Given /I worked from (.*) to (.*)/ do |start_time, end_time|
  @tf.start_time = start_time
  @tf.end_time = end_time
end

When "I press the button" do
  @tf.commit
end

Then "all fields are blank" do
  @tf.description.should be_empty
  @tf.project.should be_empty
  @tf.day.should be_empty
  @tf.start_time.should be_empty
  @tf.end_time.should be_empty
end

Then /the list contains (.*) entr(?:y|ies)/ do |n|
  @tl.task_count.should == n.to_i
end

Then /the last entry is (.*)/ do |result|
  @tl.tasks.last.text.should == result
end
</pre>
<p>Um, you&#8217;re missing a piece.  The part that uses White.  Remember the screens?  This time, I didn&#8217;t call them screens, and I don&#8217;t have a full window proxy, but I still have two helper objects.  Now, with some metaprogramming, I could cut down the code size by defining an attribute and describing the type and automation ID of it&#8217;s associated control, but I&#8217;m lazy.  Maybe for the presentation, but I&#8217;m not making any promises. </p>
<pre name="code" class="ruby">
white_loc = (File.dirname(__FILE__) + "/White_Bin_0.18/")
puts white_loc
$LOAD_PATH << white_loc
require "White.Core.dll"

Application = Core::Application
ComboBox = Core::UIItems::ListBoxItems::ComboBox
ListBox = Core::UIItems::ListBoxItems::ListBox
Window = Core::UIItems::WindowItems::Window
include Core::UIItems

class Window
  def get_button(*args)
    self.method(:get).of(Button).call(*args)
  end
  def get_textbox(*args)
    self.method(:get).of(TextBox).call(*args)
  end
  def get_combobox(*args)
    self.method(:get).of(ComboBox).call(*args)
  end
  def get_listbox(*args)
    self.method(:get).of(ListBox).call(*args)
  end
end
class TaskList
  def initialize(app, win)
    @app = app
    @win = win
  end
  def tasks
    @win.get_listbox('tasklist').items.to_a
  end
  def task_count
    tasks.size
  end
end
class TaskForm
  def initialize(app, win)
    @app = app
    @win = win
  end
  def description
    get_tb 'task'
  end
  def description=(text)
    set_tb 'task', text
  end
  def project
    @win.get_combobox('project').selected_item_text
  end
  def project=(proj)
    @win.get_combobox('project').select proj
  end
  def day
    get_tb 'dayofweek'
  end
  def day=(day)
    set_tb 'dayofweek', day
  end
  def end_time
    get_tb 'endtime'
  end
  def end_time=(et)
    set_tb 'endtime', et
  end
  def start_time
    get_tb 'starttime'
  end
  def start_time=(st)
    set_tb('starttime', st)
  end
  def commit
    @win.get_button('commit').click
  end

  private
  def set_tb(auto_id, value)
    @win.get_textbox(auto_id).set_value value
  end
  def get_tb(auto_id)
    @win.get_textbox(auto_id).text
  end
end
</pre>
<p>And some for some context, Meet Donny!<br />
<a href="http://myotherpants.com/wp-content/uploads/2009/09/Donny.PNG"><img src="http://myotherpants.com/wp-content/uploads/2009/09/Donny.PNG" alt="Donny" title="Donny" width="258" height="176" class="aligncenter size-full wp-image-123" /></a></p>
<p>And, after I enter a task, Donny looks like this.<br />
<a href="http://myotherpants.com/wp-content/uploads/2009/09/Donny1.PNG"><img src="http://myotherpants.com/wp-content/uploads/2009/09/Donny1.PNG" alt="Donny" title="Donny" width="258" height="189" class="aligncenter size-full wp-image-125" /></a></p>
<p>That's really all there is to using Cucumber with IronRuby.  Have fun!</p>
]]></content:encoded>
			<wfw:commentRss>http://myotherpants.com/2009/09/crouching-donny-iron-cucumber/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

