Showing posts with label rspec. Show all posts
Showing posts with label rspec. Show all posts

10 February 2009

The RSpec Book: Never Judge A Book By Its Cover

The RSpec Book is out in beta version!

It's a long expected book for the BDD Community. The first time I mention this book was at the Paris on Rails 2007 conference. Since then, many changes happened and it seems that API and Practices are mature enough to release a book. As far as I am concerned, the biggest boost was given by Aslak with Cucumber.

Before adding more love, I'll write about 2 small caveats. It's still a bit hard to contribute to the RSpec project as code is a bit complex, I mean compares to bacon or shoulda. The other is the painful upgrading process since version 1.0: no matters what, I always end up spending 2-3 hours to fix my specs or autospec when I update the RSpec gem ...

Apart from that, RSpec and cucumber are one of the things which make me feeling at home working with Ruby (on Rails). Being able to describe the business rules and features is a big step for the software industry. How many hours lost because of misunderstanding between customers and programmers???
This book is aimed at programmers, my hope is that there will be other books following, targeting the customers (business analyst, project manager, end user). So little by little, we learn how to communicate clearly to each other and build better software ...

Never Judge A Book By Its Cover!

The second part of this post has nothing to do with technology or the quality of the book. I want to question the choice of an incandescent bulb to represent a technology as innovative as RSpec.

I have been volunteering for 2 years in an environmentalist NGO and one of the things I keep repeating is how bad for the environment are the old incandescent bulbs. I guess pragmatic programmers editors and RSpec book authors are very busy finishing the book and have other priorities ...

However, in these times of "green revolution", I hope that many RSpec users feel concerned about environmental issues and ask David and other authors to pick another image cover. It's a detail, I know but we have to replace all these electricity greedy bulbs even in the book covers!

RSpec is for alpha geek - the earlier adopters - and I don’t identify myself to a technology born in the XIX century !!!

Why not using a Compact Fluorescent bulb?

Or even more alpha geek, an LED_lamp ?

More information on http://www.earth-policy.org/Updates/2007/Update66.htm

UPDATE: International Energy Agency Press release : "Worldwide, grid-based electric lighting consumes 19% of total global electricity production" ..."It shows that were end-users to install only efficient lamps that will save money over the life cycle of the lighting service. Following these measures would save more than 16 000 Mt of CO2 emissions over the same time frame – equivalent to about 6 years of current global car emissions – and would avoid USD 2 600 billion"

http://www.thedailygreen.com/green-homes/eco-friendly/congress-incandescent-light-bulbs-ban-461217

I found the LED bulb image at http://www.flickr.com/photos/partybooper_rob/2324613709/sizes/l/ (Collective Commons)

15 July 2008

Hack to make Autotest + RSpec >=1.1.4 work in Netbeans

If you live on the edge (Netbeans Edge + Rails 2.1.0 + RSpec edge 1.1.4 + ZenTest 3.10.0) at the time of this writing - july 2008 - you'll have to hack autotest to be able to keep working with your favourite editor :-)

Indeed, when I upgradded to the latest stable versions, the wonderful "Auto test" feature in Netbeans stopped to work. It took me 45 minutes to find out what was happenning and to find a solution, hem hack.

As it says in the History file, there is now a command called "autospec" for running specs since RSpec 1.1.4. As Netbeans run the system command "/usr/bin/autotest", it won't discover any specs in your project

A quick hack to make it work, Add the following to /usr/bin/autotest:
ENV['RSPEC'] = 'true'
which will tell autotest we are actually using specs. The sad truth is I don't understand why it works, I need to dig in the code of the rspec-rails plugin I guess ... Enough time wasted!

I am not sure this change in will make RSpec users life easier ... Anyway, that's the way it is!

For netbeans developpers, it will be quite tricky to make it work with different versions of RSpec. I guess they'll have to test what version of RSpec is installed and use autospec for RSpec >= 1.1.4 ...

My /usr/bin/autotest file:


#!/usr/bin/ruby1.8 -ws
#
# This file was generated by RubyGems.
#
# The application 'ZenTest' is installed as part of a gem, and
# this file is here to facilitate running it.
#

require 'rubygems'

version = ">= 0"

if ARGV.first =~ /^_(.*)_$/ and Gem::Version.correct? $1 then
version = $1
ARGV.shift
end

