Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
  • 13 commits
  • 11 files changed
  • 1 commit comment
  • 3 contributors
View
27 Gemfile.lock
@@ -3,9 +3,10 @@ PATH
specs:
mimic (0.4.3)
json
- plist
+ plist (~> 3.1.0)
rack
sinatra
+ thin
GEM
remote: http://rubygems.org/
@@ -17,14 +18,21 @@ GEM
gherkin (~> 2.4.1)
json (>= 1.4.6)
term-ansicolor (>= 1.0.5)
+ daemons (1.1.8)
diff-lcs (1.1.2)
+ eventmachine (0.12.10)
gherkin (2.4.1)
json (>= 1.4.6)
json (1.5.3)
mime-types (1.16)
mocha (0.9.12)
plist (3.1.0)
- rack (1.3.0)
+ rack (1.4.1)
+ rack-protection (1.2.0)
+ rack
+ rake (0.9.2.2)
+ rdoc (3.12)
+ json (~> 1.4)
rest-client (1.6.3)
mime-types (>= 1.16)
rspec (2.4.0)
@@ -35,11 +43,16 @@ GEM
rspec-expectations (2.4.0)
diff-lcs (~> 1.1.2)
rspec-mocks (2.4.0)
- sinatra (1.2.6)
- rack (~> 1.1)
- tilt (< 2.0, >= 1.2.2)
+ sinatra (1.3.2)
+ rack (~> 1.3, >= 1.3.6)
+ rack-protection (~> 1.2)
+ tilt (~> 1.3, >= 1.3.3)
term-ansicolor (1.0.5)
- tilt (1.3.2)
+ thin (1.3.1)
+ daemons (>= 1.0.9)
+ eventmachine (>= 0.12.6)
+ rack (>= 1.0.0)
+ tilt (1.3.3)
PLATFORMS
ruby
@@ -48,5 +61,7 @@ DEPENDENCIES
cucumber
mimic!
mocha
+ rake
+ rdoc
rest-client
rspec (~> 2.4.0)
View
13 README.md
@@ -51,10 +51,17 @@ Finally, because Mimic is built on top of Sinatra for the core request handling,
Mimic has a built-in REST API that lets you configure your request stubs over HTTP. This makes it possible to use Mimic from other processes that can perform HTTP requests.
-First of all, you'll need to run Mimic as a daemon. You can do this with a simple Ruby script:
+First of all, you'll need to run Mimic as a daemon. You can do this with a simple Ruby script and the [daemons](http://daemons.rubyforge.org/) gem:
#!/usr/bin/env ruby
- Mimic.daemonize({:port => 11988, :remote_configuration_path => '/api'})
+ require 'mimic'
+ require 'daemons'
+
+ Daemons.run_proc("mimic") do
+ Mimic.mimic(:port => 11988, :fork => false, :remote_configuration_path => '/api') do
+ # configure your stubs here
+ end
+ end
Give the script executable permissions and then start it:
@@ -78,6 +85,8 @@ Likewise, a POST request to the same path could be stubbed like so:
The end-point of the API is the HTTP verb you are stubbing, the path, response body, code and headers are specified in the POST data (a hash in JSON or Plist format). See the HTTP API Cucumber features for more examples.
+An [Objective-C wrapper](http://github.com/lukeredpath/LRMimic) for the REST API is available, allowing you to use mimic for your OSX and iOS apps.
+
## Contributors
* [James Fairbairn](http://github.com/jfairbairn)
View
3  Rakefile
@@ -47,8 +47,9 @@ spec = Gem::Specification.new do |s|
# relevant versions
s.add_dependency("rack")
s.add_dependency("sinatra")
+ s.add_dependency("thin")
s.add_dependency("json")
- s.add_dependency("plist")
+ s.add_dependency("plist", "~> 3.1.0")
# If your tests use any gems, include them here
s.add_development_dependency("rspec", "~> 2.4.0")
View
39 features/checking_requests_were_made.feature
@@ -0,0 +1,39 @@
+Feature: Checking requests were made
+ In order to verify requests were made to mimic (like mock expectations)
+ As a developer
+ I want to be able to ask the Mimic API what requests were made
+
+ Scenario: Configuring a request and verifying it was called
+ Given that Mimic is running and accepting remote configuration on "/api"
+ When I make an HTTP POST request to "http://localhost:11988/api/get" with the payload:
+ """
+ {"path": "/anything"}
+ """
+ Then I should receive an HTTP 201 response with a body containing:
+ """
+ {"stubs":["41f660b868e1308e8d87afbb84532b71"]}
+ """
+ And I make an HTTP GET request to "http://localhost:11988/anything"
+ And I make an HTTP GET request to "http://localhost:11988/api/requests"
+ Then I should receive an HTTP 200 response with a body containing:
+ """
+ {"requests":["41f660b868e1308e8d87afbb84532b71"]}
+ """
+
+ Scenario: Configuring a request and verifying it was not called
+ Given that Mimic is running and accepting remote configuration on "/api"
+ When I make an HTTP POST request to "http://localhost:11988/api/get" with the payload:
+ """
+ {"path": "/anything"}
+ """
+ Then I should receive an HTTP 201 response with a body containing:
+ """
+ {"stubs":["41f660b868e1308e8d87afbb84532b71"]}
+ """
+ And I make an HTTP GET request to "http://localhost:11988/api/requests"
+ Then I should receive an HTTP 200 response with a body containing:
+ """
+ {"requests":[]}
+ """
+
+
View
13 lib/mimic.rb
@@ -59,24 +59,15 @@ def serve(app, options)
end
def start_service(app, options)
- Rack::Handler::WEBrick.run(app.url_map, {
+ Rack::Handler::Thin.run(app.url_map, {
:Port => options[:port],
:Logger => logger,
:AccessLog => logger,
-
- }) do |server|
- @server = server
-
- old = trap('EXIT') do
- old.call if old
- @server.shutdown
- end
- end
+ })
end
def shutdown
Thread.kill(@thread) if @thread
- @server.shutdown if @server
end
# courtesy of http://is.gd/eoYho
View
38 lib/mimic/api.rb
@@ -15,14 +15,14 @@ def host
post "/#{verb}" do
api_request = APIRequest.from_request(request, verb)
api_request.setup_stubs_on(host)
- [201, {}, api_request.to_s]
+ [201, {"Content-Type" => api_request.request_content_type}, api_request.response]
end
end
post "/multi" do
api_request = APIRequest.from_request(request)
api_request.setup_stubs_on(host)
- [201, {}, api_request.to_s]
+ [201, {"Content-Type" => api_request.request_content_type}, api_request.response]
end
post "/clear" do
@@ -39,18 +39,39 @@ def host
[200, {}, self.host.inspect]
end
+ get "/requests" do
+ [200, {"Content-Type" => "application/json"}, {"requests" => host.received_requests.map(&:to_hash)}.to_json]
+ end
+
private
class APIRequest
- def initialize(data, method = nil)
+ attr_reader :request_content_type
+
+ def initialize(data, method = nil, request_content_type = '')
@data = data
@method = (method || "GET")
+ @stubs = []
+ @request_content_type = request_content_type
end
def to_s
@data.inspect
end
+ def response
+ response = {"stubs" => @stubs.map(&:to_hash)}
+
+ case request_content_type
+ when /json/
+ response.to_json
+ when /plist/
+ response.to_plist
+ else
+ response.to_json
+ end
+ end
+
def self.from_request(request, method = nil)
case request.content_type
when /json/
@@ -60,12 +81,12 @@ def self.from_request(request, method = nil)
else
data = JSON.parse(request.body.string)
end
- new(data, method)
+ new(data, method, request.content_type)
end
def setup_stubs_on(host)
(@data["stubs"] || [@data]).each do |stub_data|
- Stub.new(stub_data, stub_data['method'] || @method).on(host)
+ @stubs << Stub.new(stub_data, stub_data['method'] || @method).on(host)
end
end
@@ -76,9 +97,10 @@ def initialize(data, method = nil)
end
def on(host)
- stub = host.send(@method.downcase.to_sym, path).returning(body, code, headers)
- stub.with_query_parameters(params)
- stub.echo_request!(echo_format)
+ host.send(@method.downcase.to_sym, path).returning(body, code, headers).tap do |stub|
+ stub.with_query_parameters(params)
+ stub.echo_request!(echo_format)
+ end
end
def echo_format
View
24 lib/mimic/fake_host.rb
@@ -15,6 +15,10 @@ def initialize(options = {})
build_url_map!
end
+ def received_requests
+ @stubs.select { |s| s.received }
+ end
+
def get(path, &block)
request("GET", path, &block)
end
@@ -127,19 +131,21 @@ def to_s(format)
def to_hash
{"echo" => {
"params" => @request.params,
- "env" => env_without_rack_env,
+ "env" => env_without_rack_and_async_env,
"body" => @request.body.read
}}
end
private
- def env_without_rack_env
- Hash[*@request.env.select { |key, value| key !~ /^rack/i }.flatten]
+ def env_without_rack_and_async_env
+ Hash[*@request.env.select { |key, value| key !~ /^(rack|async)/i }.flatten]
end
end
class StubbedRequest
+ attr_accessor :received
+
def initialize(app, method, path)
@method, @path = method, path
@code = 200
@@ -147,6 +153,12 @@ def initialize(app, method, path)
@params = {}
@body = ""
@app = app
+ @received = false
+ end
+
+ def to_hash
+ token = "#{@method} #{@path}"
+ Digest::MD5.hexdigest(token)
end
def returning(body, code = 200, headers = {})
@@ -193,7 +205,11 @@ def response_for_request(request)
def build
stub = self
- @app.send(@method.downcase, @path) { stub.response_for_request(request) }
+
+ @app.send(@method.downcase, @path) do
+ stub.received = true
+ stub.response_for_request(request)
+ end
end
end
end
View
31 mimic.gemspec
@@ -1,20 +1,20 @@
# -*- encoding: utf-8 -*-
Gem::Specification.new do |s|
- s.name = %q{mimic}
+ s.name = "mimic"
s.version = "0.4.3"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
- s.authors = [%q{Luke Redpath}]
- s.date = %q{2011-06-25}
- s.email = %q{luke@lukeredpath.co.uk}
- s.extra_rdoc_files = [%q{README.md}]
- s.files = [%q{LICENSE}, %q{CHANGES}, %q{Rakefile}, %q{README.md}, %q{spec}, %q{lib/mimic}, %q{lib/mimic/api.rb}, %q{lib/mimic/fake_host.rb}, %q{lib/mimic.rb}]
- s.homepage = %q{http://lukeredpath.co.uk}
- s.rdoc_options = [%q{--main}, %q{README.md}]
- s.require_paths = [%q{lib}]
- s.rubygems_version = %q{1.8.5}
- s.summary = %q{A Ruby gem for faking external web services for testing}
+ s.authors = ["Luke Redpath"]
+ s.date = "2012-03-17"
+ s.email = "luke@lukeredpath.co.uk"
+ s.extra_rdoc_files = ["README.md"]
+ s.files = ["LICENSE", "CHANGES", "Rakefile", "README.md", "spec", "lib/mimic", "lib/mimic/api.rb", "lib/mimic/fake_host.rb", "lib/mimic.rb"]
+ s.homepage = "http://lukeredpath.co.uk"
+ s.rdoc_options = ["--main", "README.md"]
+ s.require_paths = ["lib"]
+ s.rubygems_version = "1.8.11"
+ s.summary = "A Ruby gem for faking external web services for testing"
if s.respond_to? :specification_version then
s.specification_version = 3
@@ -22,8 +22,9 @@ Gem::Specification.new do |s|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
s.add_runtime_dependency(%q<rack>, [">= 0"])
s.add_runtime_dependency(%q<sinatra>, [">= 0"])
+ s.add_runtime_dependency(%q<thin>, [">= 0"])
s.add_runtime_dependency(%q<json>, [">= 0"])
- s.add_runtime_dependency(%q<plist>, [">= 0"])
+ s.add_runtime_dependency(%q<plist>, ["~> 3.1.0"])
s.add_development_dependency(%q<rspec>, ["~> 2.4.0"])
s.add_development_dependency(%q<cucumber>, [">= 0"])
s.add_development_dependency(%q<mocha>, [">= 0"])
@@ -31,8 +32,9 @@ Gem::Specification.new do |s|
else
s.add_dependency(%q<rack>, [">= 0"])
s.add_dependency(%q<sinatra>, [">= 0"])
+ s.add_dependency(%q<thin>, [">= 0"])
s.add_dependency(%q<json>, [">= 0"])
- s.add_dependency(%q<plist>, [">= 0"])
+ s.add_dependency(%q<plist>, ["~> 3.1.0"])
s.add_dependency(%q<rspec>, ["~> 2.4.0"])
s.add_dependency(%q<cucumber>, [">= 0"])
s.add_dependency(%q<mocha>, [">= 0"])
@@ -41,8 +43,9 @@ Gem::Specification.new do |s|
else
s.add_dependency(%q<rack>, [">= 0"])
s.add_dependency(%q<sinatra>, [">= 0"])
+ s.add_dependency(%q<thin>, [">= 0"])
s.add_dependency(%q<json>, [">= 0"])
- s.add_dependency(%q<plist>, [">= 0"])
+ s.add_dependency(%q<plist>, ["~> 3.1.0"])
s.add_dependency(%q<rspec>, ["~> 2.4.0"])
s.add_dependency(%q<cucumber>, [">= 0"])
s.add_dependency(%q<mocha>, [">= 0"])
View
17 spec/fake_host_spec.rb
@@ -69,6 +69,23 @@
}.should raise_error
end
+ it "returns a StubbedRequest" do
+ @host.get("/some/path").should be_kind_of(Mimic::FakeHost::StubbedRequest)
+ end
+
+ describe "StubbedRequest" do
+ it "has a unique hash based on it's parameters" do
+ host = Mimic::FakeHost::StubbedRequest.new(stub, "GET", "/path")
+ host.to_hash.should == Digest::MD5.hexdigest("GET /path")
+ end
+
+ it "has the same hash as an equivalent request" do
+ host_one = Mimic::FakeHost::StubbedRequest.new(stub, "GET", "/path")
+ host_two = Mimic::FakeHost::StubbedRequest.new(stub, "GET", "/path")
+ host_one.to_hash.should == host_two.to_hash
+ end
+ end
+
private
def request_for(path, options={})
View
81 wrappers/Objective-C/LRMimic.h
@@ -1,81 +0,0 @@
-//
-// LRMimic.h
-// MimicSpecDemo
-//
-// Created by Luke Redpath on 13/01/2011.
-// Copyright 2011 LJR Software Limited. All rights reserved.
-//
-
-#import <Foundation/Foundation.h>
-
-@class LRMimic;
-@class LRRestyClient;
-@class LRMimicRequestStub;
-
-typedef void (^LRMimicConfigurationBlock)(LRMimic *);
-typedef void (^LRMimicCallback)(BOOL);
-
-@interface LRMimic : NSObject {
- NSString *URL;
- NSMutableArray *stubs;
- LRRestyClient *client;
-}
-+ (void)setURL:(NSString *)url;
-+ (void)setAutomaticallyClearsStubs:(BOOL)shouldClear;
-+ (void)reset;
-+ (void)configure:(LRMimicConfigurationBlock)configurationBlock;
-+ (void)stubAndCall:(LRMimicCallback)callback;
-- (void)ping;
-- (void)prepareStubs:(LRMimicCallback)callback;
-- (void)prepareStubs:(LRMimicCallback)callback clearRemote:(BOOL)clearRemote;
-- (void)clearRemoteStubs:(LRMimicCallback)callback;
-- (id)initWithMimicURL:(NSString *)mimicURL;
-- (void)prepareStubs:(LRMimicCallback)callback;
-- (void)reset;
-@end
-
-@interface LRMimic (StubMethods)
-- (LRMimicRequestStub *)get:(NSString *)path;
-- (LRMimicRequestStub *)post:(NSString *)path;
-- (LRMimicRequestStub *)put:(NSString *)path;
-- (LRMimicRequestStub *)delete:(NSString *)path;
-- (LRMimicRequestStub *)head:(NSString *)path;
-- (LRMimicRequestStub *)stub:(NSString *)path method:(NSString *)httpMethod;
-- (void)addRequestStub:(LRMimicRequestStub *)stub;
-@end
-
-@interface LRMimicRequestStub : NSObject
-{
- NSString *method;
- NSString *path;
- NSString *body;
- NSInteger code;
- NSDictionary *headers;
- NSDictionary *queryParameters;
- BOOL shouldEchoRequest;
-}
-+ (id)stub:(NSString *)path;
-+ (id)stub:(NSString *)path method:(NSString *)method;
-- (id)initWithPath:(NSString *)aPath method:(NSString *)HTTPMethod;
-- (void)andEchoRequest;
-- (void)willReturnResponse:(NSString *)responseBody withStatus:(NSInteger)statusCode;
-- (void)willReturnResponse:(NSString *)responseBody withStatus:(NSInteger)statusCode headers:(NSDictionary *)theHeaders;
-- (void)willReturnResponse:(NSString *)responseBody withStatus:(NSInteger)statusCode
- headers:(NSDictionary *)theHeaders queryParameters:(NSDictionary *)params;
-- (NSDictionary *)toDictionary;
-@end
-
-@interface LRMimicRequestStubBuilder : NSObject
-{}
-@property (nonatomic, copy) NSString *path;
-@property (nonatomic, copy) NSString *method;
-@property (nonatomic, assign) NSInteger code;
-@property (nonatomic, copy) NSString *body;
-@property (nonatomic, copy) NSDictionary *headers;
-@property (nonatomic, copy) NSDictionary *queryParameters;
-@property (nonatomic, assign) BOOL echoRequest;
-
-+ (id)builder;
-- (LRMimicRequestStub *)buildStub;
-@end
-
View
351 wrappers/Objective-C/LRMimic.m
@@ -1,351 +0,0 @@
-//
-// LRMimic.m
-// MimicSpecDemo
-//
-// Created by Luke Redpath on 13/01/2011.
-// Copyright 2011 LJR Software Limited. All rights reserved.
-//
-
-#import "LRMimic.h"
-#import "LRResty.h"
-
-@interface LRMimic ()
-+ (id)sharedInstance;
-- (NSData *)payload;
-@end
-
-#define kMimicDefaultURL @"http://localhost:11988/api"
-
-@implementation LRMimic
-
-static NSString *mimicURL = nil;
-static BOOL automaticallyClearStubs = NO;
-static BOOL pingsWhenInitialized = YES;
-
-+ (void)setURL:(NSString *)url;
-{
- [mimicURL autorelease];
- mimicURL = [url copy];
-}
-
-+ (void)setAutomaticallyClearsStubs:(BOOL)shouldClear
-{
- automaticallyClearStubs = shouldClear;
-}
-
-+ (void)setPingsWhenInitialized:(BOOL)shouldPing
-{
- pingsWhenInitialized = shouldPing;
-}
-
-+ (void)reset;
-{
- [[self sharedInstance] reset];
-}
-
-#pragma mark -
-#pragma mark Static API
-
-+ (void)configure:(LRMimicConfigurationBlock)configurationBlock
-{
- configurationBlock([self sharedInstance]);
-}
-
-+ (void)stubAndCall:(LRMimicCallback)callback;
-{
- [[self sharedInstance] prepareStubs:callback clearRemote:automaticallyClearStubs];
-}
-
-#pragma mark -
-
-- (id)initWithMimicURL:(NSString *)mimicURL;
-{
- if (self = [super init]) {
- URL = [mimicURL copy];
- stubs = [[NSMutableArray alloc] init];
- client = [LRResty newClient];
-
- [client attachRequestModifier:^(LRRestyRequest *req) {
- [req addHeader:@"Content-Type" value:@"application/plist"];
- }];
-
- if (pingsWhenInitialized) {
- [self ping];
- }
- }
- return self;
-}
-
-- (void)ping;
-{
- LRRestyResponse *response = [client get:[URL stringByAppendingPathComponent:@"/ping"]];
-
- if (response.status != 200) {
- [[NSException exceptionWithName:@"MimicError"
- reason:[NSString stringWithFormat:@"Couldn't ping Mimic (response: %@)", response]
- userInfo:nil] raise];
- }
-
-}
-
-- (void)dealloc
-{
- [client release];
- [mimicURL release];
- [stubs release];
- [super dealloc];
-}
-
-- (void)prepareStubs:(LRMimicCallback)callback;
-{
- [client post:[URL stringByAppendingPathComponent:@"multi"]
- payload:[self payload]
- withBlock:^(LRRestyResponse *response) {
-
- if (response.status == 201) {
- callback(YES);
- } else {
- callback(NO);
- }
- }];
-}
-
-- (void)prepareStubs:(LRMimicCallback)callback clearRemote:(BOOL)clearRemote;
-{
- if (clearRemote) {
- [self clearRemoteStubs:^(BOOL success) {
- if (success) {
- [self prepareStubs:callback];
- } else {
- callback(NO);
- }
- }];
- } else {
- [self prepareStubs:callback];
- }
-}
-
-- (void)clearRemoteStubs:(LRMimicCallback)callback;
-{
- [client post:[URL stringByAppendingPathComponent:@"clear"]
- payload:nil
- withBlock:^(LRRestyResponse *response) {
-
- if (response.status == 200) {
- callback(YES);
- } else {
- callback(NO);
- }
- }];
-}
-
-- (void)reset;
-{
- [stubs removeAllObjects];
-}
-
-#pragma mark -
-#pragma mark Private methods
-
-- (NSData *)payload;
-{
- NSMutableArray *stubPayloads = [NSMutableArray arrayWithCapacity:stubs.count];
- for (LRMimicRequestStub *stub in stubs) {
- [stubPayloads addObject:[stub toDictionary]];
- }
- NSLog(@"STUBBING %@", stubPayloads);
- NSDictionary *payload = [NSDictionary dictionaryWithObject:stubPayloads forKey:@"stubs"];
- return [NSPropertyListSerialization dataFromPropertyList:(id)payload
- format:NSPropertyListXMLFormat_v1_0
- errorDescription:nil];
-}
-
-+ (id)sharedInstance;
-{
- static id sharedInstance = nil;
-
- if (sharedInstance == nil) {
- if (mimicURL == nil) {
- mimicURL = kMimicDefaultURL;
- }
- sharedInstance = [[self alloc] initWithMimicURL:mimicURL];
- }
-
- return sharedInstance;
-}
-
-@end
-
-#pragma mark -
-
-@implementation LRMimic (StubMethods)
-
-- (LRMimicRequestStub *)get:(NSString *)path;
-{
- return [self stub:path method:@"GET"];
-}
-
-- (LRMimicRequestStub *)post:(NSString *)path;
-{
- return [self stub:path method:@"POST"];
-}
-
-- (LRMimicRequestStub *)put:(NSString *)path;
-{
- return [self stub:path method:@"PUT"];
-}
-
-- (LRMimicRequestStub *)delete:(NSString *)path;
-{
- return [self stub:path method:@"DELETE"];
-}
-
-- (LRMimicRequestStub *)head:(NSString *)path;
-{
- return [self stub:path method:@"HEAD"];
-}
-
-- (LRMimicRequestStub *)stub:(NSString *)path method:(NSString *)httpMethod;
-{
- LRMimicRequestStub *stub = [LRMimicRequestStub stub:path method:httpMethod];
- [self addRequestStub:stub];
- return stub;
-}
-
-- (void)addRequestStub:(LRMimicRequestStub *)stub;
-{
- [stubs addObject:stub];
-}
-
-@end
-
-
-#pragma mark -
-
-@implementation LRMimicRequestStub
-
-+ (id)stub:(NSString *)path;
-{
- return [self stub:path method:@"GET"];
-}
-
-+ (id)stub:(NSString *)path method:(NSString *)method
-{
- return [[[self alloc] initWithPath:path method:method] autorelease];
-}
-
-- (id)initWithPath:(NSString *)aPath method:(NSString *)HTTPMethod;
-{
- if (self = [super init]) {
- method = [HTTPMethod copy];
- path = [aPath copy];
- body = [[NSString alloc] initWithString:@""];
- code = 200;
- shouldEchoRequest = NO;
- }
- return self;
-}
-
-- (void)dealloc
-{
- [queryParameters release];
- [headers release];
- [method release];
- [path release];
- [body release];
- [super dealloc];
-}
-
-- (void)willReturnResponse:(NSString *)responseBody withStatus:(NSInteger)statusCode
- headers:(NSDictionary *)theHeaders queryParameters:(NSDictionary *)params;
-{
- body = [responseBody copy];
- code = statusCode;
- headers = [theHeaders copy];
- queryParameters = [params copy];
-}
-
-- (void)willReturnResponse:(NSString *)responseBody withStatus:(NSInteger)statusCode headers:(NSDictionary *)theHeaders;
-{
- [self willReturnResponse:responseBody withStatus:statusCode headers:theHeaders queryParameters:nil];
-}
-
-- (void)willReturnResponse:(NSString *)responseBody withStatus:(NSInteger)statusCode;
-{
- [self willReturnResponse:responseBody withStatus:statusCode headers:nil];
-}
-
-- (void)andEchoRequest;
-{
- shouldEchoRequest = YES;
-}
-
-- (NSDictionary *)toDictionary;
-{
- NSMutableDictionary *dictionary = [NSMutableDictionary dictionary];
- [dictionary setObject:method forKey:@"method"];
- [dictionary setObject:path forKey:@"path"];
- [dictionary setObject:body forKey:@"body"];
- [dictionary setObject:[NSNumber numberWithInteger:code] forKey:@"code"];
- if (shouldEchoRequest) {
- [dictionary setObject:@"plist" forKey:@"echo"];
- }
- if (headers) {
- [dictionary setObject:headers forKey:@"headers"];
- }
- if (queryParameters) {
- [dictionary setObject:queryParameters forKey:@"params"];
- }
- return dictionary;
-}
-
-@end
-
-#pragma mark -
-#pragma mark Stub builder
-
-@implementation LRMimicRequestStubBuilder
-
-@synthesize path, method, code, body, headers, queryParameters, echoRequest;
-
-+ (id)builder;
-{
- return [[[self alloc] init] autorelease];
-}
-
-- (id)init
-{
- if (self = [super init]) {
- self.path = @"/";
- self.method = @"GET";
- self.code = 200;
- self.body = @"";
- self.headers = [NSDictionary dictionary];
- self.queryParameters = [NSDictionary dictionary];
- self.echoRequest = NO;
- }
- return self;
-}
-
-- (void)dealloc
-{
- [queryParameters release];
- [path release];
- [method release];
- [body release];
- [headers release];
- [super dealloc];
-}
-
-- (LRMimicRequestStub *)buildStub;
-{
- LRMimicRequestStub *stub = [LRMimicRequestStub stub:self.path method:self.method];
- [stub willReturnResponse:self.body withStatus:self.code headers:self.headers queryParameters:self.queryParameters];
- if (self.echoRequest) {
- [stub andEchoRequest];
- }
- return stub;
-}
-
-@end
-

Showing you all comments on commits in this comparison.

@lukeredpath

Should rename this to something like #token as it's confusing (its not returning a Hash).

Something went wrong with that request. Please try again.