Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jkremser/simple-websocket-vcr
:gem: Ruby gem for testing the Simple Websocket Client - VCR support :vhs: - https://rubygems.org/gems/simple-websocket-vcr
https://github.com/jkremser/simple-websocket-vcr
ruby-gem websocket websocket-vcr
Last synced: 3 months ago
JSON representation
:gem: Ruby gem for testing the Simple Websocket Client - VCR support :vhs: - https://rubygems.org/gems/simple-websocket-vcr
- Host: GitHub
- URL: https://github.com/jkremser/simple-websocket-vcr
- Owner: jkremser
- License: apache-2.0
- Created: 2016-03-21T17:33:03.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2019-05-21T12:53:13.000Z (over 5 years ago)
- Last Synced: 2024-10-30T00:27:28.262Z (4 months ago)
- Topics: ruby-gem, websocket, websocket-vcr
- Language: Ruby
- Homepage:
- Size: 51.8 KB
- Stars: 4
- Watchers: 1
- Forks: 4
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGES.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# Simple websocket VCR
[![Build Status](https://travis-ci.org/Jiri-Kremser/simple-websocket-vcr.png?branch=master)](https://travis-ci.org/Jiri-Kremser/simple-websocket-vcr)
[![Coverage](https://coveralls.io/repos/github/Jiri-Kremser/simple-websocket-vcr/badge.svg?branch=master)](https://coveralls.io/github/Jiri-Kremser/simple-websocket-vcr?branch=master)
[![Code Climate](https://codeclimate.com/github/Jiri-Kremser/simple-websocket-vcr/badges/gpa.svg)](https://codeclimate.com/github/Jiri-Kremser/simple-websocket-vcr)
[![Gem Version](https://badge.fury.io/rb/simple-websocket-vcr.svg)](https://badge.fury.io/rb/simple-websocket-vcr)Based on the idea of [vcr](https://github.com/vcr/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
```Ruby
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](https://github.com/Jiri-Kremser/simple-websocket-vcr/blob/master/spec/vcr_spec.rb#L46))after running the code above, you should end up with a file that captured the interactions.
```yaml
---
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](spec/fixtures/vcr_cassettes/VCR_for_WS/should_record_also_the_outgoing_communication.yml))For more details consult the [specs](spec/vcr_spec.rb).