Currently using Pusher and RSpec.
Pusher.should_receive( :trigger ).with( 'message', { :data => '12345' })
This would work, except the call is Pusher[ 'channel-id' ].trigger...
How to mock this with RSpec?
Well [] is a function name so it can be stubbed. In the Pusher source you see: def_delegators :default_client, :webhook, :channel, :[] So all of these methods are forwarded to default_client. So this is actually a chain of methods.
I would do what you want to do like this.
mock_client = mock('client')
Pusher.stub(:[]).with('channel-id').and_return(mock_client)
mock_client.should_receive( :trigger ).with( 'message', { :data => '12345' })
I do not have rspec handy right now, but see no reason why it would not work.
There is also pusher-fake which starts up a fake server for your tests, so you don't have to stub – it lets your app both send and receive via that fake server.