lib/mirage/client/client.rb in mirage-2.3.0 vs lib/mirage/client/client.rb in mirage-2.4.0
- old
+ new
@@ -1,19 +1,31 @@
require 'uri'
module Mirage
class Client
+ Defaults = Struct.new(:method, :status, :delay, :content_type, :default)
include Mirage::Web
attr_reader :url
+
# Creates an instance of the Mirage client that can be used to interact with the Mirage Server
#
# Client.new => a client that is configured to connect to Mirage on http://localhost:7001/mirage (the default settings for Mirage)
# Client.new(URL) => a client that is configured to connect to an instance of Mirage running on the specified url.
- def initialize url="http://localhost:7001/mirage"
+ def initialize url="http://localhost:7001/mirage", &block
@url = url
+ @defaults = Defaults.new
+ configure &block if block_given?
end
+ def configure &block
+ yield @defaults
+ end
+
+ def reset
+ @defaults = Defaults.new
+ end
+
def stop
Mirage.stop :port => URI.parse(@url).port
end
@@ -29,10 +41,10 @@
# response.content_type = 'text/html' #defaults text/plain
# response.default = true # defaults to false. setting to true will allow this template to respond to request made to sub resources should it match.
# end
def put endpoint, response_value, &block
response = Mirage::Response.new response_value
-
+ @defaults.each_pair{|key, value|response.send("#{key}=", value) if value}
yield response if block_given?
build_response(http_put("#{@url}/templates/#{endpoint}", response.value, response.headers))
end
\ No newline at end of file