rspec-request_describer 0.2.2 → 0.3.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 +5 -5
- data/.circleci/config.yml +46 -0
- data/.gitignore +3 -6
- data/.rspec +1 -0
- data/.rubocop.yml +14 -0
- data/CHANGELOG.md +84 -29
- data/Gemfile +3 -0
- data/Gemfile.lock +96 -0
- data/README.md +67 -40
- data/Rakefile +1 -2
- data/lib/rspec/request_describer.rb +14 -11
- data/lib/rspec/request_describer/version.rb +1 -1
- data/rspec-request_describer.gemspec +11 -12
- data/spec/rspec/request_describer_spec.rb +122 -0
- data/spec/spec_helper.rb +21 -0
- metadata +13 -5
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
|
-
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: a8e2fcd9ca31fc770513b5d6c8aac8167a1a728f1413e830e4169bf680c66b0e
|
|
4
|
+
data.tar.gz: 6f7b366b4587b7c7b2fb327910a295f4a3652c6008e51223f70e358086bf03b9
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: '08ea603385b4e6820f15ae69d59e9653150564e89aca496366dcb1bf96feda8ccc97f77d1399af4725f0978a74f1c187a1bf66eede4836b99adeb95972ec3511'
|
|
7
|
+
data.tar.gz: d9203c8edf2eca941726f4909156705b226ea14a1ff690606dd439241f174bd04231cdc35872d9eef014d72d5d7199ee3beeaa68edb07d5f699168a3f79268ad
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
jobs:
|
|
2
|
+
rspec:
|
|
3
|
+
docker:
|
|
4
|
+
- image: ruby:2.5.3
|
|
5
|
+
steps:
|
|
6
|
+
- checkout
|
|
7
|
+
- restore_cache:
|
|
8
|
+
keys:
|
|
9
|
+
- v1-dependencies-{{ checksum "Gemfile.lock" }}
|
|
10
|
+
- v1-dependencies-
|
|
11
|
+
- run:
|
|
12
|
+
command: bundle install --jobs=4 --retry=3 --path vendor/bundle
|
|
13
|
+
name: bundle install
|
|
14
|
+
- save_cache:
|
|
15
|
+
key: v1-dependencies-{{ checksum "Gemfile.lock" }}
|
|
16
|
+
paths:
|
|
17
|
+
- ./vendor/bundle
|
|
18
|
+
- run:
|
|
19
|
+
command: bundle exec rspec
|
|
20
|
+
name: rspec
|
|
21
|
+
rubocop:
|
|
22
|
+
docker:
|
|
23
|
+
- image: ruby:2.5.3
|
|
24
|
+
steps:
|
|
25
|
+
- checkout
|
|
26
|
+
- restore_cache:
|
|
27
|
+
keys:
|
|
28
|
+
- v1-dependencies-{{ checksum "Gemfile.lock" }}
|
|
29
|
+
- v1-dependencies-
|
|
30
|
+
- run:
|
|
31
|
+
command: bundle install --jobs=4 --retry=3 --path vendor/bundle
|
|
32
|
+
name: bundle install
|
|
33
|
+
- save_cache:
|
|
34
|
+
key: v1-dependencies-{{ checksum "Gemfile.lock" }}
|
|
35
|
+
paths:
|
|
36
|
+
- ./vendor/bundle
|
|
37
|
+
- run:
|
|
38
|
+
command: bundle exec rubocop
|
|
39
|
+
name: rubocop
|
|
40
|
+
version: 2
|
|
41
|
+
workflows:
|
|
42
|
+
version: 2
|
|
43
|
+
test:
|
|
44
|
+
jobs:
|
|
45
|
+
- rspec
|
|
46
|
+
- rubocop
|
data/.gitignore
CHANGED
data/.rspec
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
--require spec_helper
|
data/.rubocop.yml
ADDED
data/CHANGELOG.md
CHANGED
|
@@ -1,45 +1,100 @@
|
|
|
1
|
-
|
|
1
|
+
# Changelog
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
6
7
|
|
|
7
|
-
|
|
8
|
+
## v0.3.0 - 2019-05-05
|
|
8
9
|
|
|
9
|
-
|
|
10
|
+
### Added
|
|
10
11
|
|
|
11
|
-
- Support
|
|
12
|
-
- Dependent on actionpack
|
|
12
|
+
- Support symbol keys in request headers.
|
|
13
13
|
|
|
14
|
-
## 0.
|
|
15
|
-
- Prevent warning for Rails 5 (Thx @mrkn, #9)
|
|
14
|
+
## 0.2.2 - 2018-05-13
|
|
16
15
|
|
|
17
|
-
|
|
18
|
-
- Rename `method` with `http_method` (Thx @yujinakayama, #8)
|
|
16
|
+
### Fixed
|
|
19
17
|
|
|
20
|
-
|
|
21
|
-
- Ignore case-sensivity on Content-Type checking
|
|
18
|
+
- Fix bug: Ignore case-sensitivity of HTTP headers.
|
|
22
19
|
|
|
23
|
-
## 0.
|
|
24
|
-
- Use more sophisticated method capture pattern
|
|
20
|
+
## 0.2.1 - 2017-02-27
|
|
25
21
|
|
|
26
|
-
|
|
27
|
-
- Add `send_request` to explicitly call `subject` (Thx @lazywei)
|
|
22
|
+
### Fixed
|
|
28
23
|
|
|
29
|
-
|
|
30
|
-
- Allow any non-space characters in URL path
|
|
24
|
+
- Fix error from `#process`.
|
|
31
25
|
|
|
32
|
-
## 0.0
|
|
33
|
-
- Allow hyphen in path
|
|
26
|
+
## 0.2.0 - 2017-02-27
|
|
34
27
|
|
|
35
|
-
|
|
36
|
-
- Define HTTPS as reserved header name
|
|
28
|
+
### Added
|
|
37
29
|
|
|
38
|
-
|
|
39
|
-
- Remove dependency on ActiveSupport's `Object#in?`
|
|
30
|
+
- Support actionpack 5.1.0.
|
|
40
31
|
|
|
41
|
-
|
|
42
|
-
- Support RSpec 3
|
|
32
|
+
### Changed
|
|
43
33
|
|
|
44
|
-
|
|
45
|
-
|
|
34
|
+
- Declare runtime dependency on actionpack.
|
|
35
|
+
|
|
36
|
+
## 0.1.1 - 2016-05-15
|
|
37
|
+
|
|
38
|
+
### Fixed
|
|
39
|
+
|
|
40
|
+
- Prevent warning for Rails 5.
|
|
41
|
+
|
|
42
|
+
## 0.1.0 - 2015-10-09
|
|
43
|
+
|
|
44
|
+
### Changed
|
|
45
|
+
|
|
46
|
+
- Rename `method` with `http_method`.
|
|
47
|
+
|
|
48
|
+
## 0.0.9 - 2015-06-24
|
|
49
|
+
|
|
50
|
+
### Changed
|
|
51
|
+
|
|
52
|
+
- Ignore case-sensivity on Content-Type checking.
|
|
53
|
+
|
|
54
|
+
## 0.0.8 - 2015-05-20
|
|
55
|
+
|
|
56
|
+
### Changed
|
|
57
|
+
|
|
58
|
+
- Use more sophisticated method capture pattern.
|
|
59
|
+
|
|
60
|
+
## 0.0.7 - 2015-04-20
|
|
61
|
+
|
|
62
|
+
### Added
|
|
63
|
+
|
|
64
|
+
- Add `send_request` to explicitly call `subject`.
|
|
65
|
+
|
|
66
|
+
## 0.0.6 - 2015-02-12
|
|
67
|
+
|
|
68
|
+
### Fixed
|
|
69
|
+
|
|
70
|
+
- Allow any non-space characters in URL path.
|
|
71
|
+
|
|
72
|
+
## 0.0.5 - 2014-12-25
|
|
73
|
+
|
|
74
|
+
### Fixed
|
|
75
|
+
|
|
76
|
+
- Allow hyphen in path.
|
|
77
|
+
|
|
78
|
+
## 0.0.4 - 2014-12-18
|
|
79
|
+
|
|
80
|
+
### Added
|
|
81
|
+
|
|
82
|
+
- Define HTTPS as reserved header name.
|
|
83
|
+
|
|
84
|
+
## 0.0.3 - 2014-10-13
|
|
85
|
+
|
|
86
|
+
### Removed
|
|
87
|
+
|
|
88
|
+
- Remove dependency on ActiveSupport's `Object#in?`.
|
|
89
|
+
|
|
90
|
+
## 0.0.2 - 2014-09-25
|
|
91
|
+
|
|
92
|
+
### Added
|
|
93
|
+
|
|
94
|
+
- Support RSpec 3.
|
|
95
|
+
|
|
96
|
+
## 0.0.1 - 2014-08-29
|
|
97
|
+
|
|
98
|
+
### Added
|
|
99
|
+
|
|
100
|
+
- 1st Release.
|
data/Gemfile
CHANGED
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: .
|
|
3
|
+
specs:
|
|
4
|
+
rspec-request_describer (0.2.2)
|
|
5
|
+
actionpack (>= 5.0.0)
|
|
6
|
+
|
|
7
|
+
GEM
|
|
8
|
+
remote: https://rubygems.org/
|
|
9
|
+
specs:
|
|
10
|
+
actionpack (5.2.2)
|
|
11
|
+
actionview (= 5.2.2)
|
|
12
|
+
activesupport (= 5.2.2)
|
|
13
|
+
rack (~> 2.0)
|
|
14
|
+
rack-test (>= 0.6.3)
|
|
15
|
+
rails-dom-testing (~> 2.0)
|
|
16
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.2)
|
|
17
|
+
actionview (5.2.2)
|
|
18
|
+
activesupport (= 5.2.2)
|
|
19
|
+
builder (~> 3.1)
|
|
20
|
+
erubi (~> 1.4)
|
|
21
|
+
rails-dom-testing (~> 2.0)
|
|
22
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.3)
|
|
23
|
+
activesupport (5.2.2)
|
|
24
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
|
25
|
+
i18n (>= 0.7, < 2)
|
|
26
|
+
minitest (~> 5.1)
|
|
27
|
+
tzinfo (~> 1.1)
|
|
28
|
+
ast (2.4.0)
|
|
29
|
+
builder (3.2.3)
|
|
30
|
+
concurrent-ruby (1.1.3)
|
|
31
|
+
crass (1.0.4)
|
|
32
|
+
diff-lcs (1.3)
|
|
33
|
+
erubi (1.7.1)
|
|
34
|
+
i18n (1.1.1)
|
|
35
|
+
concurrent-ruby (~> 1.0)
|
|
36
|
+
jaro_winkler (1.5.1)
|
|
37
|
+
loofah (2.2.3)
|
|
38
|
+
crass (~> 1.0.2)
|
|
39
|
+
nokogiri (>= 1.5.9)
|
|
40
|
+
mini_portile2 (2.3.0)
|
|
41
|
+
minitest (5.11.3)
|
|
42
|
+
nokogiri (1.8.5)
|
|
43
|
+
mini_portile2 (~> 2.3.0)
|
|
44
|
+
parallel (1.12.1)
|
|
45
|
+
parser (2.5.3.0)
|
|
46
|
+
ast (~> 2.4.0)
|
|
47
|
+
powerpack (0.1.2)
|
|
48
|
+
rack (2.0.6)
|
|
49
|
+
rack-test (1.1.0)
|
|
50
|
+
rack (>= 1.0, < 3)
|
|
51
|
+
rails-dom-testing (2.0.3)
|
|
52
|
+
activesupport (>= 4.2.0)
|
|
53
|
+
nokogiri (>= 1.6)
|
|
54
|
+
rails-html-sanitizer (1.0.4)
|
|
55
|
+
loofah (~> 2.2, >= 2.2.2)
|
|
56
|
+
rainbow (3.0.0)
|
|
57
|
+
rake (10.5.0)
|
|
58
|
+
rspec (3.8.0)
|
|
59
|
+
rspec-core (~> 3.8.0)
|
|
60
|
+
rspec-expectations (~> 3.8.0)
|
|
61
|
+
rspec-mocks (~> 3.8.0)
|
|
62
|
+
rspec-core (3.8.0)
|
|
63
|
+
rspec-support (~> 3.8.0)
|
|
64
|
+
rspec-expectations (3.8.2)
|
|
65
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
66
|
+
rspec-support (~> 3.8.0)
|
|
67
|
+
rspec-mocks (3.8.0)
|
|
68
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
69
|
+
rspec-support (~> 3.8.0)
|
|
70
|
+
rspec-support (3.8.0)
|
|
71
|
+
rubocop (0.61.1)
|
|
72
|
+
jaro_winkler (~> 1.5.1)
|
|
73
|
+
parallel (~> 1.10)
|
|
74
|
+
parser (>= 2.5, != 2.5.1.1)
|
|
75
|
+
powerpack (~> 0.1)
|
|
76
|
+
rainbow (>= 2.2.2, < 4.0)
|
|
77
|
+
ruby-progressbar (~> 1.7)
|
|
78
|
+
unicode-display_width (~> 1.4.0)
|
|
79
|
+
ruby-progressbar (1.10.0)
|
|
80
|
+
thread_safe (0.3.6)
|
|
81
|
+
tzinfo (1.2.5)
|
|
82
|
+
thread_safe (~> 0.1)
|
|
83
|
+
unicode-display_width (1.4.0)
|
|
84
|
+
|
|
85
|
+
PLATFORMS
|
|
86
|
+
ruby
|
|
87
|
+
|
|
88
|
+
DEPENDENCIES
|
|
89
|
+
bundler (~> 1.7)
|
|
90
|
+
rake (~> 10.0)
|
|
91
|
+
rspec
|
|
92
|
+
rspec-request_describer!
|
|
93
|
+
rubocop
|
|
94
|
+
|
|
95
|
+
BUNDLED WITH
|
|
96
|
+
1.17.1
|
data/README.md
CHANGED
|
@@ -1,88 +1,115 @@
|
|
|
1
1
|
# RSpec::RequestDescriber
|
|
2
|
-
|
|
2
|
+
|
|
3
|
+
[](https://circleci.com/gh/r7kamura/rspec-request_describer)
|
|
4
|
+
[](https://rubygems.org/gems/rspec-request_describer)
|
|
5
|
+
|
|
6
|
+
An RSpec plugin to write self-documenting request-specs.
|
|
7
|
+
|
|
8
|
+
This gem is designed for:
|
|
9
|
+
|
|
10
|
+
- [rack-test](https://github.com/rack-test/rack-test)
|
|
11
|
+
- [rspec-rails](https://github.com/rspec/rspec-rails)
|
|
3
12
|
|
|
4
13
|
## Setup
|
|
5
|
-
|
|
14
|
+
|
|
15
|
+
### Install
|
|
16
|
+
|
|
17
|
+
Add this line to your application's Gemfile:
|
|
6
18
|
|
|
7
19
|
```ruby
|
|
8
|
-
|
|
9
|
-
|
|
20
|
+
gem 'rspec-request_describer'
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
And then execute:
|
|
24
|
+
|
|
25
|
+
```
|
|
26
|
+
bundle
|
|
27
|
+
```
|
|
10
28
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
29
|
+
Or install it yourself as:
|
|
30
|
+
|
|
31
|
+
```
|
|
32
|
+
gem install rspec-request_describer
|
|
14
33
|
```
|
|
15
34
|
|
|
16
|
-
|
|
35
|
+
### Include
|
|
36
|
+
|
|
37
|
+
Include `RSpec::RequestDescriber` to your example groups like this:
|
|
17
38
|
|
|
18
39
|
```ruby
|
|
19
|
-
|
|
40
|
+
require 'rspec/request_describer'
|
|
41
|
+
|
|
20
42
|
RSpec.configuration.include RSpec::RequestDescriber, type: :request
|
|
21
43
|
```
|
|
22
44
|
|
|
23
45
|
## Usage
|
|
24
|
-
RSpec::RequestDescriber provides some `subject` and `let` to your specs.
|
|
25
46
|
|
|
26
47
|
### subject
|
|
27
|
-
|
|
28
|
-
|
|
48
|
+
|
|
49
|
+
`RSpec::RequestDescriber` provides `subject` from its top-level description.
|
|
29
50
|
|
|
30
51
|
```ruby
|
|
31
|
-
|
|
32
|
-
|
|
52
|
+
# subject will be `get('/users')`.
|
|
53
|
+
RSpec.describe 'GET /users' do
|
|
54
|
+
it { is_expected.to eq(200) }
|
|
33
55
|
end
|
|
34
56
|
```
|
|
35
57
|
|
|
36
58
|
### headers
|
|
37
|
-
`headers` is provided to modify request headers.
|
|
38
|
-
In the below example, a token is added into Authorization request header.
|
|
39
59
|
|
|
60
|
+
If you want to modify request headers, change `headers` before calling `subject`.
|
|
40
61
|
|
|
41
62
|
```ruby
|
|
42
|
-
|
|
43
|
-
|
|
63
|
+
# `subject` will be `get('/users', headers: { 'Authorization' => 'token 12345' })`.
|
|
64
|
+
RSpec.describe 'GET /users' do
|
|
65
|
+
context 'with Authorization header' do
|
|
44
66
|
before do
|
|
45
|
-
headers[
|
|
67
|
+
headers['Authorization'] = 'token 12345'
|
|
46
68
|
end
|
|
47
|
-
it {
|
|
69
|
+
it { is_expected.to eq(200) }
|
|
48
70
|
end
|
|
49
71
|
end
|
|
50
72
|
```
|
|
51
73
|
|
|
52
74
|
### params
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
For GET request `params` is converted into URL query string,
|
|
56
|
-
while it's converted into request body for the other methods
|
|
57
|
-
.
|
|
58
|
-
Note that if you specified `application/json` Content-Type request header,
|
|
59
|
-
`params` would be encoded into JSON format.
|
|
75
|
+
|
|
76
|
+
If you want to modify request parameters, change `params` before calling `subject`.
|
|
60
77
|
|
|
61
78
|
```ruby
|
|
62
|
-
|
|
63
|
-
|
|
79
|
+
# `subject` will be `get('/users', params: { 'sort' => 'id' })`.
|
|
80
|
+
RSpec.describe 'GET /users' do
|
|
81
|
+
context 'with sort parameter' do
|
|
64
82
|
before do
|
|
65
|
-
params[
|
|
83
|
+
params['sort'] = 'id'
|
|
66
84
|
end
|
|
67
85
|
|
|
68
|
-
it
|
|
86
|
+
it 'returns users in ID order' do
|
|
87
|
+
is_expected.to eq(200)
|
|
88
|
+
|
|
69
89
|
users = JSON.parse(response.body)
|
|
70
|
-
users[0]
|
|
71
|
-
users[1]
|
|
90
|
+
expect(users[0]['id']).to eq(1)
|
|
91
|
+
expect(users[1]['id']).to eq(2)
|
|
72
92
|
end
|
|
73
93
|
end
|
|
74
94
|
end
|
|
75
95
|
```
|
|
76
96
|
|
|
77
|
-
###
|
|
78
|
-
|
|
79
|
-
|
|
97
|
+
### variables in URL path
|
|
98
|
+
|
|
99
|
+
You can embed variables in URL path like `/users/:id`.
|
|
100
|
+
In this example, the returned value of `id` method will be emobeded as its real value.
|
|
80
101
|
|
|
81
102
|
```ruby
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
103
|
+
# `subject` will be `get("/users/#{user_id}")`.
|
|
104
|
+
RSpec.describe 'GET /users/:user_id' do
|
|
105
|
+
let(:user) do
|
|
106
|
+
User.create(name: 'alice')
|
|
85
107
|
end
|
|
86
|
-
|
|
108
|
+
|
|
109
|
+
let(:user_id) do
|
|
110
|
+
user.id
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
it { is_expected.to eq(200) }
|
|
87
114
|
end
|
|
88
115
|
```
|
data/Rakefile
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
require
|
|
2
|
-
|
|
1
|
+
require 'bundler/gem_tasks'
|
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
require
|
|
1
|
+
require 'rspec/request_describer/version'
|
|
2
2
|
|
|
3
3
|
module RSpec
|
|
4
4
|
module RequestDescriber
|
|
5
|
-
RESERVED_HEADER_NAMES = %w
|
|
5
|
+
RESERVED_HEADER_NAMES = %w[
|
|
6
6
|
content-type
|
|
7
7
|
host
|
|
8
8
|
https
|
|
9
|
-
|
|
9
|
+
].freeze
|
|
10
10
|
|
|
11
|
-
SUPPORTED_METHODS = %w
|
|
11
|
+
SUPPORTED_METHODS = %w[
|
|
12
12
|
DELETE
|
|
13
13
|
GET
|
|
14
14
|
PATCH
|
|
15
15
|
POST
|
|
16
16
|
PUT
|
|
17
|
-
|
|
17
|
+
].freeze
|
|
18
18
|
|
|
19
19
|
class << self
|
|
20
20
|
def included(base)
|
|
@@ -28,15 +28,17 @@ module RSpec
|
|
|
28
28
|
http_method,
|
|
29
29
|
path,
|
|
30
30
|
headers: env,
|
|
31
|
-
params: request_body
|
|
31
|
+
params: request_body
|
|
32
32
|
)
|
|
33
33
|
end
|
|
34
34
|
|
|
35
35
|
let(:request_body) do
|
|
36
|
-
if
|
|
36
|
+
if env['CONTENT_TYPE'] == 'application/json'
|
|
37
37
|
params.to_json
|
|
38
38
|
else
|
|
39
|
-
params
|
|
39
|
+
params.inject({}) do |result, (key, value)|
|
|
40
|
+
result.merge(key.to_s => value)
|
|
41
|
+
end
|
|
40
42
|
end
|
|
41
43
|
end
|
|
42
44
|
|
|
@@ -50,8 +52,9 @@ module RSpec
|
|
|
50
52
|
|
|
51
53
|
let(:env) do
|
|
52
54
|
headers.inject({}) do |result, (key, value)|
|
|
53
|
-
key =
|
|
54
|
-
key = key.
|
|
55
|
+
key = key.to_s
|
|
56
|
+
key = 'HTTP_' + key unless RESERVED_HEADER_NAMES.include?(key.downcase)
|
|
57
|
+
key = key.tr('-', '_').upcase
|
|
55
58
|
result.merge(key => value)
|
|
56
59
|
end
|
|
57
60
|
end
|
|
@@ -67,7 +70,7 @@ module RSpec
|
|
|
67
70
|
end
|
|
68
71
|
|
|
69
72
|
let(:path) do
|
|
70
|
-
endpoint_segments[2].gsub(/:(\w+[!?=]?)/) { send(
|
|
73
|
+
endpoint_segments[2].gsub(/:(\w+[!?=]?)/) { send(Regexp.last_match(1)) }
|
|
71
74
|
end
|
|
72
75
|
end
|
|
73
76
|
end
|
|
@@ -1,23 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
lib = File.expand_path('../lib', __FILE__)
|
|
1
|
+
lib = File.expand_path('lib', __dir__)
|
|
3
2
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
3
|
require 'rspec/request_describer/version'
|
|
5
4
|
|
|
6
5
|
Gem::Specification.new do |spec|
|
|
7
|
-
spec.name =
|
|
6
|
+
spec.name = 'rspec-request_describer'
|
|
8
7
|
spec.version = RSpec::RequestDescriber::VERSION
|
|
9
|
-
spec.authors = [
|
|
10
|
-
spec.email = [
|
|
11
|
-
spec.summary =
|
|
12
|
-
spec.homepage =
|
|
13
|
-
spec.license =
|
|
8
|
+
spec.authors = ['Ryo Nakamura']
|
|
9
|
+
spec.email = ['r7kamura@gmail.com']
|
|
10
|
+
spec.summary = 'An RSpec plugin to write self-documenting request-specs.'
|
|
11
|
+
spec.homepage = 'https://github.com/r7kamura/rspec-request_describer'
|
|
12
|
+
spec.license = 'MIT'
|
|
14
13
|
|
|
15
14
|
spec.files = `git ls-files -z`.split("\x0")
|
|
16
15
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
|
17
16
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
|
18
|
-
spec.require_paths = [
|
|
17
|
+
spec.require_paths = ['lib']
|
|
19
18
|
|
|
20
|
-
spec.add_dependency
|
|
21
|
-
spec.add_development_dependency
|
|
22
|
-
spec.add_development_dependency
|
|
19
|
+
spec.add_dependency 'actionpack', '>= 5.0.0'
|
|
20
|
+
spec.add_development_dependency 'bundler', '~> 1.7'
|
|
21
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
|
23
22
|
end
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
RSpec.describe RSpec::RequestDescriber do
|
|
2
|
+
include RSpec::RequestDescriber
|
|
3
|
+
|
|
4
|
+
def get(*args)
|
|
5
|
+
[__method__, *args]
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
describe 'GET /users' do
|
|
9
|
+
it 'calls #get' do
|
|
10
|
+
is_expected.to eq(
|
|
11
|
+
[
|
|
12
|
+
:get,
|
|
13
|
+
'/users',
|
|
14
|
+
headers: {},
|
|
15
|
+
params: {}
|
|
16
|
+
]
|
|
17
|
+
)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
context 'with headers' do
|
|
21
|
+
let(:headers) do
|
|
22
|
+
super().merge('Authorization' => 'token 12345')
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
it 'calls #get with HTTP_ prefixed and upper-cased headers' do
|
|
26
|
+
is_expected.to eq(
|
|
27
|
+
[
|
|
28
|
+
:get,
|
|
29
|
+
'/users',
|
|
30
|
+
headers: { 'HTTP_AUTHORIZATION' => 'token 12345' },
|
|
31
|
+
params: {}
|
|
32
|
+
]
|
|
33
|
+
)
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
context 'with headers including reserved header name' do
|
|
38
|
+
let(:headers) do
|
|
39
|
+
super().merge('Https' => 'on')
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
it 'calls #get with headers with non HTTP_ prefixed and upper-cased headers' do
|
|
43
|
+
is_expected.to eq(
|
|
44
|
+
[
|
|
45
|
+
:get,
|
|
46
|
+
'/users',
|
|
47
|
+
headers: { 'HTTPS' => 'on' },
|
|
48
|
+
params: {}
|
|
49
|
+
]
|
|
50
|
+
)
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
context 'with symbolized keys headers' do
|
|
55
|
+
let(:headers) do
|
|
56
|
+
super().merge(AUTHORIZATION: 'token 12345')
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
it 'calls #get with HTTP_ prefixed and stringified keys headers' do
|
|
60
|
+
is_expected.to eq(
|
|
61
|
+
[
|
|
62
|
+
:get,
|
|
63
|
+
'/users',
|
|
64
|
+
headers: { 'HTTP_AUTHORIZATION' => 'token 12345' },
|
|
65
|
+
params: {}
|
|
66
|
+
]
|
|
67
|
+
)
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
context 'with params' do
|
|
72
|
+
let(:params) do
|
|
73
|
+
super().merge('sort' => 'id')
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
it 'calls #get with params' do
|
|
77
|
+
is_expected.to eq(
|
|
78
|
+
[
|
|
79
|
+
:get,
|
|
80
|
+
'/users',
|
|
81
|
+
headers: {},
|
|
82
|
+
params: { 'sort' => 'id' }
|
|
83
|
+
]
|
|
84
|
+
)
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
context 'with symbolized keys params' do
|
|
89
|
+
let(:params) do
|
|
90
|
+
super().merge(sort: 'id')
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
it 'calls #get with stringified keys params' do
|
|
94
|
+
is_expected.to eq(
|
|
95
|
+
[
|
|
96
|
+
:get,
|
|
97
|
+
'/users',
|
|
98
|
+
headers: {},
|
|
99
|
+
params: { 'sort' => 'id' }
|
|
100
|
+
]
|
|
101
|
+
)
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
describe 'GET /users/:user_id' do
|
|
107
|
+
let(:user_id) do
|
|
108
|
+
1
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
it 'calles #get with embeded variable in URL path' do
|
|
112
|
+
is_expected.to eq(
|
|
113
|
+
[
|
|
114
|
+
:get,
|
|
115
|
+
'/users/1',
|
|
116
|
+
headers: {},
|
|
117
|
+
params: {}
|
|
118
|
+
]
|
|
119
|
+
)
|
|
120
|
+
end
|
|
121
|
+
end
|
|
122
|
+
end
|
data/spec/spec_helper.rb
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
require 'rspec/request_describer'
|
|
2
|
+
|
|
3
|
+
RSpec.configure do |config|
|
|
4
|
+
config.expect_with :rspec do |expectations|
|
|
5
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
config.mock_with :rspec do |mocks|
|
|
9
|
+
mocks.verify_partial_doubles = true
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
config.shared_context_metadata_behavior = :apply_to_host_groups
|
|
13
|
+
|
|
14
|
+
config.filter_run_when_matching :focus
|
|
15
|
+
|
|
16
|
+
config.disable_monkey_patching!
|
|
17
|
+
|
|
18
|
+
config.warnings = true
|
|
19
|
+
|
|
20
|
+
config.default_formatter = 'doc' if config.files_to_run.one?
|
|
21
|
+
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: rspec-request_describer
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.3.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ryo Nakamura
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2019-05-05 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: actionpack
|
|
@@ -59,15 +59,21 @@ executables: []
|
|
|
59
59
|
extensions: []
|
|
60
60
|
extra_rdoc_files: []
|
|
61
61
|
files:
|
|
62
|
+
- ".circleci/config.yml"
|
|
62
63
|
- ".gitignore"
|
|
64
|
+
- ".rspec"
|
|
65
|
+
- ".rubocop.yml"
|
|
63
66
|
- CHANGELOG.md
|
|
64
67
|
- Gemfile
|
|
68
|
+
- Gemfile.lock
|
|
65
69
|
- LICENSE.txt
|
|
66
70
|
- README.md
|
|
67
71
|
- Rakefile
|
|
68
72
|
- lib/rspec/request_describer.rb
|
|
69
73
|
- lib/rspec/request_describer/version.rb
|
|
70
74
|
- rspec-request_describer.gemspec
|
|
75
|
+
- spec/rspec/request_describer_spec.rb
|
|
76
|
+
- spec/spec_helper.rb
|
|
71
77
|
homepage: https://github.com/r7kamura/rspec-request_describer
|
|
72
78
|
licenses:
|
|
73
79
|
- MIT
|
|
@@ -88,8 +94,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
88
94
|
version: '0'
|
|
89
95
|
requirements: []
|
|
90
96
|
rubyforge_project:
|
|
91
|
-
rubygems_version: 2.6
|
|
97
|
+
rubygems_version: 2.7.6
|
|
92
98
|
signing_key:
|
|
93
99
|
specification_version: 4
|
|
94
|
-
summary:
|
|
95
|
-
test_files:
|
|
100
|
+
summary: An RSpec plugin to write self-documenting request-specs.
|
|
101
|
+
test_files:
|
|
102
|
+
- spec/rspec/request_describer_spec.rb
|
|
103
|
+
- spec/spec_helper.rb
|