nock and cucumber
Hey there, how are you?
The real coder doesn't test. Only the ones who fear are testing. But not him.
(from here)
nock is an HTTP mocking and expectations library for Node.js
Examples
var nock = require('nock');
var couchdb = nock('https://kikoo.js')
.get('/users/1')
.reply(200, {
_id: '123ABC',
_rev: '946B7D1C',
username: 'toto',
email: 'toto2015@kikoo.js'
});
var scope = nock('https://kikoo.js')
.post('/users', {
username: 'toto',
email: 'toto2015@kikoo.js'
})
.reply(201, {
ok: true,
id: '123ABC',
rev: '946B7D1C'
});
Good to know
-
Allow unmocked
var scope = nock('https://kikoojs.com', {allowUnmocked: true});
-
Intercept once by default
nock('https://kikoo.js').get('/').times(4).reply(200, 'Ok');
-
See what happens
DEBUG=nock.*
-
Register what happens
nock.recorder.rec();
cucumber
Behaviour
Driven
Development
How to cucumber?
- Describe behaviour in plain text
- Write a step definition in Ruby
- Run and watch it fail
- Write code to make the step pass
- Run again and see the step pass
- Repeat 2-5 until green like a cuke
(from https://cucumber.io)
1: Feature: Some terse yet descriptive text of what is desired
2: Textual description of the business value of this feature
3: Business rules that govern the scope of the feature
4: Any additional information that will make the feature easier to understand
5:
6: Scenario: Some determinable business situation
7: Given some precondition
8: And some other precondition
9: When some action by the actor
10: And some other action
11: And yet another action
12: Then some testable outcome is achieved
13: And something else we can check happens too
14:
15: Scenario: A different situation
16: ...
Steps: Gherkin => Code
Regexp
String interpolation
this.Then(/^I should see "(.*)" as the page title$/, function (title, callback) { ...
this.Then('I should see "$title" as the page title', function (title, callback) { ...
World
- Testing environment
- "this" is always the same !
- Bullet Three
Hooks
- Before and After
- Access to the scenario
- "this" is always the same !
Links
Questions ?
nock and cucumber
By Siegfried Ehret
nock and cucumber
- 2,550