Hi!
I started with a rudimentary HTTP mocking lib (adding features as needed) inspired by nock, but using the existing ZnClient / ZnRequest / ZnResponse api for mocking. Atm the feature are very basic (no filtering, matching only by host and scheme), but there it is for the interested. Usage: setUp "other stuff" Znock default intercept tearDown "other stuff" Znock default verify testFooBar 'https://foo.bar' znock url: '/api/v0/info'; get; ok: (ZnEntity json: self sampleInfoResponse). "code that should get https://foo.bar/api/v0/info" The setUp starts and cleans the mocker; the test case sets up the expectation that GET https://foo.bar/api/v0/info will occur and defines the response; tearDown checks that that GET actually appeared and fails if not. DNU w/ whitelisting is used to reply certain ZnClient messages to set up the expectation, ZnResponse class messages to create the response and ZnResponse messages to fill it further. So you can 'foo.bar' znock https; url: '/api/v0/info'; get; notModified. if you like it this way or 'foo.bar' znock url: '/api/v0/info'; get; notModified. to allow both http and https; eventually 'foo.bar/api/v0/info' znock get; notModified. if you want it shorter; mocking multiple req/res pair should work (not tested), as in 'foo.bar' znock url: '/api/v0/info'; get; notModified; url: '/api/v0/last'; get; ok: (ZnEntity textCRLF: 'herby'). Both must appear (in any order) for verify to be happy. Herby |
Herbert Vojčík wrote: > Hi! > > I started with a rudimentary HTTP mocking lib (adding features as > needed) inspired by nock, but using the existing ZnClient / ZnRequest / > ZnResponse api for mocking. Credits: Uses Mocketry's `ZnClient new stub will: ...` to set up mocked client; thanks Denis Kudriashov. Herby > Atm the feature are very basic (no filtering, matching only by host and > scheme), but there it is for the interested. > > Usage: > > setUp > "other stuff" > Znock default intercept > > tearDown > "other stuff" > Znock default verify > > testFooBar > 'https://foo.bar' znock > url: '/api/v0/info'; > get; > ok: (ZnEntity json: self sampleInfoResponse). > "code that should get https://foo.bar/api/v0/info" > > The setUp starts and cleans the mocker; the test case sets up the > expectation that GET https://foo.bar/api/v0/info will occur and defines > the response; tearDown checks that that GET actually appeared and fails > if not. > > DNU w/ whitelisting is used to reply certain ZnClient messages to set up > the expectation, ZnResponse class messages to create the response and > ZnResponse messages to fill it further. > > So you can > > 'foo.bar' znock > https; > url: '/api/v0/info'; > get; > notModified. > > if you like it this way or > > 'foo.bar' znock > url: '/api/v0/info'; > get; > notModified. > > to allow both http and https; eventually > > 'foo.bar/api/v0/info' znock > get; > notModified. > > if you want it shorter; mocking multiple req/res pair should work (not > tested), as in > > 'foo.bar' znock > url: '/api/v0/info'; > get; > notModified; > url: '/api/v0/last'; > get; > ok: (ZnEntity textCRLF: 'herby'). > > Both must appear (in any order) for verify to be happy. > > Herby > |
In reply to this post by Herby Vojčík
Herbert Vojčík wrote: > Hi! > > I started with a rudimentary HTTP mocking lib (adding features as > needed) inspired by nock, but using the existing ZnClient / ZnRequest / > ZnResponse api for mocking. > > Atm the feature are very basic (no filtering, matching only by host and > scheme), but there it is for the interested. > > Usage: > > setUp > "other stuff" > Znock default intercept > > tearDown > "other stuff" > Znock default verify > > testFooBar > 'https://foo.bar' znock > url: '/api/v0/info'; > get; > ok: (ZnEntity json: self sampleInfoResponse). > "code that should get https://foo.bar/api/v0/info" > > The setUp starts and cleans the mocker; the test case sets up the > expectation that GET https://foo.bar/api/v0/info will occur and defines > the response; tearDown checks that that GET actually appeared and fails > if not. > > DNU w/ whitelisting is used to reply certain ZnClient messages to set up s/reply/replay/ > the expectation, ZnResponse class messages to create the response and > ZnResponse messages to fill it further. > > So you can > > 'foo.bar' znock > https; > url: '/api/v0/info'; > get; > notModified. > > if you like it this way or > > 'foo.bar' znock > url: '/api/v0/info'; > get; > notModified. > > to allow both http and https; eventually > > 'foo.bar/api/v0/info' znock > get; > notModified. > > if you want it shorter; mocking multiple req/res pair should work (not > tested), as in > > 'foo.bar' znock > url: '/api/v0/info'; > get; > notModified; > url: '/api/v0/last'; > get; > ok: (ZnEntity textCRLF: 'herby'). > > Both must appear (in any order) for verify to be happy. > > Herby > |
In reply to this post by Herby Vojčík
This cool. Because I wanted to use that in one test with a project with my son.
What is the license? Where is the code? On Tue, Jan 30, 2018 at 11:31 PM, Herbert Vojčík <[hidden email]> wrote: > Hi! > > I started with a rudimentary HTTP mocking lib (adding features as needed) > inspired by nock, but using the existing ZnClient / ZnRequest / ZnResponse > api for mocking. > > Atm the feature are very basic (no filtering, matching only by host and > scheme), but there it is for the interested. > > Usage: > > setUp > "other stuff" > Znock default intercept > > tearDown > "other stuff" > Znock default verify > > testFooBar > 'https://foo.bar' znock > url: '/api/v0/info'; > get; > ok: (ZnEntity json: self sampleInfoResponse). > "code that should get https://foo.bar/api/v0/info" > > The setUp starts and cleans the mocker; the test case sets up the > expectation that GET https://foo.bar/api/v0/info will occur and defines the > response; tearDown checks that that GET actually appeared and fails if not. > > DNU w/ whitelisting is used to reply certain ZnClient messages to set up the > expectation, ZnResponse class messages to create the response and ZnResponse > messages to fill it further. > > So you can > > 'foo.bar' znock > https; > url: '/api/v0/info'; > get; > notModified. > > if you like it this way or > > 'foo.bar' znock > url: '/api/v0/info'; > get; > notModified. > > to allow both http and https; eventually > > 'foo.bar/api/v0/info' znock > get; > notModified. > > if you want it shorter; mocking multiple req/res pair should work (not > tested), as in > > 'foo.bar' znock > url: '/api/v0/info'; > get; > notModified; > url: '/api/v0/last'; > get; > ok: (ZnEntity textCRLF: 'herby'). > > Both must appear (in any order) for verify to be happy. > > Herby > |
License... ah I forgot to put it there... it'll be MIT.
Code is, as pointed out in subject, is at https://lolg.it/herby/znock. As I said, beware, wip (but working for simple positive scenarios). Herby Stephane Ducasse wrote: > This cool. Because I wanted to use that in one test with a project with my son. > What is the license? Where is the code? > > On Tue, Jan 30, 2018 at 11:31 PM, Herbert Vojčík<[hidden email]> wrote: >> Hi! >> >> I started with a rudimentary HTTP mocking lib (adding features as needed) >> inspired by nock, but using the existing ZnClient / ZnRequest / ZnResponse >> api for mocking. >> >> Atm the feature are very basic (no filtering, matching only by host and >> scheme), but there it is for the interested. >> >> Usage: >> >> setUp >> "other stuff" >> Znock default intercept >> >> tearDown >> "other stuff" >> Znock default verify >> >> testFooBar >> 'https://foo.bar' znock >> url: '/api/ >> get; >> ok: (ZnEntity json: self sampleInfoResponse). >> "code that should get https://foo.bar/api/v0/info" >> >> The setUp starts and cleans the mocker; the test case sets up the >> expectation that GET https://foo.bar/api/v0/info will occur and defines the >> response; tearDown checks that that GET actually appeared and fails if not. >> >> DNU w/ whitelisting is used to reply certain ZnClient messages to set up the >> expectation, ZnResponse class messages to create the response and ZnResponse >> messages to fill it further. >> >> So you can >> >> 'foo.bar' znock >> https; >> url: '/api/v0/info'; >> get; >> notModified. >> >> if you like it this way or >> >> 'foo.bar' znock >> url: '/api/v0/info'; >> get; >> notModified. >> >> to allow both http and https; eventually >> >> 'f >> get; >> notModified. >> >> if you want it shorter; mocking multiple req/res pair should work (not >> tested), as in >> >> 'foo.bar' znock >> url: '/api/v0/info'; >> get; >> notModified; >> url: '/api/v0/last'; >> get; >> ok: (ZnEntity textCRLF: 'herby'). >> >> Both must appear (in any order) for verify to be happy. >> >> Herby >> > |
Herbert Vojčík wrote: > License... ah I forgot to put it there... it'll be MIT. Just added. :-) |
Free forum by Nabble | Edit this page |