RSpec 3 undefined `allow 'method for # <RSpec :: Core :: ExampleGroup ...>

describe '#messages' do
  subject do
    FactoryGirl.create :foo,
      :type => 'test',
      :country => 'US'
  end

  context 'when is not U.S.' do
    before{ allow(subject).to receive(:country).and_return('MX') }

    describe '#messages' do
      subject { super().messages }
      it { is_expected.to include 'This foo was not issued in the United States of America.' }
    end
  end
end

I am trying to assign an attribute to this topic ... I cannot force the spell to work correctly. Do I need a Double here? I am not sure how this works, and I apparently cannot decrypt the documents. Any help is appreciated.

+4
source share
2 answers

I think the problem here is one of the areas. you call the code in a block beforebefore you setsubject

you need to either move subjectto an external context, move beforeto an internal description, or configure an alternative way to call it so that it is subjectconfigured before launchbefore

0

, subject , let. , .

, :

describe '#messages' do
  let(:subject) do
    FactoryGirl.create :foo,
      :type => 'test',
      :country => 'US'
  end

  context 'when is not U.S.' do
    before{ allow(subject).to receive(:country).and_return('MX') }

    describe '#messages' do
      subject { super().messages }
      it { is_expected.to include 'This foo was not issued in the United States of America.' }
    end
  end
end 
0

All Articles