title: How to test if a method call with arguments happened in RSpec
body: <p>In my Ruby app, I'm trying to test with RSpec a module method called with arguments from a controller.</p>
  
  <p>The module in question is the EventTracker module to track analytics: <a href="https://github.com/doorkeeper/event_tracker" rel="nofollow noreferrer">https://github.com/doorkeeper/event_tracker</a></p>
  
  <p>This is the situation:</p>
  
  <ol>
  <li><p>From my controller I call the method from the controller like below:</p>
  
  <pre><code>class InvestorHomeController &lt; ApplicationController
    def do_something
      track_event 'User Action'
    end
  end
  </code></pre></li>
  <li><p>The <code>track_event</code> method is defined inside the <code>EventTracker</code> module, like the following:</p>
  
  <pre><code>module EventTracker
    module HelperMethods
      def track_event(event_name, args = {})
        (session[:event_tracker_queue] ||= []) &lt;&lt; [event_name, args]
    end
  end
  </code></pre>
  
  <p>end</p></li>
  <li><p>I tried different solutions, but nothing worked for me. Like:</p>
  
  <pre><code>expect(controller).to receive(:track_event).with('User Action')
  expect(EventTracker).to receive(:track_event).with('User Action')
  </code></pre></li>
  </ol>
  
  <p>The first it didn't work because <code>track_event</code> is not a method of the controller,
  and for the second one I've got the error below:</p>
  
  <pre><code>RSpec::Mocks::MockExpectationError: (EventTracker).track_event("User Action")
  expected: 1 time with arguments: ("User Action")
  received: 0 times
  </code></pre>
  
  <p>Anyone knows how to test this kind of methods with RSpec?</p>
  
  <p>Thanks,
  D.</p>