Every now and then people ask about how to package reusable step definitions in a gem. Another popular request is translations of webrat_steps.rb into other languages.
Since I want to keep Cucumber slim and easy for me to maintain, I don't want to package lots of step definitions into Cucumber, but I do think that reusable step definitions in gems, possibly i18n'ed could be helpful for a couple of reasons:
1) It would help newbies who are not sure how to write good step definitions 2) It would consolidate our community a little more
For example, on thing that I would like to see in a gem is cucumber's own step definitions, which are handy for apps with a command line interface. (They'd have to be honed a little to be generally useful, but that shouldn't be a big job).
Here are already a few efforts in this space that I know of:
These are all great little projects, so chip in if you want to help out! Who wants to create a cucumber_webrat_i18n project? I'd provide Norwegian and French translations :-)
> Every now and then people ask about how to package reusable step definitions
> in a gem.
> Another popular request is translations of webrat_steps.rb into other
> languages.
> Since I want to keep Cucumber slim and easy for me to maintain, I don't want
> to package lots of step definitions into Cucumber,
> but I do think that reusable step definitions in gems, possibly i18n'ed
> could be helpful for a couple of reasons:
> 1) It would help newbies who are not sure how to write good step definitions
> 2) It would consolidate our community a little more
> For example, on thing that I would like to see in a gem is cucumber's own
> step definitions, which are handy
> for apps with a command line interface. (They'd have to be honed a little to
> be generally useful, but that shouldn't
> be a big job).
> Here are already a few efforts in this space that I know of:
> These are all great little projects, so chip in if you want to help out! Who
> wants to create a cucumber_webrat_i18n project? I'd provide Norwegian and
> French translations :-)
> Aslak
Last week I started my first rails application using cucumber step
definitions not written in English.
These are the features I wished the cucumber generator had while
setting it up:
1) Localized version of the webrat_steps
2) cucumber.yml with default and autospec profiles set for the chosen
language
My first attempt on translating the steps with maintainability in mind
was to simply call the English steps from the localized ones, as can
be seen on this gist:
http://gist.github.com/151803
Although I have doubled the steps to accomplish the same stuff, I'll
only have to update the translated steps if future releases change the
English regular expressions.
I'm willing to help out. I have been working on a gem that does/will do
precisely what you want. I just put the code I already have on github (
http://github.com/jeroenvandijk/interlingua/<http://www.github.com/jeroenvandijk/interlingua>)
to give you an idea. This could be become part of cucumber or something like
what ActiveSupport is for Rails. Below is an explaination of the features.
Note that it is still far from complete but since you started this thread I
wanted to show what I have already done.
I'm currently working on a application written for Dutch users. I have
decided to write all the features in Dutch because this obviously is closer
to the mindset of the users. However, I also knew that I couldn't use all
the available webrat steps, not to mention all the available plugins (e.g.
pickle, email_spec). Plus Dutch has also some exceptions that make you
define the same steps twice:
English:
Then I should see "a"
And I should see "b"
Dutch:
Dan moet ik "a" zien
En ik moet "b"
As you can see in English you just need one step definition to have two
grammatically correct sentences whereas in Dutch you need two. Because of
all these productivity killers I decided to write my own plugin that would
make this possible without all the hassle.
On http://github.com/jeroenvandijk/interlingua/<http://www.github.com/jeroenvandijk/interlingua>you
can find an alpha version of the plugin I'm working on. The idea is
that
there is one API and for each new language there is a yaml file needed which
define the step translations (see lib/interlingua/languages/nl.yml to get
the idea). The actual regular expressions for the steps are obtained by
parsing the string in the yaml files.
The current features of the plugin (which could also make it interesting for
English features):
- definition of common steps
- exploit of Rails I18n by guessing paths and reporting when translations or
routes are missing:
- easily translate steps and have multiple translations for the same steps
(as above)
TODO:
- Create a test task that tests if an added language is correctly
implemented
- Adding more steps with plugins as pickle as an example
Possible future features:
- exploiting the API by using it for other purposes than testing e.g. for
auto-completion, for creating a visual user manual, translating features in
other languages
I'm very eager for feedback so please let me know if you have ideas for
features or suggestions for improving the architecture etc.
On Wed, Jul 22, 2009 at 6:50 AM, aguids <felipe.do...@gmail.com> wrote:
> On Jul 21, 8:15 pm, aslak hellesoy <aslak.helle...@gmail.com> wrote:
> > Every now and then people ask about how to package reusable step
> definitions
> > in a gem.
> > Another popular request is translations of webrat_steps.rb into other
> > languages.
> > Since I want to keep Cucumber slim and easy for me to maintain, I don't
> want
> > to package lots of step definitions into Cucumber,
> > but I do think that reusable step definitions in gems, possibly i18n'ed
> > could be helpful for a couple of reasons:
> > 1) It would help newbies who are not sure how to write good step
> definitions
> > 2) It would consolidate our community a little more
> > For example, on thing that I would like to see in a gem is cucumber's own
> > step definitions, which are handy
> > for apps with a command line interface. (They'd have to be honed a little
> to
> > be generally useful, but that shouldn't
> > be a big job).
> > Here are already a few efforts in this space that I know of:
> > These are all great little projects, so chip in if you want to help out!
> Who
> > wants to create a cucumber_webrat_i18n project? I'd provide Norwegian and
> > French translations :-)
> > Aslak
> Last week I started my first rails application using cucumber step
> definitions not written in English.
> These are the features I wished the cucumber generator had while
> setting it up:
> 1) Localized version of the webrat_steps
> 2) cucumber.yml with default and autospec profiles set for the chosen
> language
> My first attempt on translating the steps with maintainability in mind
> was to simply call the English steps from the localized ones, as can
> be seen on this gist:
> http://gist.github.com/151803
> Although I have doubled the steps to accomplish the same stuff, I'll
> only have to update the translated steps if future releases change the
> English regular expressions.
I found it curious, that cucumber doesn't seem to have translations in
the languages.yml file for the top level constructs of a feature, such
as "In order" and "As a".
I also had a need for a danish webrat translation. I have since
created a webrat_da.rb. Where would I submit such a patch for reuse?
> I found it curious, that cucumber doesn't seem to have translations in
> the languages.yml file for the top level constructs of a feature, such
> as "In order" and "As a".
These words aren't parsed by Cucumber. These words don't even exist for
English in the Cucumber codebase. However, the Cucumber.tmbundle uses them
in the feature snippet.
Cucumber ignores everything up to the first Scenario, Scenario Outline or
Background. In fact, even the Feature keyword is ignored. It is currently
only used by syntax highlighting tools such as Cucumber.tmbundle. (Cucumber
might parse the Feature word in the future though).
> I also had a need for a danish webrat translation. I have since
> created a webrat_da.rb. Where would I submit such a patch for reuse?
I won't put webrat_steps translations into Cucumber. Too much maintenance.
It would be great if someone would take Cucumber's Rails generator, extract
it into a separate project on github and package it as a gem
(cucumber-rails). If that happens I think it's OK to have several
translations there.
>> Could you do this change to cucumber-rails-test, Dennis?
> I did this and guess it works fine, can you verify that? I just sent you a > pull request.
Looks good. I also moved lib/cucumber/rails from cucumber to my fork of cucumber-rails. I have deleted all the rails related stuff from cucumber now. It's currently on my remove-rails branch. Once I get gemcutter karma from you I'll push cucumber-rails-0.1.1.rc1 and cucumber 0.4.4.rc1 so people can check if stuff is still working after this split. If that's ok I'll merge remove-rails onto master and release cucumber-rails-0.1.1 and cucumber-0.4.4.
Since the "main" cucumber-rails project is yours it is the only one that can have Github tickets. I have created 2 tickets there and closed the associated ones in LH. Let's keep the bugs with the projects. (Already done like this for Cuke4Duke and Cuke4Nuke).
If you don't mind I'd like to control releases of cucumber-rails in the start - just to see that everything is OK. (git tagging, pushing gems to gemcutter). Then I'll happily give that honor over to you Dennis (or anyone else who wants it).
>>> Is there a way to use the localized keywords (instead of Given/When/ >>> Then) in the step definitions?
>> Yes - the methods are aliased when Cucumber parses a Feature file of a >> different i18n language (which happens before ruby files are loaded).
> Hmm, maybe you can go ahead with the norwegian version and I'll see what I'm > doing wrong.
>> On Sun, Nov 8, 2009 at 4:58 PM, dbloete <dblo...@gmail.com> wrote:
>>>> I won't put webrat_steps translations into Cucumber. Too much >>>> maintenance. >>>> It would be great if someone would take Cucumber's Rails generator, >>>> extract >>>> it into a separate project on github and package it as a gem >>>> (cucumber-rails). If that happens I think it's OK to have several >>>> translations there.
>>> So far I've just added a language argument to the cucumber generator >>> and a german version of the webrat_steps.rb. >>> I'd like to get some feedback on whether or not this is a good way to >>> add localization.
>>> Is there a way to use the localized keywords (instead of Given/When/ >>> Then) in the step definitions?
>> Yes - the methods are aliased when Cucumber parses a Feature file of a >> different i18n language (which happens before ruby files are loaded).
>> I can add Norwegian translations - I already have most of the steps >> translated at work.
>> I have a cucumber_rails project >> (http://github.com/aslakhellesoy/cucumber-rails-test) that is used to >> test Cucumber against various versions of Rails (I just renamed it >> from cucumber_rails to avoid confusion with your new cucumber-rails >> gem).
>> If/when I delete the code you have moved over from cucumber, we'll >> need to modify cucumber-rails-test to install cucumber-rails as a >> plugin - so it can be tested with the latest versions of both cucumber >> and cucumber-rails.
>> Could you do this change to cucumber-rails-test, Dennis?
>> Cheers, >> Aslak
>>> I saw that the aforementioned Gist did >>> that, but I couldn't get this going with the german keywords.