Class { #name : #ZnockClient, #superclass : #ZnClient, #instVars : [ 'interceptor' ], #category : #Znock } { #category : #'instance creation' } ZnockClient class >> newWithInterceptor: aZnock [ ^ self new interceptor: aZnock; yourself ] { #category : #'private protocol' } ZnockClient >> fakeDelay: aDuration [ | localTimeout | localTimeout := self timeout seconds. localTimeout <= aDuration ifTrue: [ localTimeout asDelay wait. ConnectionTimedOut signal: 'Znock timeout' ] ifFalse: [ aDuration asDelay wait ] ] { #category : #'private protocol' } ZnockClient >> fakeResponse: aZnResponse [ response := aZnResponse. (response respondsTo: #signal) ifTrue: [ response signal ] ] { #category : #'private protocol' } ZnockClient >> getConnectionAndExecute [ | expectation | expectation := interceptor consumeExpectationFor: self. expectation ifNil: [ ^ super executeRequestResponse ]. expectation customizeResponseFromRequest: request. expectation delay ifNotNil: [ :delay | self fakeDelay: delay ]. self fakeResponse: expectation response. ^ response contents ] { #category : #accessing } ZnockClient >> interceptor: anObject [ interceptor := anObject ] { #category : #comparing } ZnockClient >> matches: aZnockExpectation [ | req exp | req := self request. exp := aZnockExpectation request. exp url scheme ifNotNil: [ :scheme | scheme = req url scheme ifFalse: [ ^ false ] ]. exp url authority ifNotNil: [ :authority | authority = req url authority ifFalse: [ ^ false ] ]. exp method ifNotNil: [ :method | method = req method ifFalse: [ ^ false ] ]. (req url path beginsWith: exp url path) ifFalse: [ ^ false ]. ^ true ]