lib/acfs/stub.rb in acfs-1.5.1 vs lib/acfs/stub.rb in acfs-1.6.0

- old
+ new

@@ -20,11 +20,11 @@ @opts[:return].map! {|h| h.stringify_keys! if h.is_a? Hash } end end def accept?(op) - return opts[:with].call op if opts[:with].respond_to? :call + return opts[:with].call(op) if opts[:with].respond_to?(:call) params = op.full_params.stringify_keys data = op.data.stringify_keys with = opts[:with] @@ -82,13 +82,17 @@ private def raise_error(op, name, data) raise name if name.is_a? Class - data.stringify_keys! if data.respond_to? :stringify_keys! + data.stringify_keys! if data.respond_to?(:stringify_keys!) - op.handle_failure ::Acfs::Response.new op.request, status: Rack::Utils.status_code(name), data: data + op.handle_failure ::Acfs::Response.new( + op.request, + status: Rack::Utils.status_code(name), + data: data + ) end class << self # Stub a resource with given handler block. An already created handler # for same resource class will be overridden. @@ -152,15 +156,17 @@ def stubbed(op) stub = stub_for op unless stub return false if allow_requests? - raise RealRequestsNotAllowedError.new <<-MSG.strip.gsub(/^[ ]{12}/, '') - No stub found for `#{op.action}' on `#{op.resource.name}' with params `#{op.full_params.inspect}', data `#{op.data.inspect}' and id `#{op.id}'. + raise RealRequestsNotAllowedError.new <<~ERROR + No stub found for `#{op.action}' on `#{op.resource.name}' \ + with params `#{op.full_params.inspect}', data `#{op.data.inspect}' \ + and id `#{op.id}'. Available stubs: #{pretty_print} - MSG + ERROR end stub.call op true end