How to mock Pusher with RSpec in Ruby? -
currently using pusher , rspec.
pusher.should_receive( :trigger ).with( 'message', { :data => '12345' })
this work, except call pusher[ 'channel-id' ].trigger...
how mock rspec?
well []
function name can stubbed. in pusher source see: def_delegators :default_client, :webhook, :channel, :[]
of these methods forwarded default_client
. chain of methods.
i want this.
mock_client = mock('client') pusher.stub(:[]).with('channel-id').and_return(mock_client) mock_client.should_receive( :trigger ).with( 'message', { :data => '12345' })
i not have rspec handy right now, see no reason why not work.
Comments
Post a Comment