It’s a well known fact that one can use cucumber with any testing framework. There are a lot of posts on that, but basically one needs to comment out lines that require rspec in features/support/env.rb and update a couple of step definitions that use rspec in features/step_definitions/webrat_steps.rb

If you use shoulda in particular, it also works just fine, however you’ll notice that you can’t use controller macros in step definitions. Although this is correct in terms of ideology (you should be using them in functional tests instead) and technology (macros are not included in ActionController::Integration::Session which is the context of cucumber step definitions) depending on the way you use Cucumber and write your features, you may want to use them.

First, you’ve got to mix Cucumber and shoulda matchers by adding this line to features/support/env.rb:

World(Shoulda::ActionController::Matchers)

It will make matchers accessible in your step definitions. At this point, if you were using Rspec you could relax, cause the following step definition would work perfectly:

Then /^the "(.*)" layout should be used$/ do |layout|
@controller.should render_with_layout(layout)
end

But since you’re a shoulda addict, read on.

Shoulda macros are supposed to be class methods of Test::Unit::TestCase and they obviously won’t work as instance methods of ActionController::Integration::Session. But if you take a peek at the sources of standard macros, you’ll notice that they use matchers (which makes sense to avoid duplication) internally.

Besides matchers and macros shoulda adds a bunch of assertions to your tests. One of them is assert_accepts, that takes a matcher and an object that’s being tested and asserts that the object meets the matcher requirements. Exactly this assertion is used in the standard shoulda macros and you can use it as well in your step definitions:

Then /^the "(.*)" layout should be used$/ do |layout|
assert_accepts render_with_layout(layout), @controller
end

And that’s it. You’ve got access to shoulda matchers in your cucumber step definitions without rspec, which is basically the same as using macros.

Now one could argue that you should not test which layout is rendered in your acceptance tests. And personally I don’t. But as I mentioned above, it depends on the way you use cucumber. It’s just a tool and there many ways it could be used. I would say that if it makes you productive and your software more robust and maintainable, you’re doing it right.