wt-rspec-grape 0.3.0 → 0.4.0
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/README.md +6 -0
- data/lib/rspec/grape/methods.rb +10 -1
- data/lib/rspec/grape/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 557b54745719600189a9b4ae344430fc6c426ed0fd9b72a63307a5c707c47faf
|
|
4
|
+
data.tar.gz: eb71e02ea97135769162b523699e4092cf9ee37bd5ef7447e9806f9adb11cee2
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: '083d403ab5d91ccab4bac5b98013f5ceba01b35b45a5bfd63f7e4b353fe1497a294a585207ccd271ec7af0c5564307a5a323cf571cb94515353c2306d54afdc7'
|
|
7
|
+
data.tar.gz: ecaa68b2d9dcb7641383ca8ab7572664f995300b40182cce7ede30a08b7305767dae113ecc106a317d60cc65b6a40a69787f5046393c2ace502be8aa8a3b3068
|
data/README.md
CHANGED
|
@@ -88,6 +88,12 @@ Params can be passed to `call_api` method:
|
|
|
88
88
|
call_api({foo: :bar})
|
|
89
89
|
```
|
|
90
90
|
|
|
91
|
+
Body params are sent as JSON. When params contain a `Rack::Test::UploadedFile` (at any nesting level), they are sent as `multipart/form-data` instead:
|
|
92
|
+
|
|
93
|
+
```ruby
|
|
94
|
+
call_api(file: Rack::Test::UploadedFile.new('spec/fixtures/doc.pdf', 'application/pdf'))
|
|
95
|
+
```
|
|
96
|
+
|
|
91
97
|
### Stubbing API helpers
|
|
92
98
|
|
|
93
99
|
rspec-grape provides two methods to stub API helpers: `expect_endpoint_to` and `expect_endpoint_not_to`. You can easily write:
|
data/lib/rspec/grape/methods.rb
CHANGED
|
@@ -41,7 +41,7 @@ module RSpec
|
|
|
41
41
|
url = api_url
|
|
42
42
|
end
|
|
43
43
|
|
|
44
|
-
if %w[GET HEAD DELETE].include?(api_method.to_s.upcase) || params.empty?
|
|
44
|
+
if %w[GET HEAD DELETE].include?(api_method.to_s.upcase) || params.empty? || file_upload?(params)
|
|
45
45
|
self.send(api_method, url, params)
|
|
46
46
|
else
|
|
47
47
|
self.send(api_method, url, {}, { 'CONTENT_TYPE' => 'application/json', input: params.to_json })
|
|
@@ -66,6 +66,15 @@ module RSpec
|
|
|
66
66
|
def parameterized_url?
|
|
67
67
|
api_url =~ /\/:/
|
|
68
68
|
end
|
|
69
|
+
|
|
70
|
+
def file_upload?(value)
|
|
71
|
+
case value
|
|
72
|
+
when Rack::Test::UploadedFile then true
|
|
73
|
+
when Hash then value.values.any? { |v| file_upload?(v) }
|
|
74
|
+
when Array then value.any? { |v| file_upload?(v) }
|
|
75
|
+
else false
|
|
76
|
+
end
|
|
77
|
+
end
|
|
69
78
|
end
|
|
70
79
|
end
|
|
71
80
|
end
|
data/lib/rspec/grape/version.rb
CHANGED