Skip to content
bnorton edited this page Mar 26, 2013 · 3 revisions
  1. Use the Custom rspec matcher for asynchronous expectations on class instances :should_receive_async (Coming soon)
  2. Use a direct :should_receive on the _async post-fixed method you want to call.
describe User do
  describe '#save' do
    describe 'on create' do
      let(:user) { FactoryGirl.build(:user) }

      # a model instance
      it 'should update the social profile' do
        user.should_receive_async(:update_social_profile) # Custom rspec matcher (1.)

        user.save!
      end
    end

    describe 'when the user changes' do
      before do
        user.last_event = event
      end

      # Dedicated Worker Class
      it 'should update social data' do
        SocialDataUpdater.should_receive(:perform_async).with(user.id) # direct message expectation (2.)

        user.save!
      end
    end
  end  
end

Clone this wiki locally