ENV['RSPEC'] = 'true'
gem 'ZenTest', version
load 'autotest'

07 May 2008

XP Day France 2008

Bonjour à la communauté Agile francophone!

Je viens de mettre ma présentation "Intro a RSpec" à XP Day France 2008 dans slideshare:



Vous pouvez télécharger le pdf de ma présentation avec box.net. N'hésitez pas à me contacter pour des questions. Surtout les 150 personnes à qui j'ai distribué mes cartes de visite ;-)


N'hésitez pas à me contacter pour des questions. Surtout les "150" personnes à qui j'ai distribué mes cartes de visite ;-)

Je vous avouerai franchement que je me suis senti comme un poisson dans l'eau en discutant avec les participants: quelle énergie, quel amour de l'art, du travail bien fait!!!
C'est décidé, mon futur sera Agile et je ferai tout pour travailler en 2009 avec / pour l'une des entreprises Agile de France et de Navarre.

A ma grande surprise, Ruby on Rails n'a pas (encore) percé en France !!! Java règne en maître mais je suis confiant: le coup de foudre sera pour 2009!
5 ans après la naissance de la technologie, adoptée massivement aux US (2006), en UK, les pays nordiques, en Allemagne (2007) et même en Espagne (2008) !!! Que des pays qui parlent couramment anglais à l'exception de l'Espagne .... Je m'interroge, le niveau d'anglais des informaticiens français ne leur permet pas de lire les 56 (!!!) livres en anglais publiés à ce jour (09/05/2008) ???

J'hallucine en couleur quand j'entends les doutes et peurs de me compatriotes sur Rails: "does it scale, does it work, etc ..."
L'informatique n'est qu'une affaire de mode et de suivisme, l'humain est un mouton qui suit la masse!!!
Or, Sun Microsystems, Thoughtworks et quelque milliers d'individus super smart ont pariés sur Rails. VOUS AVEZ ENCORE PEUR??? On se croirait en 1999 lorsque je voulais faire du java et qu'il n'y avait aucun projet et que des doutes.

Pour revenir a XP Days France 2008, un petit commentaire sur les présentations auxquelles j'ai assistées.
  • Laboratoire Extreme Programming, par Eric Mignot (Pyxis) et François Beauregard (Pyxis): 5 équipes de 4 personnes en "pair programming" sur le jeu du milebornes, histoire d'illustrer les grands principes de XP. Quel chaos mais vraiment ludique et instructif!!! Plus les animateurs sont vachement sympas

  • La pratique du conflit, Regis Medina, Crossbow Labs, Antoine Contal, Orange Online Multimedia, Pascal Pratmarty, Indépendant. LA MEILLEURE: QUEL SHOW!
    Les orateurs étaient en tenue de Aïkido et nous ont fait bien marrés. Cette présentation m'a fait beaucoup réfléchir et j'ai passé une bonne partie du mercredi à penser à mon futur proche. Vous ne me croirez peut-être pas mais elle m'a aidé à décider d'arrêter de travailler pour mon client actuel et de passer à autre chose, plus human friendly!

  • Laboratoire Erlang, Dominic Williams, Esmertec, Nicolas Charpentier, Esmertec, Fabrice Nourisson: merci pour les explications et la patience des animateurs. J'avoue que mon cerveau était un peu "low energy" et que j'ai vraiment du mal à comprendre les principes du langage mais peut-être un jour ...

  • Sujets éclair sur l'agilité, Yannick Ameur, Valtech: Lightning Talk en français. Pas mal de sujets, très bonne idée! Merci à Yannick de m'avoir parlé de la cifconf.

  • Agilité et avionique, Emmanuel Chenu, Thales Avionics: un retour d'expérience intéressant. WOW L'airbus A350 volera avec des logiciels "Agile". QUE des PROS!!!

  • Tests unitaires avec les librairies de Mock, Guillaume Carré, Xebia: après avoir écouté, j'avoue que java+eclipse permet de travailler de manière super facile avec les mocks.


Cette conf était vraiment géniale, merci à tous!

Jean-Michel @ Café La Marine (wifi) @ Paris

PS: Un "special thanks" à Philippe Hanrigou pour avoir relu ma présentation avec attention et pour son feedback

28 April 2008

Specing actions which have session management turned off

The spec:


describe "rss action" do
before :each do
get :rss
end

it "should turn off session management" do
request.session_options.should be_false
end

