Rspec 跟踪多次重复上下文?

发布于 2024-12-17 02:08:13 字数 1845 浏览 0 评论 0原文

我最近注意到我的 rspec 输出中的一个错误,特别是在失败规范的完整描述中 - 当它提前结束输出时,它总是使上下文加倍,但最近它所做的不仅仅是加倍,并且在运行不正确的情况下提前取消了。

举个例子:

  1. 当用户类型为“admin”时,在“帐户”区域中 当“用户详细信息”上的用户类型为“admin”时,在“帐户”区域中 页面 当用户类型为“admin”时,在“帐户”区域中 当“用户详细信息”上的用户类型为“管理员”时,“帐户”区域 页面的行为类似于“帐户”区域中带有帐户菜单的页面 当用户类型为“admin”时 在“帐户”区域中,当用户 在“用户详细信息”页面上的“帐户”区域中输入“admin”时 用户类型为“admin” 当用户类型为“帐户”区域时 “用户详细信息”页面上的“admin”的行为类似于带有 帐户菜单应该有一个名为“主页”的链接

失败/错误:::这里有错误消息::

可能是什么原因导致的,我该如何阻止它?

更多详情: 这种情况似乎最常发生在共享示例组中。特别是使用其他共享示例组的共享示例组。

这是我正在使用的代码类型的一个粗略的精简示例:

shared_examples "a page with a standard page header" do
 before(:each){ @header=find(:xpath,"//*[@id='page_header']") }
 it_behaves_like "a header with a user control menu"
 context "the standard menu" do
   test "should exist"
 end
end

shared_examples "a page with an administrative header" do
 before(:each){ @header=find(:xpath,"//*[@id='page_header']") }
 it_behaves_like "a header with a user control menu"
 context "the admin menu" do
  test "should exist"
 end
end

shared_examples "a header with a user control menu" do
 context "the user control menu" do
  test "should exist"
 end
end

users_type.each do |user|
 describe "/index" do
  before(:each){ @user=set_up_user(user);login_as(@user); visit(page)}
  context "when the user is a #{user.type}" do
   if(['general','mod'].includes?(@user.type))
    test "some things should be true"
    it_behaves_like "a page with a standard page header"
   elsif('admin'[email protected])
    test "some other things should be true"
    it_behaves_like "a page with an administrative header"
   else
    it_behaves_like "access denied"
   end
  end
 end
end 

I've been noticing a bug in my rspec output lately, specifically in the full description for failed specs - it always doubled the context when it ended the output early, but lately it's been doing more than doubling and in situations where the run wasn't cancelled early.

As an example:

  1. In the 'accounts' area when the user type is 'admin' In the 'accounts' area when the user type is 'admin' on the "user details"
    page In the 'accounts' area when the user type is 'admin' In the
    'accounts' area when the user type is 'admin' on the "user details"
    page behaves like a page with an Accounts Menu In the 'accounts' area
    when the user type is 'admin' In the 'accounts' area when the user
    type is 'admin' on the "user details" page In the 'accounts' area when
    the user type is 'admin' In the 'accounts' area when the user type is
    'admin' on the "user details" page behaves like a page with an
    Accounts Menu there should be a link called 'Home'

Failure/Error: ::error message here::

What could be causing this, and how can I stop it?

Further details:
It seems to occur most often with shared example groups. ESPECIALLY shared example groups that use other shared example groups.

Here is a rough, stripped down example of the kind of code I'm using.:

shared_examples "a page with a standard page header" do
 before(:each){ @header=find(:xpath,"//*[@id='page_header']") }
 it_behaves_like "a header with a user control menu"
 context "the standard menu" do
   test "should exist"
 end
end

shared_examples "a page with an administrative header" do
 before(:each){ @header=find(:xpath,"//*[@id='page_header']") }
 it_behaves_like "a header with a user control menu"
 context "the admin menu" do
  test "should exist"
 end
end

shared_examples "a header with a user control menu" do
 context "the user control menu" do
  test "should exist"
 end
end

users_type.each do |user|
 describe "/index" do
  before(:each){ @user=set_up_user(user);login_as(@user); visit(page)}
  context "when the user is a #{user.type}" do
   if(['general','mod'].includes?(@user.type))
    test "some things should be true"
    it_behaves_like "a page with a standard page header"
   elsif('admin'[email protected])
    test "some other things should be true"
    it_behaves_like "a page with an administrative header"
   else
    it_behaves_like "access denied"
   end
  end
 end
end 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文