无论页面内容如何,Cucumber/capybara 功能始终会通过
我有以下黄瓜场景:
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
即使我在功能或视图中将“删除”一词更改为“这永远不会起作用”,该功能总是会通过。然而,在浏览器中,“删除”链接仅正确显示在具有“看门人”角色的用户的文章上。
Cucumber 的“显示页面”和“显示响应”似乎没有被定义,尽管大量文章建议它们应该被定义。 (我的 env.rb)
其他功能似乎按预期工作。有人能发现我哪里出了问题吗?
I have the following cucumber scenario:
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
...and the definition for that last step:
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
Even if I change the word "Delete" to "this should never work" in either the feature or the view, the feature always passes. In the browser, however, the "Delete" link correctly only appears on articles for users who have the "janitor" role.
Cucumber's "show me the page" and "show me the response" don't seem to be defined, despite a large number of articles suggesting they should be. (My env.rb)
Other feature seem to work as expected. Can anybody spot where I'm going wrong with this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我在你的测试中没有看到任何断言。尝试将
article.should_not have_css('a', text: content)
更改为assertarticle.should_not have_css('a', text: content)
,依此类推。编辑:
结果是什么?
恕我直言,您应该使用查找助手,然后对您找到的元素进行断言。我想知道您在该块中有什么可用的“文章”。
I see no assertions in your test. Try changing
article.should_not have_css('a', text: content)
toassert article.should_not have_css('a', text: content)
, and so on.Edit:
What's the result of?
Imho you should use find helper and then make assertions on the element you find. I wonder what you have available in the block as "article".