小编Sha*_*nia的帖子

Rubocop RSpec/MultipleMemoizedHelpers 关于专家规范测试的问题

我使用 pundit 进行授权,使用 RSpec 在我的 Rails 应用程序中进行测试。因此,我必须为策略创建规范。

但是,我遇到 rubocop 抛出错误的问题:RSpec/MultipleMemoizedHelpers。我明白这意味着我有太多的let电话subject。我的问题是我不太确定如何解决或重构我的代码,以便它符合我应该进行的正确调用次数。

另一件事,可以为规范文件禁用 RSpec/MultipleMemoizedHelpers 吗?

以下是三个存在问题的策略规范文件。

require "rails_helper"

describe AnswerPolicy do
  subject { described_class }

  let(:user_admin) { build(:user, :admin) }
  let(:consultant) { build(:consultant) }
  let(:user_consultant) { build(:user, :consultant, consultant: consultant) }
  let(:client) { build(:client, consultant: consultant) }
  let(:user_client) { build(:user, :client, client: client) }
  let(:other_client) { build(:client, consultant: build(:consultant)) }
  let(:answer) { build(:answer, client: client) }
  let(:other_answer) { build(:answer, client: other_client) }

  permissions :update? do
    it "allows access …
Run Code Online (Sandbox Code Playgroud)

ruby rspec ruby-on-rails pundit rubocop

11
推荐指数
1
解决办法
5959
查看次数

标签 统计

pundit ×1

rspec ×1

rubocop ×1

ruby ×1

ruby-on-rails ×1