mardi 12 avril 2016

How to test chains of methods in rspec. Delay is one of them

I am trying to write a test like this:

  it 'logs events' do
        expect(Event).to receive("delay.create!").with(hash_including(
                                                    app_context: app_context,
                                                    event_type: Event::EventType::FOOD_SUBSCRIPTION_STARTED))
        subject
      end

for code that looks like this:

Event.delay.create!(
      event_type: event_type,
      description: 'Automatically populated',
      date: Time.now.utc,
      eventable: user,
      app_context: app_context
    )

I want to just test that at some point, Event is called with .delay and .create and that the hash passed to create contains 2 key-value pairs. How do I do this?

Event.delay just returns a long string of numbers and letters so I don't think I want to stub that?

Aucun commentaire:

Enregistrer un commentaire