https://github.com/carbonfive/nock-vcr
Automate the recording and plack-back functionality provided by nock.
https://github.com/carbonfive/nock-vcr
Last synced: about 1 year ago
JSON representation
Automate the recording and plack-back functionality provided by nock.
- Host: GitHub
- URL: https://github.com/carbonfive/nock-vcr
- Owner: carbonfive
- Created: 2013-01-26T05:31:16.000Z (over 13 years ago)
- Default Branch: master
- Last Pushed: 2013-01-28T03:52:24.000Z (over 13 years ago)
- Last Synced: 2025-03-25T19:51:22.486Z (about 1 year ago)
- Size: 108 KB
- Stars: 28
- Watchers: 71
- Forks: 4
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
#Nock-VCR
Like the Ruby [VCR][VCR] gem, record your test-suite's HTTP interactions
and replay them during future runs for speedy, deterministic, and
accurate tests. Built atop [nock][nock]'s testing and recording
capability.
## Installation
```sh
npm install nock-vcr
```
## Usage
In your tests, require nock-vcr. Then use insertCassette to
mark the start of where recording - and later playback - should begin
and ejectCassette where it should end. Recorded "cassettes"
\- [nock][nock] code to mock the transactions - will be saved under
test/cassettes!
For example:
```coffeescript
nvcr = require 'nock-vcr'
fs = require 'fs'
http = require 'http'
requestComplete = false
describe 'using nock-vcr', ->
context 'insert a cassette, and eject it when it is done', ->
beforeEach (done)->
nvcr.insertCassette 'Your cassette name here'
options = method: 'GET', host: 'google.com', port: 80, path: '/'
http.request(options, (res)=>
res.on 'end', =>
requestComplete = true
nvcr.ejectCassette()
done()
).end()
it 'creates a cassette', ->
expect(requestComplete).to.be.true
```
You can force nock-vcr to record all the time by passing and setting a
record option of insertCassette to the string
'ALL', or by setting the environment variable
NOCK_VCR_MODE to the same value.
## Notes
Currently this runs on top of [a modified version of nock][my-nock]
that corrects a bug in the code generated during recording as well as a
way to re-activate mocking after a restore.
## Upcoming Features
* More options that can affect the recording behavior.
* Hooks into popular testing frameworks.
[my-nock]: http://github.com/rudyjahchan/nock
[nock]: http://github.com/flatiron/nock
[vcr]: http://github.com/vcr/vcr