2012-02-13 105 views
0

我有以下黄瓜场景:黄瓜/水豚功能总是通过不分页面内容

Background: 
    Given the following roles exist: 
    | id | name | 
    | 1 | janitor | 
    And the following users exist: 
    | username | password | email    | role_ids | 
    | janitor | Cleaning31 | [email protected] | 1  | 
    And I am logged in as "janitor" with password "Cleaning31" 
    And the following articles exist: 
    | id | title  | slug  | content  | 
    | 1 | Article One | article-one | Article one. | 

Scenario: Seeing link for deleting an article 
    When I view the article list 
    Then I should see the "Delete" link for article 1 

...并为最后一步的定义:

Then /^I should (not)?see the "([^"]*)" link (?:in|under|for) article (\d+)$/ do |negation, content, article_id| 
    page.should have_selector("\#article_#{article_id}") do |article| 
    if negation 
     article.should_not have_css('a', text: content) 
    else 
     article.should have_css('a', text: content) 
    end 
    end 
end 

即使我改变在特征或视图中将单词“删除”改为“该不应该工作”,该特征总是通过。然而,在浏览器中,“删除”链接正确地只出现在具有“看门人”角色的用户的文章中。

尽管大量的文章暗示他们应该是黄瓜的“显示我的网页”和“显示我的回应”似乎并没有被定义。 (我的env.rb

其他功能似乎按预期工作。任何人都可以发现我在哪里错了吗?

回答

3

我在您的测试中看不到任何断言。尝试将article.should_not have_css('a', text: content)更改为assert article.should_not have_css('a', text: content),依此类推。

编辑:

结果是什么?

element = page.find("\#article_#{article_id}") 
if negation 
     element.should_not have_css('a', text: content) 
else 
     element.should have_css('a', text: content) 
end 

Imho你应该使用find助手,然后对你找到的元素作出断言。我想知道你在这个块里有没有可用的“文章”。

+0

谢谢,但这并没有什么区别;无论内容如何,​​它仍然通过。所有其他功能都以相同的风格编写,并且能够正常工作 - 当然.should_not和.should本身就是断言。 – 2012-02-14 10:14:29

+0

在我的答案中进行了编辑。 – socjopata 2012-02-14 11:36:15

+0

工作,谢谢!我想知道我是否试图在水豚中使用Webrat风格? – 2012-02-14 14:24:06