Skip to content
代码片段 群组 项目
未验证 提交 e3880ee9 编辑于 作者: Peter Leitzen's avatar Peter Leitzen
浏览文件

Add new cop rule RSpec/FactoryBot/StaticAssignment

Flag local assignments during factory "load time". This leads to
static data definitions.

Move these definitions into attribute block or
`transient` block to ensure that the data is evaluated during
"runtime" and remains dynamic.

Example:
  # bad
  factory :foo do
    random = rand(23)
    baz { "baz-#{random}" }

    trait :a_trait do
      random = rand(23)
      baz { "baz-#{random}" }
    end

    transient do
      random = rand(23)
      baz { "baz-#{random}" }
    end
  end

  # good
  factory :foo do
    baz { "baz-#{random}" }

    trait :a_trait do
      baz { "baz-#{random}" }
    end

    transient do
      random { rand(23) }
    end
  end
上级 e3ca06ff
No related branches found
No related tags found
加载中
加载中
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册