Skip to content

jkremser/simple-websocket-vcr

Repository files navigation

Simple websocket VCR

Build Status Coverage Code Climate Gem Version

Based on the idea of vcr project which record the http interactions and store them as files that can be replayed later and simulate the real communication counterpart (mostly server).

However, this projects aims on the web socket protocol where normally there is only a single HTTP connection and multiple messages or frames being sent over the channel.

Usage

  it 'should record also the outgoing communication' do
    WebSocketVCR.configure do |c|
      c.hook_uris = [HOST]
    end
    WebSocketVCR.record(example, self) do
      puts 'we are recording..' if WebSocketVCR.live?
      url = "ws://#{HOST}/hawkular/command-gateway/ui/ws"
      c = WebSocket::Client::Simple.connect url do |client|
        client.on(:message, once: true, &:data)
      end
      sleep 1 if WebSocketVCR.live?
      c.send('something 1')
      c.send('something 2')
      c.send('something 3')

      expect(c).not_to be nil
      expect(c.open?).to be true
    end
  end

(source)

after running the code above, you should end up with a file that captured the interactions.

---
websocket_interactions:
- - operation: read
    event: message
    type: text
    data: WelcomeResponse={"sessionId":"XQVVtE53wxz1lmMsqz2TbmR68ilFzDxLOOpkKGpd"}
  - operation: write
    send: message
    data: something 1
  - operation: write
    send: message
    data: something 2
  - operation: write
    send: message
    data: something 3

(source)

For more details consult the specs.

About

💎 Ruby gem for testing the Simple Websocket Client - VCR support 📼 - https://rubygems.org/gems/simple-websocket-vcr

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages