Rspec:仅当会话条件为真时才运行测试
假设我有一个共享示例组。该小组进行测试以确保网站的每个页面上都存在正确的菜单。
问题是每一页上的菜单并不相同,只是几乎相同。例外情况是菜单不包含指向您当前正在测试的页面的链接。因此,需要跳过该测试。作为测试套件的一部分,我有所有链接的完整列表。
测试这个的最好方法是什么?通常,我只会有条件地生成测试,但由于它取决于包含共享示例的上下文(页面标识),因此当我获得所需信息时,已经太晚了。我可以进行像这样的测试 link_list.each 做 |link| 它“应该存在于该页面上,除非该页面位于例外列表中” if(@session.not_on(列表)) @session.should not_have_link(链接) 别的 @session.should have_link(链接) 结尾 结尾 结束
但我认为最好避免这种模棱两可的测试。此时,我将知道会发生什么行为,因为我可以检查会话页面是否在列表中,但我不知道如何表达这一点。
我可以做什么来获得我想要的行为?
Say I have a share example group. This group tests to make sure the correct menu exists on every page on the site.
The problem is the menu is not identical on each page, merely nearly identical. The exception is that the menu does not include a link to the page you are currently testing. As such, that test needs to be skipped. I have, as a component of the testing suite, a full list of all the links.
What would be the best way to test this? Normally, I would just have the test conditionally generated, but since it depends on the context (the page identity) of where the shared example is included, by the time I have that bit of required information it is too late to do so. I could have a test like
link_list.each do |link|
it "should exist on this page unless this page is on the exception list" do
if(@session.not_on(list))
@session.should not_have_link(link)
else
@session.should have_link(link)
end
end
end
but I think ambiguous tests of this sort are best avoided. By this point, I will KNOW what behaviour to expect, since I can check to see whether the session page is or is not on the list, but I don't know how to express that.
What can I do to get the behaviour I want?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论