rspec-grape 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +19 -10
- data/lib/rspec/grape/methods.rb +2 -6
- data/lib/rspec/grape/utils.rb +1 -1
- data/lib/rspec/grape/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 53dffc4ee324581222ce3f71be6f754d018c3519
|
4
|
+
data.tar.gz: c6fabdd0c1867136da1069423e60b1df239bd0bf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2355940cfd8573aeca126bfda5f4fc321f488572dca3bb5ef4dee96b08e018cf70062e21a998ca621e477c3d7b1213b678baf89bbb70b7e20706984a6b7dba05
|
7
|
+
data.tar.gz: 09fe14fde234836a83a7e874972f3e2ea943f301a1abcc5341288975d22fb344de85d97505dbcfc375395bc352219b681404488a0ab065d274bd9f924d600027
|
data/README.md
CHANGED
@@ -62,20 +62,12 @@ end
|
|
62
62
|
|
63
63
|
### Passing request params
|
64
64
|
|
65
|
-
Params can be
|
65
|
+
Params can be passed to `call_api` method:
|
66
66
|
|
67
67
|
```ruby
|
68
68
|
call_api({foo: :bar})
|
69
69
|
```
|
70
70
|
|
71
|
-
or set via `let`:
|
72
|
-
|
73
|
-
```ruby
|
74
|
-
let(:api_params) { { foo: :bar } }
|
75
|
-
```
|
76
|
-
|
77
|
-
Note, that params, explicitly passed to `call_api`, have precendence over thoose set in `api_params`.
|
78
|
-
|
79
71
|
### Stubbing API helpers
|
80
72
|
|
81
73
|
rspec-grape provides two methods to stub API helpers: `expect_endpoint_to` and `expect_endpoint_not_to`. You can easily write:
|
@@ -93,7 +85,7 @@ When you define some parameters in url like
|
|
93
85
|
```ruby
|
94
86
|
get '/url/with/:param'
|
95
87
|
```
|
96
|
-
you can use `parameterized_api_url` helper
|
88
|
+
you can use `parameterized_api_url` helper to generate full url. Pass parameters as hash. The result will be url with parameter names substituted with actual values:
|
97
89
|
```ruby
|
98
90
|
parameterized_api_url(param: 'defined') # '/url/with/defined'
|
99
91
|
```
|
@@ -101,6 +93,23 @@ parameterized_api_url(param: 'defined') # '/url/with/defined'
|
|
101
93
|
If some parameters are not set, method will raise `RSpec::Grape::UrlNotSetException`.
|
102
94
|
Note that `call_api` helper will use parameterized_url to generate url to be called.
|
103
95
|
|
96
|
+
### Nested descriptions
|
97
|
+
|
98
|
+
You may need to define nested descriptions of endpoint when you are using inline url parameters:
|
99
|
+
```ruby
|
100
|
+
describe 'GET /inline/:param' do
|
101
|
+
describe 'GET /inline/false' do
|
102
|
+
...
|
103
|
+
end
|
104
|
+
|
105
|
+
describe 'GET /inline/true' do
|
106
|
+
...
|
107
|
+
end
|
108
|
+
end
|
109
|
+
```
|
110
|
+
|
111
|
+
In this case `api_url` will point to inner description, `/inline/false` and `/inline/true` consequently. If you set all inline parameters in description, there is no need to pass parameters to `call_api`.
|
112
|
+
|
104
113
|
### Additional spec helpers
|
105
114
|
|
106
115
|
It is also possible to use two methods in your specs: `api_url` and `api_method`. The former returns url from spec description, while the latter returns http method.
|
data/lib/rspec/grape/methods.rb
CHANGED
@@ -18,7 +18,7 @@ module RSpec
|
|
18
18
|
def parameterized_api_url(params = nil)
|
19
19
|
raise RSpec::Grape::UrlIsNotParameterized unless parameterized_url?
|
20
20
|
|
21
|
-
params ||=
|
21
|
+
params ||= {}
|
22
22
|
|
23
23
|
url = api_url.dup
|
24
24
|
names = RSpec::Grape::Utils.url_param_names(api_url)
|
@@ -32,7 +32,7 @@ module RSpec
|
|
32
32
|
end
|
33
33
|
|
34
34
|
def call_api(params = nil)
|
35
|
-
params ||=
|
35
|
+
params ||= {}
|
36
36
|
|
37
37
|
if parameterized_url?
|
38
38
|
url = parameterized_api_url(params)
|
@@ -61,10 +61,6 @@ module RSpec
|
|
61
61
|
def parameterized_url?
|
62
62
|
api_url =~ /\/:/
|
63
63
|
end
|
64
|
-
|
65
|
-
def resolve_params(params = nil)
|
66
|
-
params || self.respond_to?(:api_params) ? api_params : {}
|
67
|
-
end
|
68
64
|
end
|
69
65
|
end
|
70
66
|
end
|
data/lib/rspec/grape/utils.rb
CHANGED
data/lib/rspec/grape/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspec-grape
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Timothy Kovalev
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-07-
|
11
|
+
date: 2016-07-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack-test
|