FactoryGirl create vs. build

Problem: we have the before_save callback for a provider, and we want to test whether this callback is executed correctly.

The test passes

    context 'valid provider' do
      let(:provider) { FactoryGirl.build(:provider) }

      it 'get triggered when saved' do
        expect(provider).to receive(:test_before_save_callback)
        provider.save!
      end
    end

Even when we force the creation of provider with let, the test still passes.

    context 'valid provider' do
      let!(:provider) { FactoryGirl.build(:provider) }

      it 'get triggered when saved' do
        expect(provider).to receive(:test_before_save_callback)
        provider.save!
      end
    end

 

Advertisements