wt-rspec-grape 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c69d33d068a6e76b6e3940b922d31537e1b707f7dc2d5ee90ac393884a972d23
4
- data.tar.gz: b72bd50ac8c9ec14339e0e063025c7b1b89350a1529fe03a6f32ba046bad22aa
3
+ metadata.gz: 557b54745719600189a9b4ae344430fc6c426ed0fd9b72a63307a5c707c47faf
4
+ data.tar.gz: eb71e02ea97135769162b523699e4092cf9ee37bd5ef7447e9806f9adb11cee2
5
5
  SHA512:
6
- metadata.gz: 0e9e13c2c5cceadb64a04784bcd900167ae1a1beb209b62df22a5e89e531025ffaaa6006b4659101ea9294a6453fe73227805f241a33c2a6c2f66c969683f032
7
- data.tar.gz: 16281b22be187da754c68b954677c0e378eedb9ad8dd4a76bdb0ead8240169ffc6589a3a16fe3f67b272ae784cc3d06b8db76e395037d8b322bb8e4ba4af3140
6
+ metadata.gz: '083d403ab5d91ccab4bac5b98013f5ceba01b35b45a5bfd63f7e4b353fe1497a294a585207ccd271ec7af0c5564307a5a323cf571cb94515353c2306d54afdc7'
7
+ data.tar.gz: ecaa68b2d9dcb7641383ca8ab7572664f995300b40182cce7ede30a08b7305767dae113ecc106a317d60cc65b6a40a69787f5046393c2ace502be8aa8a3b3068
data/README.md CHANGED
@@ -50,6 +50,24 @@ Or use a symbol:
50
50
  describe MyAPI, :api do
51
51
  ```
52
52
 
53
+ ### Root API
54
+
55
+ By default requests are sent to `described_class`. Since Grape 3.3, mounted APIs no longer inherit helpers, rescue handlers and prefixes from the API they are mounted into, so specs usually need to hit the root API instead. Configure it once in your spec helper:
56
+
57
+ ```ruby
58
+ RSpec.configure do |config|
59
+ config.grape_app = API
60
+ end
61
+ ```
62
+
63
+ Any Rack app works, e.g. `Rails.application`. It can also be overridden per example group with metadata:
64
+
65
+ ```ruby
66
+ describe MyAPI, type: :api, grape_app: OtherAPI do
67
+ ```
68
+
69
+ Defining `app` (or `let(:app)`) in an example group still takes precedence.
70
+
53
71
  ### Basic usage
54
72
 
55
73
  This gem provides the `call_api` helper method. It automatically reads endpoint url and method from context description, allowing you to avoid duplication and write a shorter spec:
@@ -70,6 +88,12 @@ Params can be passed to `call_api` method:
70
88
  call_api({foo: :bar})
71
89
  ```
72
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
+
73
97
  ### Stubbing API helpers
74
98
 
75
99
  rspec-grape provides two methods to stub API helpers: `expect_endpoint_to` and `expect_endpoint_not_to`. You can easily write:
@@ -4,7 +4,7 @@ module RSpec
4
4
  include Rack::Test::Methods
5
5
 
6
6
  def app
7
- self.described_class
7
+ self.class.metadata[:grape_app] || RSpec.configuration.grape_app || described_class
8
8
  end
9
9
 
10
10
  def api_method
@@ -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
@@ -1,5 +1,5 @@
1
1
  module Rspec
2
2
  module Grape
3
- VERSION = "0.2.0"
3
+ VERSION = "0.4.0"
4
4
  end
5
5
  end
@@ -8,6 +8,8 @@ require 'rspec/grape/utils'
8
8
  require 'rspec/grape/methods'
9
9
 
10
10
  RSpec.configure do |config|
11
+ config.add_setting :grape_app
12
+
11
13
  config.include RSpec::Grape::Methods, type: :api
12
14
  config.include RSpec::Grape::Methods, :api
13
15
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wt-rspec-grape
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ivan Tarapon