I'm trying to test that the subject has called get_auth_token, but I don't 
think I can do that the way I have my code written.

>From what I understand, I'm supposed to have a test spy set up before 
actually calling the code I'm testing, to sort of record/observe which 
methods are called on the spy object.

I guess that is complicated by the fact that my subject is defined as 
Yotpo::BackendApi.new

So I guess my question is, how would you set any expectations on the 
instance before the instance even exists yet? Or would this indicate that I 
have a code smell, and I need to re-think my design?

RSpec.describe Yotpo::BackendApi do
  subject { Yotpo::BackendApi.new }

  describe 'class constants' do
    it 'has STORE_ID' do
      expect(described_class).to have_constant(:STORE_ID)
    end

    it 'has CLIENT_SECRET' do
      expect(described_class).to have_constant(:CLIENT_SECRET)
    end
  end

  describe '::new' do
    it 'calls #get_auth_token' do
      expect(subject).to have_received(:get_auth_token)
    end
  end
end

-- 
You received this message because you are subscribed to the Google Groups 
"rspec" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rspec+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rspec/b740b5d6-ea89-4819-b861-de5744f689e4n%40googlegroups.com.

Reply via email to