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

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

javascript - addthis share facebook and google+ url -

ios - Show keyboard with UITextField in the input accessory view -