RSpec your functional tests

The release of RSpec 0.9.4 can be considered a landmark release of sorts. With the inclusion of Spec::Ui 0.2.0, RSpec can now perform functional testing of web applications within a browser. Out of the box support is limited to Watir/Internet Explorer for now as the Selenium RC custom matchers are not implemented yet. includes WATIR/Windows and Watirsafari/OSX. The custom matchers for Selenium RC are not implemented yet but its certainly possible to use Selenium with Spec::Ui, it just won't read as nicely compared to WATIR. Spec::Ui also comes with a custom result formatter that packages a screenshot of the browser on spec failure, along with its HTML source in the report.

To use Watirsafari in your functional specs, you'll need to install the gem for it: gem install watirsafari

spec_helper.rb should be updated to include the snippet below (code lifted from the original release announcement):

RUBY:
  1. Spec::Runner.configure do |config|
  2. config.include Spec::Matchers::Watir
  3. end

The specification will need before and after blocks like this:

RUBY:
  1. before(:all) do
  2. @browser = Watir::Browser.new
  3. end
  4.  
  5. after(:each) do
  6. # This is needed to make screenshots work
  7. Spec::Ui::ScreenshotFormatter.browser = @browser
  8. end
  9.  
  10. after(:all) do
  11. @browser.kill! rescue nil
  12. end

There are a lot more useful information available in the examples supplied with Spec::Ui. Take a look at the samples to get up and running.

Update
My thanks to Aslak Hellesoy for correcting me on support for WATIR and Selenium.

1 Comment

Using Textmate for Actionscript

I've never liked the default code editor that comes with the Flash IDE, so when the I discovered that I would need to develop actionscript code for a project, my first thought was to use Textmate instead. Incidentally, some people are already doing this.

I've used MTASC to compile Actionscript files before, the most important difference that surfaces when comparing it to Macromedia's Actionscript compiler (MMC), which is the one that's packaged in every installation of Flash, is that MTASC is much stricter on enforcing proper syntax. This is intended to reduce occurences of hard to find bugs that arise from improper scripting. The other feature that MTASC touts is its faster compile speed, however I've not experienced a visible variance between it and MMC. I would think that this speed improvement would be more apparent when compiling large projects consisting of more than 50 Actionscript files.

I'm using dirtystylus' Textmate command for checking the syntax of my files, it took me a while to get it working as I organised the dependencies differently. Following my conventions in using MacPorts which is installed in /opt/local/, MTASC and XTrace were placed in /opt/local/managed/. The executable for MTASC was stored in /opt/local/managed/bin/ while XTrace.app was copied to the Applications folder. All supporting scripts were moved to /opt/local/managed/lib/.

This is the customised command that I'm using after trying for about 2 hours.

CODE:
  1. FLASHPLAYER=SAFlashPlayer
  2. MTASC=/opt/local/managed/bin/mtasc
  3. CLASSPATHS="-cp /opt/local/managed/lib/mtasc/std/ -cp /opt/local/managed/lib/mtasc/std8/ -cp /Users/douglas/Library/Application\ Support/Macromedia/Flash\ 8/en/Configuration/Classes/"
  4. SOURCE="$TM_FILEPATH"
  5. OUTPUT=test.swf
  6. VERSION=8
  7. TRACE="-trace com.mab.util.debug.trace"
  8. TMPFILE=/tmp/as-compile.err
  9. compileResult=`$MTASC -main "$SOURCE" -wimp -version $VERSION -strict $CLASSPATHS $TRACE 2>&1`
  10. echo "
  11. <style type="\'text/css\'"> body {margin: 10px; font-family: Monaco; font-size: 14px;} a {color: #000000; text-decoration: underline;} a:hover {color: #666666;} </style> <script type="\'text/javascript\'"> function closeWin() { self.close(); } </script>"
  12. if test -n "$compileResult"
  13. then
  14. errorLine=`echo $compileResult | sed 's/.*:\([0-9]*\):.*/\1/'`
  15. echo "<a href="txmt://open?url=file://$TM_FILEPATH&amp;line=$errorLine" onclick="closeWin();">$compileResult</a>";
  16. else
  17. echo "
  18. fi

3 Comments

Using Ruby and Rails in the enterprise

The Rails Podcast has an excellent interview with Josh Shairbaum and Dan Manges from JP Morgan on using Rails in the enterprise. Do check it out if you're at all interested in introducting Ruby/Rails to your particular company.

Listening to Josh and Dan made me realise that I'm quite fortunate to be working in a company where there are no corporate traditions to follow when it comes to technology. I've developed 2 applications for use by staff and clients alike so far and they're both powered by Rails. Being the sole developer in my company, Rails is a perfect fit and this combination has shown its worth.

Josh mentioned that his development team of 3 got Rails in the door by using it to develop a reporting application, an app where the implementing technology was not a big issue with corporate managers. By having the reporting application running AND available to end users within 1.5 months demonstrated the productivity gains that can be achieved by Rails. A lot of evangelizing and demonstrations were done to help their cause too. I think that they benefited a fair bit from having key people in other functional units willing to give Rails a try, even though it required them to risk doing something that's new and by corporate definition, risky.

It's encouraging to listen to them and their passion for Rails was apparent in the way they talked about and how they dealt with people who did not understand what it was.

Comments

Behaviour Driven Development with RSpec

I've started using RSpec in my Rails projects. Besides serving the purposes of testing my application, it has also become an extremely useful design tool. Comparing the DSLs for Test::Unit and RSpec, the latter expresses the intention of the tests much more clearly and quickly. Luke Redpath does a great job of explaining the basics of Behaviour Driven Development using RSpec on Rails. Its a must read if you're interested in exploring BDD for your Rails development.

Technorati Tags: , ,

Comments