RSpec 和 FactoryGirl

RSpec and FactoryGirl

我目前有一个 RSpec 测试:

    Rspec.describe Some::ServiceClass do 
      args = ['1', '2']
      subject { described_class.new(args) }

      describe '#finder_method' do 
        let(:user_1) { FactorGirl.create(:user) } 

        it 'returns the right number of users' do
          expect(subject.finder_method.count).to eq(1)
        end
      end
    end 

这就是被测 class 的样子

   module Some

      class Service

        ....
        # other methods used to identify the resource model

        def finder_method 
          resource.all
        end
      end

    end

预期

实际结果

谁能解释一下为什么会这样? FactoryGirl 创建的 user_1 在哪里?

呃!!

let 是罪魁祸首......完全忘记了它被懒惰地评估。我需要睡一觉:(