创建动态cucumber_steps以检查页面上的链接

时间:2011-07-24 22:52:18

标签: ruby-on-rails-3 cucumber integration-testing rspec2

基本上我希望场景大纲循环遍历所有各种组合,这样我就不必编写一堆场景。我想让它访问起始页面,然后检查链接是否在那里,但是我遇到了障碍。

黄瓜功能

    Scenario Outline: As a user I need links in order to navigate the site
    Given I am a '<user>'
    When I am at the <page> page
    Then I should see a link to '<link>'

    Scenarios: As a user that is not logged in
        |       user         |   page    |  link   |
        | not_signed_in_user |    /      | contact |

黄瓜功能步骤

    Given /^I am a 'not_signed_in_user'$/ do
         @user = nil
    end

    When /^I am at the (.+) page$/ do |starting_page|
         visit starting_page
    end

    Then /^I should see a link to (.+)$/ do |link|
         pending
    end

我需要使用类似的东西:

    response.should have_selector('a,':href => link_path,
                                     :content => link )

但这不会动态,因为它只会检查link_path ...

1 个答案:

答案 0 :(得分:1)

听起来你想在这里使用send("#{link}_path")。这将使用路由助手生成链接,我认为这是你想要的。