White is an open source .Net library designed to support Unit Testing of Windows GUIs. I used it for the first time this week. The results were good enough to recommend using it again. The performance was a little slow, so I wouldn't want to have lots of tests. I prefer to avoid UI Unit Tests by separating the presentation from the logic. However, sometimes you need to unit test an interaction. For those cases, White can be useful.
I'm not going to blog an example here. The documentation for White has some examples. See Getting Started.
Wednesday, June 03, 2009
Wednesday, April 29, 2009
Using Cucumber Testing Framework without Rails
Most of the articles for Cucumber are given as Rails examples. While Cucumber was born for Rails testing, it isn't limited to that environment. A few simple steps will allow you to use Cucumber with any Ruby project.
This example will use Rake to run cucumber because the Cucumber::Rake::Task does a lot of work for you. It will automatically load (require) the features and steps for you.
First, you should follow Cucumber's pattern for directories:
First create a rakefile for your project and add a Cucumber::Rake::Task as follows...
Next create the features file(s). The rake task will automatically require all the .feature files in the features directory. This example reproduces the additions.feature shown on Cucumber's homepage.
At this time, you may run "rake features" to see Cucumber runs. The results will show that 4 steps are undefined. To define the steps create features\step_definitions\addition_steps.rb. The rake task will automatically require all the step_definitions files.
This example uses a class Calculator from my project. So lets define that class under lib\calculator.rb.
This calculator isn't very exciting. It just uses a stack to remember values. The first item in the stack is the "screen". The add method will add the top two values. This is the bare minimum needed to meet the defined feature. (Normally you would define the class and fill in the details in a test-first fashion. But to keep this article short, I've posted the completed class.)
The rake features task doesn't automatically require the calculator.rb file. Also, if you noticed the addition_steps.rb makes use of rspec expectations, which isn't available by default. To require these files, create the features/support/env.rb file. The rake features task will automatically require any file under features/support
Now when you run "rake features" everything will work together. Your steps should all run and pass with green color!
This example will use Rake to run cucumber because the Cucumber::Rake::Task does a lot of work for you. It will automatically load (require) the features and steps for you.
First, you should follow Cucumber's pattern for directories:
| {project home}/features | stores all the .feature files |
| {project home}/features/step_definitions | stores the .rb files containing steps |
| {project home}/features/support | contains the env.rb file |
First create a rakefile for your project and add a Cucumber::Rake::Task as follows...
Next create the features file(s). The rake task will automatically require all the .feature files in the features directory. This example reproduces the additions.feature shown on Cucumber's homepage.
At this time, you may run "rake features" to see Cucumber runs. The results will show that 4 steps are undefined. To define the steps create features\step_definitions\addition_steps.rb. The rake task will automatically require all the step_definitions files.
This example uses a class Calculator from my project. So lets define that class under lib\calculator.rb.
This calculator isn't very exciting. It just uses a stack to remember values. The first item in the stack is the "screen". The add method will add the top two values. This is the bare minimum needed to meet the defined feature. (Normally you would define the class and fill in the details in a test-first fashion. But to keep this article short, I've posted the completed class.)
The rake features task doesn't automatically require the calculator.rb file. Also, if you noticed the addition_steps.rb makes use of rspec expectations, which isn't available by default. To require these files, create the features/support/env.rb file. The rake features task will automatically require any file under features/support
Now when you run "rake features" everything will work together. Your steps should all run and pass with green color!
Saturday, April 04, 2009
TofuHash is done!
Thursday, March 12, 2009
TofuHash is now a ruby gem.
I've released v0.1.0 as a ruby gem. The documentation is online at http://tofuhash.rubyforge.org/
To install it, simply use:
gem install tofuhash
To install it, simply use:
gem install tofuhash
Tuesday, February 03, 2009
wordle.net

I found wordle.net which can generate word clouds from text, blogs, etc. Just for fun, I created one from my blog.
Monday, December 08, 2008
tufuhash 0.0.1 available
TufuHash is posted on github. TofuHash is a case-insensitive hash plus string/symbol indifferent access version of Ruby's Hash. It is implemented as a subclass of Hash. The behavior is easily modifiable by creating a different TofuKey. So you could have it perform key lookups anyway you want!
The current release 0.0.1 hasn't been used in many places. So if you find defects, send them to me. I'll get it fixed asap. So far I've create a bunch of unit tests to verify TofuHash behavior. These unit tests include modified versions of Ruby's Hash unit tests, sourcecode examples from the ri documentation of Hash, plus some of my own tests.
So far I've avoided monkey patching Hash. So there is a known issue where Hash doesn't always know how to handle TofuHash. For example, you can't compare Hash to TofuHash(myHash == myTofuHash), but the reverse is possible (myTofuHash == myHash).
The easiest way to create and populate a TofuHash is to use Hash's [ ] syntax as shown here:
The current release 0.0.1 hasn't been used in many places. So if you find defects, send them to me. I'll get it fixed asap. So far I've create a bunch of unit tests to verify TofuHash behavior. These unit tests include modified versions of Ruby's Hash unit tests, sourcecode examples from the ri documentation of Hash, plus some of my own tests.
So far I've avoided monkey patching Hash. So there is a known issue where Hash doesn't always know how to handle TofuHash. For example, you can't compare Hash to TofuHash(myHash == myTofuHash), but the reverse is possible (myTofuHash == myHash).
The easiest way to create and populate a TofuHash is to use Hash's [ ] syntax as shown here:
require 'tofuhash'
h = TofuHash[ :aSymbol => "symbol", "MixedCaseString" => "string", 11 => "number" ]
puts h["asymbol"] #=> "symbol"
puts h[:mixedCaseString] #=> "string"
puts h[11] #=> "number"
color-block 0.2.0 released
Several weeks ago I made color-block available on github. This is a small library to colorize ruby output. Specifically I wanted to colorize my rake output. In some rake tasks, I didn't have access to the details of the task. So I couldn't add color to each string. Instead color-block allows me to colorize an entire block of code.
Several friends have tested color-block on Windows, Linux and Apple Mac.
Several friends have tested color-block on Windows, Linux and Apple Mac.
require 'color-block'
include ColorBlock
color( :blue ) { "everything in this block is blue!" }
color( :white, :blue ) do
puts "now everything is white on blue!"
color( :green, :black ) { "nesting is supported" }
end
color( :white, :black, :bold ) { "third parameter to specify :bold or :dim" }
Subscribe to:
Posts (Atom)