bearcat 1.3.47 → 1.3.48
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/bearcat/spec_helpers.rb +50 -28
- data/lib/bearcat/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b57723897b87e3fa4b7f13dd36b248e8057291bbdc34d2fda4c36239c105f986
|
|
4
|
+
data.tar.gz: 55d51657b04977a727e98d256362af2dcb9557c233deee69f64db8bd7f7419e1
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ae314ea98375c5685ec644724b07b7fc90e040cd4efd92219e3545c94ca2003c14970a8f9a4dd5496ebd05bd286f62da1b11d6121a0ba5dc143bc2103de11dcf
|
|
7
|
+
data.tar.gz: c98e3a06fe914bb0f06d9c42d3cf1472d874255456d021462162ce19be5eecd272d83cdda14b426e24166e25a7e71bf58f8e32799335ea7788acc6e196e26881
|
data/lib/bearcat/spec_helpers.rb
CHANGED
|
@@ -13,6 +13,56 @@ module Bearcat::SpecHelpers
|
|
|
13
13
|
# Accepts optional keyword parameters to interpolate specific values into the URL.
|
|
14
14
|
# Returns a mostly-normal Webmock stub (:to_return has been overridden to allow :body to be set to a Hash)
|
|
15
15
|
def stub_bearcat(endpoint, prefix: nil, **kwargs)
|
|
16
|
+
url = case endpoint
|
|
17
|
+
when Symbol
|
|
18
|
+
ruby_method = Bearcat::Client.instance_method(endpoint)
|
|
19
|
+
match = SOURCE_REGEX.match(ruby_method.source)
|
|
20
|
+
bits = []
|
|
21
|
+
url = match[:url].gsub(/\/$/, '')
|
|
22
|
+
lend = 0
|
|
23
|
+
url.scan(/#\{(?<key>.*?)\}/) do |key|
|
|
24
|
+
m = Regexp.last_match
|
|
25
|
+
between = url[lend..m.begin(0)-1]
|
|
26
|
+
bits << between if between.present? && (m.begin(0) > lend)
|
|
27
|
+
lend = m.end(0)
|
|
28
|
+
bits << (kwargs[m[:key].to_sym] || /\w+/)
|
|
29
|
+
end
|
|
30
|
+
between = url[lend..-1]
|
|
31
|
+
bits << between if between.present?
|
|
32
|
+
|
|
33
|
+
bits.map do |bit|
|
|
34
|
+
case bit
|
|
35
|
+
when Regexp
|
|
36
|
+
bit.source
|
|
37
|
+
when String
|
|
38
|
+
Regexp.escape(bit)
|
|
39
|
+
end
|
|
40
|
+
end.join
|
|
41
|
+
when String
|
|
42
|
+
Regexp.escape(endpoint)
|
|
43
|
+
when Regexp
|
|
44
|
+
endpoint.source
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
url = Regexp.escape(resolve_prefix(prefix)) + url
|
|
48
|
+
stub = stub_request(match[:method].to_sym, Regexp.new(url))
|
|
49
|
+
|
|
50
|
+
# Override the to_return method to accept a Hash as body:
|
|
51
|
+
stub.define_singleton_method(:to_return, ->(*resps) {
|
|
52
|
+
resps.map do |resp|
|
|
53
|
+
resp[:headers] ||= {}
|
|
54
|
+
resp[:headers]["Content-Type"] ||= "application/json"
|
|
55
|
+
resp[:body] = resp[:body].to_json
|
|
56
|
+
end
|
|
57
|
+
super(*resps)
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
stub
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
private
|
|
64
|
+
|
|
65
|
+
def resolve_prefix(prefix)
|
|
16
66
|
if prefix == true
|
|
17
67
|
prefix = canvas_api_client if defined? canvas_api_client
|
|
18
68
|
prefix = canvas_sync_client if defined? canvas_sync_client
|
|
@@ -29,33 +79,5 @@ module Bearcat::SpecHelpers
|
|
|
29
79
|
when String
|
|
30
80
|
prefix
|
|
31
81
|
end
|
|
32
|
-
|
|
33
|
-
ruby_method = Bearcat::Client.instance_method(endpoint)
|
|
34
|
-
match = SOURCE_REGEX.match(ruby_method.source)
|
|
35
|
-
url = match[:url]
|
|
36
|
-
url = url.gsub(/#\{(?<key>.*?)\}/) do |match|
|
|
37
|
-
match = Regexp.last_match
|
|
38
|
-
v = kwargs[match[:key].to_sym]
|
|
39
|
-
case v
|
|
40
|
-
when nil
|
|
41
|
-
'\\w+'
|
|
42
|
-
when Regexp
|
|
43
|
-
v.source
|
|
44
|
-
when String
|
|
45
|
-
Regexp.escape(v)
|
|
46
|
-
end
|
|
47
|
-
end
|
|
48
|
-
url = prefix + url if prefix.present?
|
|
49
|
-
url_pattern = Regexp.new(url)
|
|
50
|
-
stub = stub_request(match[:method].to_sym, url_pattern)
|
|
51
|
-
stub.define_singleton_method(:to_return, ->(*resps) {
|
|
52
|
-
resps.map do |resp|
|
|
53
|
-
resp[:headers] ||= {}
|
|
54
|
-
resp[:headers]["Content-Type"] ||= "application/json"
|
|
55
|
-
resp[:body] = resp[:body].to_json
|
|
56
|
-
end
|
|
57
|
-
super(*resps)
|
|
58
|
-
})
|
|
59
|
-
stub
|
|
60
82
|
end
|
|
61
83
|
end
|
data/lib/bearcat/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: bearcat
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.3.
|
|
4
|
+
version: 1.3.48
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Nathan Mills, Jake Sorce
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2019-06-
|
|
11
|
+
date: 2019-06-28 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rake
|