module SoStubVeryTest
Constants
- VERSION
Attributes
default_host[RW]
Public Class Methods
clear_custom_stubs()
click to toggle source
# File lib/so_stub_very_test.rb, line 73 def clear_custom_stubs custom_stubs.each do |stub| Excon.stubs.delete stub end custom_stubs.clear end
custom_stubs()
click to toggle source
# File lib/so_stub_very_test.rb, line 81 def custom_stubs @custom_stubs ||= [] end
defaults(&block)
click to toggle source
# File lib/so_stub_very_test.rb, line 101 def defaults(&block) @defining_default_stubs = true instance_exec &block ensure @defining_default_stubs = false end
defining_default_stubs()
click to toggle source
# File lib/so_stub_very_test.rb, line 85 def defining_default_stubs @defining_default_stubs ||= false end
register_host(name, host)
click to toggle source
# File lib/so_stub_very_test.rb, line 89 def register_host(name, host) define_method "#{name}_namespace" do |path, &block| namespace path, host, &block end Excon::HTTP_VERBS.each do |verb| define_method "#{name}_stub_#{verb}" do |path, response = nil| send "stub_#{verb}", path, response, host end end end
Public Instance Methods
namespace(path, host = nil) { || ... }
click to toggle source
# File lib/so_stub_very_test.rb, line 11 def namespace(path, host = nil, &block) validate_host(host) stub_paths << path self.stub_host = host || default_host yield ensure stub_paths.pop if stub_paths.empty? self.stub_host = nil end end
Private Instance Methods
create_path_regexp(path)
click to toggle source
# File lib/so_stub_very_test.rb, line 111 def create_path_regexp(path) Regexp.new '\A' + path + '\Z' end
default_host()
click to toggle source
# File lib/so_stub_very_test.rb, line 115 def default_host SoStubVeryTest.default_host end
get_request_host(host)
click to toggle source
# File lib/so_stub_very_test.rb, line 119 def get_request_host(host) stub_host || host || default_host end
is_request_options?(options)
click to toggle source
# File lib/so_stub_very_test.rb, line 123 def is_request_options?(options) options.is_a?(Hash) && options.has_key?(:path) end
replace_path_params(path)
click to toggle source
# File lib/so_stub_very_test.rb, line 127 def replace_path_params(path) path.gsub /:[^\/]+/, '[^\/]+' end
stub_host()
click to toggle source
# File lib/so_stub_very_test.rb, line 135 def stub_host @stub_host end
stub_host=(host)
click to toggle source
# File lib/so_stub_very_test.rb, line 131 def stub_host=(host) @stub_host = host end
stub_path()
click to toggle source
# File lib/so_stub_very_test.rb, line 139 def stub_path stub_paths.join end
stub_paths()
click to toggle source
# File lib/so_stub_very_test.rb, line 143 def stub_paths @stub_paths ||= [] end
validate_host(host)
click to toggle source
# File lib/so_stub_very_test.rb, line 153 def validate_host(host) if stub_paths.any? && host && stub_host != host raise MixedNamespacesError, "Namespaces can't be mixed (#{stub_host} and #{host == nil ? "nil" : host})" end end
validate_path_given(path)
click to toggle source
# File lib/so_stub_very_test.rb, line 147 def validate_path_given(path) if stub_paths.empty? && !(is_request_options?(path) || path.is_a?(String)) raise NoPathGivenError, "Must provide a path to stub requests for" end end
validate_single_response(block, response)
click to toggle source
# File lib/so_stub_very_test.rb, line 159 def validate_single_response(block, response) if block && response raise AmbiguousResponseError, "Must provide only either a response object or a block" end end