end


The controller:


# turn off session management for only the atom and rss actions.
session :off, :only => %w(atom rss)
def rss
# ...
end

15 February 2008

Reducing frequency of autotest file checks

I am using RSpec 1.1.3 with ZenTest-3.9.1 and I wanted to share my set up.

If your cpu is at 100% when autotest is running and the fan noise is getting too much, don't worry there's something you can do.

You can reduce the frequency at which autotest checks for changes on your file system by adding an initialize hook in your ~/.autotest configuration:

gedit ~/.autotest



Autotest.add_hook :initialize do |at|
# Reducing frequency of autotest file checks too 30 seconds. Default is 1s which makes my laptop very hoooot
at.sleep = 30

# Ignore files with suffix
%w{.svn
.hg
.git
.rhtml
.png
.txt
.sh
.project
.rjs
.rake
.jpg
.xml
.xlst}.each { |exception| at.add_exception(exception) }
end


More information about autotest hooks in David Chelimsky blog

19 November 2007

RSpec Resources

Subscribe to the RSS of my RSpec presentations:

(click on the RSS logo)



My bookmarks with the 'rspec' tag:

24 October 2007

Output the rspec report to an html file

rake spec

Create a spec.opts with:

--format
html:doc/rspec_report.html
--loadby
mtime


=> It will generate a rspec_report.html file in your doc folder!!!

The rspec documentation actually explains it but I missed an example to start using it ...

07 June 2007

Selenium reports with screenshots using RSpec and imagemagick on ubuntu


After having read Aslak Hellesoy's post Watir reports with screenshots using RSpec and Win32::Screenshot, I got very excited because this was exactly the kind of thing I had been daydreaming while taking my morning shower (don't you?).
Aslak's article explains how to use Watir and Internet Explorer on Windows to generate rspec reports with screenshots. Garps! I am working on linux (ubuntu Feisty) as I can't afford a mac (yet) and can't stand Windows. I got a bit frustrated because I wanted to do the same thing on my ubuntu.

So, I decided to do a bit of researches and x*y*z hours later (sic), I got my selenium+rspec taking screenshots! My intention is to contribute to the RSpec sub-project spec_ui.


How does it work?


To get a 30s answer, please watch the flah screencast I have made of netbeans executing rake spec:selenium, running the selenium server, Webrick, lanching firefox and taking a screenshot after having maximized the screen.

Here is the code in spec_helper.rb :



config.before(:all, :behaviour_type => :view) do
selenium_remote_control_manager = SeleniumRemoteControlManager.new
selenium_remote_control_manager.start_webrick
selenium_remote_control_manager.start_selenium_server
@browser = selenium_remote_control_manager.get_firefox
@browser.start
end

config.after(:each, :behaviour_type => :view) do
Spec::Ui::ScreenshotFormatter.take_screenshot_of(@browser)
end

config.after(:all, :behaviour_type => :view) do
@browser.kill! rescue nil
end


And the code of contact_list_spec.rb:



describe "/contact/list", :behaviour_type => :view do
include SeleniumSpecHelper

it "should provide a description automatically (TODO extract)" do
open "/contact/list"
@browser.is_text_present("Frequently Texted").should be_true
# This line will fail :-)
@browser.is_text_present("All Contact Tak tak").should be_true
end

end




I have used imagemagick to capture the screenshot.



What's next?


I have had the chance to meet Aslak at an irb meeting in the beautiful Oslo and we talked about rspec and selenium. He told me about the idea of generating screencast from the execution of a selenium rspec and I have started to implement it. I am really close to get a solution but I will publish it by the end of july.

Here are a few features I'd like to have / implement for testing Rails Views:


  • a nice BNL compatible with watir and selenium
  • take a screenshot from the specs in order to generate nice documentation, not only when a spec fails
  • generate a good looking html doc with a sidebar - a la javadoc. And an AJAX search a la gotapi.com ;-) In a funky world, this would be connected to subversion and allow specs to be updated
  • to be completed ...

To conclude, I hope that tools such as greenpepper and RSpec are announcing the beginning of the end of "Microsoft Word" and "PrintScreen" as tools for writing specifications. Obviously, there will be some serious Manager / Customer / Developper resistance before accepting that tests are part of the delivery and THE only accurate specifications but let's wait for 5-10 years and see in 2012 how people work ;-)