bearcat 1.3.47 → 1.3.48

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
  SHA256:
3
- metadata.gz: 80686ce28c0fbf0d96f638ff05e1f82ab76638d782d963a8f544b0c0fab17a8f
4
- data.tar.gz: cd9784f0d0e63527c13fe5f34703915e61a05030ab618fe60889ae1ec449e3f5
3
+ metadata.gz: b57723897b87e3fa4b7f13dd36b248e8057291bbdc34d2fda4c36239c105f986
4
+ data.tar.gz: 55d51657b04977a727e98d256362af2dcb9557c233deee69f64db8bd7f7419e1
5
5
  SHA512:
6
- metadata.gz: 980dc61ffa0dd83c74ac5307c4a9f6ac5b2e0f31af634a6f90257f8053079e512c5bb6c08ea7e77a50ebff62f39469a7aced145bc1bed59adf76ee74c3020700
7
- data.tar.gz: e8147a8d1e751c533dacd061b5f7ab0094c8c6aa17c5fb0d4720b52900d84418a58679aaafb2f2500223f41e4942de978befcb5ccbe3d7850733e7165340b168
6
+ metadata.gz: ae314ea98375c5685ec644724b07b7fc90e040cd4efd92219e3545c94ca2003c14970a8f9a4dd5496ebd05bd286f62da1b11d6121a0ba5dc143bc2103de11dcf
7
+ data.tar.gz: c98e3a06fe914bb0f06d9c42d3cf1472d874255456d021462162ce19be5eecd272d83cdda14b426e24166e25a7e71bf58f8e32799335ea7788acc6e196e26881
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Bearcat
2
- VERSION = '1.3.47' unless defined?(Bearcat::VERSION)
2
+ VERSION = '1.3.48' unless defined?(Bearcat::VERSION)
3
3
  end
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.47
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-27 00:00:00.000000000 Z
11
+ date: 2019-06-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake