开发者

Ruby on Rails: Cucumber custom definitions for paths.rb

I trying to learn BDD way for development and just watched RailsCasts lesson for Cucumber. There i've seen approach to describe some actions like:

When I go to the list of articles
Then I should see "Pizza"

And, as i understand all those "I go to" and "I should see" constructions hardcoded somewhere. So in paths.rb i can write:

def path_to(page_name)
case page_name

when /the list of articles/
  articles_path

And it'll recognize this path next time automaticaly. And "i should see" has same feature.

So, the question: is there ant way to replace those "I go to" and "I should see" constructions with another language or custom sequences? For example:

When I constantly visi开发者_StackOverflowting the list of articles
Then I have to observe text "Pizza" 


Sure,

Cucumber uses the steps in web_steps.rb to make the call to the mapping. It looks like:

When /^(?:|I )go to (.+)$/ do |page_name|
    visit path_to(page_name)
end

Then /^(?:|I )should see "([^"]*)"(?: within "([^"]*)")?$/ do |text, selector|
  with_scope(selector) do
    if page.respond_to? :should
      page.should have_content(text)
    else
      assert page.has_content?(text)
    end
  end
end

So, I would write the following step that redirect to the standard web_steps ...

#step_definitions/my_steps.rb

When /^(?:|I )constantly visiting (.+)$/ do |page_name|
   When %{I go to #{page_name}}
end

Then /^(?:|I )have to observe text "([^"]*)" do |text|
   Then %{I should see "#{text}"}
end 

Hope this helps.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