so_stub_very_test 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1ab2e09581e5a95d21c45bc5dcf362eba75dbbb7
4
- data.tar.gz: 747f711125f10c91436421fc41178be84ee675bd
3
+ metadata.gz: 8bea5981613aaddffae3b7321fd518e334f52b58
4
+ data.tar.gz: ab5194c35b3fa09d9719803f0a0ad77c75324e8c
5
5
  SHA512:
6
- metadata.gz: 52732f7b77f26b1e49afdc0089aafa5f3fa74766effb526c0618eab31870c66bbfc0362214e7174874612a7f2588e96fa4d8262536db0005a24863b218c47a17
7
- data.tar.gz: f1b376fb7c675adc75e7f8248e502961601fe5208d4ae7df46625f6d577130bba380b4caa64af804887c98945749363c6b857330e211637f1ff4c80e60e5c27b
6
+ metadata.gz: 047c0bb072bcd48c962cdcb806b87a268ee7798e03871cce6d01bb5c439d7e42aeec27dd750d5202f34e9168b68b03ea8791367cd04509ade8dc1ca3dca270c9
7
+ data.tar.gz: a9dacada5866084ecaddbd228802a1c25eb9ea43281c9c6cf3644303993a86cfde72ebf664e7f6b7f3804e9e3d7c8841831507c16d2822dad82438e0ca9b8f5e
@@ -1,3 +1,3 @@
1
1
  module SoStubVeryTest
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -9,9 +9,7 @@ module SoStubVeryTest
9
9
  class NoPathGivenError < StandardError; end
10
10
 
11
11
  def namespace(path, host = nil, &block)
12
- if stub_paths.any? && host && stub_host != host
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 stub_host || default_host
49
- request[:host] = stub_host || default_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
- namespace path, host do
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
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: so_stub_very_test
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonathan Clem