Localized Steps with Cucumber
Today i was once again annoyed, by having tests calling steps like...
Then I should see "Thank you for your Message"
This neccessarly causes the step to fail, whenever the locales for this message are changed, and thats definitely not what we want.
Well, so i thought about it for a minute, came up with the logical conclusion of modifying step definitions to process the localization, was to lazy to test it out, complained in my favourite irc channel, and someone sent me this link: http://www.railway.at/articles/2009/09/12/using-cucumber-to-test-a-multilingual-app/
As it was exactly what i wanted, i added those modified steps to a file i called localized_steps.rb.
Two problems coming up:
1. cucumber did not know wether to use the original step from web_steps.rb or the ones in localized_steps.rb
2. i did not yet change all steps to use localized strings, to they would all fail, and i'd prefer doing it step by step, as there is not the time for modifying all the tests now.
Solution: I explicitly choose wethere i use the step with localization or with a plain string.
# localized_steps.rb
When /^I press localized "([^\"]*)"$/ do |key|
click_button(I18n.t(key))
end
When /^(?:|I )follow localized "([^\"]*)"$/ do |key|
click_link(I18n.t(key))
end
When /^(?:|I )follow localized "([^\"]*)" within "([^\"]*)"$/ do |key, parent|
click_link_within(parent, I18n.t(key))
end
Then /^I should see localized "([^\"]*)"$/ do |key|
response.should contain(I18n.t(key))
end
Trackbacks
Verwenden Sie den folgenden Link zur Rückverlinkung von Ihrer eigenen Seite:
http://praktikanten.brueckenschlaeger.org/trackbacks?article_id=28