Comments (3)
Hi
Didn't know VCRURLConnection
but it seems pretty straightforward to me to make it work with OHHTTPStubs
. Not sure an official branch or addition would be useful.
After reading the source, it seems to me that you simply need to create a VCRCassette
object from your JSON file, then for each request to stub, use [cassette recordingForRequest:theRequest]
to get a VCRRecording
object and build an OHHTTPStubsResponse
with its properties:
VCRCassette* cassette = [[VCRCassette alloc] initWithData:[NSData dataWithContentsOfFile:yourJSONFileURL]];
[OHHTTPStubs shouldStubRequestsPassingTest:^BOOL(NSURLRequest *request) {
return ([cassette recordingForRequest:request] != nil);
} withStubResponse:^OHHTTPStubsResponse*(NSURLRequest *request) {
VCRRecording* rec = [cassette recordingForRequest:request];
return [OHHTTPStubsResponse responseWithData:rec.data
statusCode:rec.statusCode
responseTime:whateverYourLike
headers:rec.headerFields];
}];
And that should do the trick!
I haven't tested it but it doesn't seems to be anything more needed.
from ohhttpstubs.
Ah, thanks! I overlooked this -recordingForRequest
part. Seems really simple now. I did switch from acceptance testing stuff for a while, I will look at this closer later.
I am closing this issue for now.
Anyway, let me know, if you will have any insights about using OHHTTPStubs
together with VCR
.
from ohhttpstubs.
Hi
For your information latest versions 1.2.x
and 2.x.y
of OHHTTPStubs
now include the capability of loading files generated by the output of curl -is
, that is files that include the headers (with the response status code) AND body.
Simply put each of your responses (with their headers and body) in a *.response
file (for example using curl -is http://example.iana.org >example1.response
) and then use [OHHTTPStubsResponse responseNamed:@"example1" inBundle:nil responseTime:...]
to replay them.
Not really the same format as the JSON format used by your VCR class, but still quite the same principle as you can replay real requests easily.
from ohhttpstubs.
Related Issues (20)
- Mocktail support HOT 2
- pod 'AFNetworking', '~> 3.0'
- Incorrect example for onStubActivation on Usage Examples page
- [wiki] OHHTTPStubsResponse to HTTPStubsResponse with Swift HOT 4
- Module 'OHHTTPStubs' has no member named 'removeAllStubs' in 9.0.0 HOT 2
- Xcode Analyze: Logic error
- N HOT 1
- Travis CI has seemed to be moved. HOT 3
- How to use in a UITest HOT 9
- OHHTTPStubs with SPM in Xcode 12.5 HOT 1
- Fluent API for stubbing
- how do i use it HOT 1
- Liscense HOT 1
- 4 da world HOT 1
- - [ ] Submitting a maybeaplle @mtodd []()![image](https://user-images.githubusercontent.com/122186144/230750410-f43c3ffb-f6a7-4bd4-9970-8b065670ea28.jpeg)@craystyle1212
- Won't build with Carthage and Xcode 14.3 HOT 7
- App Crashes on Device When OHHTTPStubsSwift Added to iOS Framework via Swift Package Manager HOT 1
- FEATURE REQUEST: Ability to control response stream
- `canInitWithRequest` not called in Xcode 15 preventing stubbing being setup correctly
- Request to provide Privacy Manifest file for OHHTTPStubs SDK HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ohhttpstubs.