Module: SoStubVeryTest
Defined Under Namespace
Classes: AmbiguousResponseError, MixedNamespacesError, NoPathGivenError
Constant Summary
collapse
- VERSION =
"0.0.0"
Class Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Class Attribute Details
.default_host ⇒ Object
Returns the value of attribute default_host.
65
66
67
|
# File 'lib/so_stub_very_test.rb', line 65
def default_host
@default_host
end
|
Class Method Details
.clear_custom_stubs ⇒ Object
67
68
69
70
71
72
73
|
# File 'lib/so_stub_very_test.rb', line 67
def clear_custom_stubs
custom_stubs.each do |stub|
Excon.stubs.delete stub
end
custom_stubs.clear
end
|
.custom_stubs ⇒ Object
75
76
77
|
# File 'lib/so_stub_very_test.rb', line 75
def custom_stubs
@custom_stubs ||= []
end
|
.defaults(&block) ⇒ Object
97
98
99
100
101
102
|
# File 'lib/so_stub_very_test.rb', line 97
def defaults(&block)
@defining_default_stubs = true
instance_exec &block
ensure
@defining_default_stubs = false
end
|
.defining_default_stubs ⇒ Object
79
80
81
|
# File 'lib/so_stub_very_test.rb', line 79
def defining_default_stubs
@defining_default_stubs ||= false
end
|
.register_host(name, host) ⇒ Object
83
84
85
86
87
88
89
90
91
92
93
94
95
|
# File 'lib/so_stub_very_test.rb', line 83
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|
namespace path, host do
send "stub_#{verb}", response
end
end
end
end
|
Instance Method Details
#namespace(path, host = nil, &block) ⇒ Object
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
# File 'lib/so_stub_very_test.rb', line 11
def namespace(path, host = nil, &block)
if stub_paths.any? && stub_host != host
raise MixedNamespacesError
end
stub_paths << path
self.stub_host = host || default_host
yield
ensure
stub_paths.pop
if stub_paths.empty?
self.stub_host = nil
end
end
|