In RSpec, using let variable inside before :all block

后端 未结 3 2022
眼角桃花
眼角桃花 2021-01-07 16:54

I have the following code inside most of my tests:

describe \'index\'
 let(:company) { FactoryGirl.create(:company) }
 let(:user) { FactoryGirl.create(:user,         


        
3条回答
  •  借酒劲吻你
    2021-01-07 17:43

    I'm not sure what you mean by "this" in "what is the correct way of doing this"? Accessing let and subject within a before(:all) is deprecated and will be removed in RSpec 3 with the following explanation from https://github.com/rspec/rspec-core/pull/857:

    let and subject declarations are not intended to be called in a before(:all) hook, as they exist to define state that is reset between each example, while before(:all) exists to define state that is shared across examples in an example group.

提交回复
热议问题