I'm doing what it says in the subject line, and I thought I'd post
some
notes and links. For those who don't know, Cucumber (http://cukes.info/
) is
a BDD tool, successor to RSpec's story runner, that lets you
describe
desired behavior ("features") in something that looks like human
language,
and then write the code that defines the behavior ("steps") in
Ruby. Webrat
(http://github.com/brynary/webrat/tree/master) is an acceptance
testing tool
that lets you write steps that emulate browser interaction -
clicking links,
filling in forms - without the overhead of actually firing up a
browser.
You all know what Radiant is.
(I'm working with Radiant 0.6.9, unfortunately, because I want my
extension
to support an existing site. But I suspect the basic steps will
apply to
0.7.)
The basic setup went pretty quickly. The instructions for using
Cucumber
with Rails (http://wiki.github.com/aslakhellesoy/cucumber/ruby-on-rails
) go,
roughly:
- install a bunch of gems
- create a Rails project (I already had a Radiant project)
- run the cucumber generator
In my case, script/generate didn't know about Cucumber, I guess
because
Radiant looks for generators in other places. So I created a new
Rails
project, ran the generator there, and copied the files that looked
useful
into my Radiant extension. I'm reconstructing this from the git
commit - it
looks like the files were:
- features/step_definitions/webrat_steps.rb
- features/support/paths.rb
- features/support/env.rb
I modified env.rb in two ways:
- The path to config/environment is three steps higher
(../../../).
- Load fixtures from spec/ (see
http://wiki.github.com/aslakhellesoy/cucumber/fixtures).
That was pretty much it - I'm now able to start writing features
and steps.
There was one major hitch. I wrote a step definition that goes
like this:
When /^I visit the "(.+)" admin page$/ do |page|
visit page_edit_path(Page.find_by_title(page))
end
... and a feature that goes like this, in part:
When I visit the "Anno Domini" admin page
And I fill in "Address" with "366 So. First Street, San Jose, CA
95113"
And I press "Save and Continue Editing"
You can guess what that does. On the last step, when the form was
submitted, I got the error "Couldn't find Page without an ID".
The edit
form, in the test environment only, was being created with
action="/admin/page/edit" (note the missing page ID) instead of
"/admin/pages/edit/3".
Turns out that in the test environment, Radiant adds its own test
fixtures
to the extension paths. If you're configured to load all
extensions, that
will include BasicExtension, which sets up a default route that
gets in the
way of page_edit_path, and probably a lot of other paths.
For anyone else traveling this path, the way I got around this was
to ensure
my extension was the only one loaded, by putting this line in
config/environment.rb in my project:
config.extensions = [ :locations ] if config.environment == 'test'
There may be a better way, but this is probably good enough.
Looking
forward, I see that in 0.7, the route that caused the trouble is
commented
out.
Hope this is useful. When the extension is a little more
functional, I plan
to put it up on Github, so there'll be some sample code.
Meantime, Aslak
Hellesoy's Ba extension (http://github.com/aslakhellesoy/ba/tree/master
) is
I think a little behind current practices, but it's where I got
most of my
ideas.
--Erik Ostrom
e...@echographia.com
_______________________________________________
Radiant mailing list
Post: Radiant@radiantcms.org
Search: http://radiantcms.org/mailing-list/search/
Site: http://lists.radiantcms.org/mailman/listinfo/radiant