so_stub_very_test 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/so_stub_very_test/version.rb +1 -1
- data/lib/so_stub_very_test.rb +16 -9
- data/test/so_stub_very_test_test.rb +6 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8bea5981613aaddffae3b7321fd518e334f52b58
|
4
|
+
data.tar.gz: ab5194c35b3fa09d9719803f0a0ad77c75324e8c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 047c0bb072bcd48c962cdcb806b87a268ee7798e03871cce6d01bb5c439d7e42aeec27dd750d5202f34e9168b68b03ea8791367cd04509ade8dc1ca3dca270c9
|
7
|
+
data.tar.gz: a9dacada5866084ecaddbd228802a1c25eb9ea43281c9c6cf3644303993a86cfde72ebf664e7f6b7f3804e9e3d7c8841831507c16d2822dad82438e0ca9b8f5e
|
data/lib/so_stub_very_test.rb
CHANGED
@@ -9,9 +9,7 @@ module SoStubVeryTest
|
|
9
9
|
class NoPathGivenError < StandardError; end
|
10
10
|
|
11
11
|
def namespace(path, host = nil, &block)
|
12
|
-
|
13
|
-
raise MixedNamespacesError, "Namespaces can't be mixed (#{stub_host} and #{host == nil ? "nil" : host})"
|
14
|
-
end
|
12
|
+
validate_host(host)
|
15
13
|
|
16
14
|
stub_paths << path
|
17
15
|
self.stub_host = host || default_host
|
@@ -25,7 +23,8 @@ module SoStubVeryTest
|
|
25
23
|
end
|
26
24
|
|
27
25
|
Excon::HTTP_VERBS.each do |verb|
|
28
|
-
define_method "stub_#{verb}" do |path, response = nil, &block|
|
26
|
+
define_method "stub_#{verb}" do |path, response = nil, host = nil, &block|
|
27
|
+
validate_host(host)
|
29
28
|
validate_path_given(path)
|
30
29
|
|
31
30
|
unless path.is_a? String
|
@@ -45,8 +44,8 @@ module SoStubVeryTest
|
|
45
44
|
|
46
45
|
request = { method: verb, path: path }
|
47
46
|
|
48
|
-
if
|
49
|
-
request[:host] =
|
47
|
+
if host = get_request_host(host)
|
48
|
+
request[:host] = host
|
50
49
|
end
|
51
50
|
|
52
51
|
unless response.is_a?(Proc) || (response.is_a?(Hash) && response.has_key?(:body))
|
@@ -87,9 +86,7 @@ module SoStubVeryTest
|
|
87
86
|
|
88
87
|
Excon::HTTP_VERBS.each do |verb|
|
89
88
|
define_method "#{name}_stub_#{verb}" do |path, response = nil|
|
90
|
-
|
91
|
-
send "stub_#{verb}", response
|
92
|
-
end
|
89
|
+
send "stub_#{verb}", path, response, host
|
93
90
|
end
|
94
91
|
end
|
95
92
|
end
|
@@ -112,6 +109,10 @@ module SoStubVeryTest
|
|
112
109
|
SoStubVeryTest.default_host
|
113
110
|
end
|
114
111
|
|
112
|
+
def get_request_host(host)
|
113
|
+
stub_host || host || default_host
|
114
|
+
end
|
115
|
+
|
115
116
|
def replace_path_params(path)
|
116
117
|
path.gsub /:[^\/]+/, '[^\/]+'
|
117
118
|
end
|
@@ -138,6 +139,12 @@ module SoStubVeryTest
|
|
138
139
|
end
|
139
140
|
end
|
140
141
|
|
142
|
+
def validate_host(host)
|
143
|
+
if stub_paths.any? && host && stub_host != host
|
144
|
+
raise MixedNamespacesError, "Namespaces can't be mixed (#{stub_host} and #{host == nil ? "nil" : host})"
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
141
148
|
def validate_single_response(block, response)
|
142
149
|
if block && response
|
143
150
|
raise AmbiguousResponseError, "Must provide only either a response object or a block"
|
@@ -148,6 +148,12 @@ class TestSoStubVeryTest < Minitest::Test
|
|
148
148
|
assert_equal Excon.stubs, [[{ path: /\A\/foo\Z/, host: "foo.example.com", method: :get }, { body: true }]]
|
149
149
|
end
|
150
150
|
|
151
|
+
def test_passing_string_body_to_namespaced_stub
|
152
|
+
SoStubVeryTest.register_host :foo, "foo.example.com"
|
153
|
+
foo_stub_get "/foo", "bar"
|
154
|
+
assert_equal Excon.stubs, [[{ path: /\A\/foo\Z/, host: "foo.example.com", method: :get }, { body: "bar" }]]
|
155
|
+
end
|
156
|
+
|
151
157
|
def test_can_not_mismatch_namespaces
|
152
158
|
SoStubVeryTest.register_host :foo, "foo.example.com"
|
153
159
|
|