Ben Biddington

Whatever it is, it's not about "coding"

Posts Tagged ‘cucumber

Outside-in development taken too far

with 2 comments

You may feel someone is taking things too far when you receive a set of scenarios like this:

Scenario 1: Warm Teapot

Given a Kettle of Boiling Water
When Boiling Water is poured in to the Teapot
Then it should* warm the Teapot

Scenario 2: Brewing the tea

Given a Kettle of Boiling Water
And 5 Teabags
When 5 Teabags are placed in the Teapot
And Boiling Water is poured in to the Teapot
And the Teapot is left with the above ingredients in it for 5 minutes
Then you should have Brewed Tea

Scenario 3: Pouring the tea

Given a Teapot of Brewed Tea
And a Mug with some Milk in it**
When the Brewed Tea is poured in to the Mug
Then you should have a Perfect Cup of Tea

* “Do or do not. There is no should”
** Debatable. I think we need to triangulate this, or consult the client.

Written by benbiddington

3 August, 2010 at 13:37

Posted in development

Tagged with , , ,

Passing cucumber specs on windows

leave a comment »

I had some trouble getting cucumber test features to pass on Windows due to directory separator differences, something like:
 Failing Scenarios:
-cucumber features/background/failing_background.feature:8 # Scenario: failing background
+cucumber features\background\failing_background.feature:8 # Scenario: failing background
There is an easy solution — run features with windows_mri profile, which results in the CUCUMBER_FORWARD_SLASH_PATHS environment variable being set to true.

Example

cucumber features/background.feature:93 -p windows_mri

Written by benbiddington

20 April, 2010 at 13:37

Posted in development

Tagged with , , ,

Rake — shell task failure

leave a comment »

For my current project, we’re running cucumber as one of our tasks. Our report generation runs afterwards — which we need to happen regardless of cucumber’s exit code (cucumber exits with code 1 when any tests fail).

Handling shell task failure

We noticed that if cucumber fails, rake exits immediately — without running our subsequent report tasks.

We’re running cucumber with rake’s ruby function — which runs the ruby interpreter in its own process by invoking a shell command.

Pseudo-stacktrace (irrelevant source lines omitted):

Shell::CommandProcessor.system(command, *opts)
Rake::Win32.rake_system(*cmd)
FileUtils.sh(*args, &block)
FileUtils.ruby(*args, &block)

The key to this is the behaviour of rake’s FileUtils.sh. Examining the source shows:

If it is not supplied a block, and the shell command fails, and rake exits with error status.

Aside: For some reason, Kernel.system echoes errors.

Example

This task will cause rake to exit immediately with status 1:

task 'this-one-fails' do
    ruby("xxx")
end

while the following task does not cause rake to terminate  normally, any subsequent task will still run:

path = File.expand_path(File.dirname(__FILE__) + ‘/output/cucumber-manual.txt’)
cuke_path = ‘C:/ruby/lib/ruby/gems/1.8/gems/cucumber-0.3.3/bin/cucumber’
ruby(“#{cuke_path} -h > ‘#{path}'”) do |success, exit_code|
puts “Exited with code: #{exit_code}” if !success
end
task 'this-one-succeeds' do
    ruby("xxx") do |success, exit_code|
        puts "Exited with code: #{exit_code.exitstatus}" unless success
    end
end

Getting the last exit status

The $? variable contains the status of the last child process to terminate. This may be useful if steps subsequent to the failed one require this information.

Written by benbiddington

16 May, 2009 at 16:45