rspec-request_describer 0.4.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -10
- data/CHANGELOG.md +17 -0
- data/README.md +40 -31
- data/Rakefile +2 -0
- data/lib/rspec/request_describer/version.rb +3 -1
- data/lib/rspec/request_describer.rb +9 -2
- metadata +5 -14
- data/.github/workflows/test.yml +0 -17
- data/.gitignore +0 -11
- data/Gemfile +0 -8
- data/Gemfile.lock +0 -52
- data/rspec-request_describer.gemspec +0 -18
- data/spec/rspec/request_describer_spec.rb +0 -141
- data/spec/spec_helper.rb +0 -21
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: de9d2d420aea6eaecc42d619a9b1d8f0088def0dd316a88fa13861b53437ef98
|
4
|
+
data.tar.gz: 17cd3e64fe24ac5f0818f77514ee340cd94dc3c879544ea48bddaed84f425862
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f0a1c4c9cb78bc8030407b1933c5ce8f63ad42ee2e7eb115639800ef431d6a149c436241fc9b4daecd1e2b3cd9ef21924426da68a70b2a372a5b30b92bd671d0
|
7
|
+
data.tar.gz: 117491f2b88edde6a0f3a7271b99f5223a6389da5624b35bb014408f5b6539e64d5235d66ea01de9599f88007fb58520201e9068210f74ec872aa6052a5199da
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,23 @@
|
|
2
2
|
|
3
3
|
## Unreleased
|
4
4
|
|
5
|
+
## 0.6.0 - 2024-08-02
|
6
|
+
|
7
|
+
### Changed
|
8
|
+
|
9
|
+
- Drop Ruby 2.6- support.
|
10
|
+
|
11
|
+
### Fixed
|
12
|
+
|
13
|
+
- Reduce some files from gem package.
|
14
|
+
- Correct some RuboCop offenses.
|
15
|
+
|
16
|
+
## 0.5.0 - 2024-03-28
|
17
|
+
|
18
|
+
### Added
|
19
|
+
|
20
|
+
- Raise friendly error on incorrect `describe` usage.
|
21
|
+
|
5
22
|
## 0.4.0 - 2023-07-10
|
6
23
|
|
7
24
|
### Added
|
data/README.md
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
[![test](https://github.com/r7kamura/rspec-request_describer/actions/workflows/test.yml/badge.svg)](https://github.com/r7kamura/rspec-request_describer/actions/workflows/test.yml)
|
4
4
|
[![Gem Version](https://badge.fury.io/rb/rspec-request_describer.svg)](https://rubygems.org/gems/rspec-request_describer)
|
5
5
|
|
6
|
-
|
6
|
+
RSpec plugin to write self-documenting request-specs.
|
7
7
|
|
8
8
|
This gem is designed for:
|
9
9
|
|
@@ -12,33 +12,18 @@ This gem is designed for:
|
|
12
12
|
|
13
13
|
## Setup
|
14
14
|
|
15
|
-
### Install
|
16
|
-
|
17
15
|
Add this line to your application's Gemfile:
|
18
16
|
|
19
17
|
```ruby
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
And then execute:
|
24
|
-
|
25
|
-
```
|
26
|
-
bundle
|
27
|
-
```
|
28
|
-
|
29
|
-
Or install it yourself as:
|
30
|
-
|
31
|
-
```
|
32
|
-
gem install rspec-request_describer
|
18
|
+
group :test do
|
19
|
+
gem 'rspec-request_describer'
|
20
|
+
end
|
33
21
|
```
|
34
22
|
|
35
|
-
|
36
|
-
|
37
|
-
Include `RSpec::RequestDescriber` to your example groups like this:
|
23
|
+
And then include `RSpec::RequestDescriber`:
|
38
24
|
|
39
25
|
```ruby
|
40
|
-
|
41
|
-
|
26
|
+
# spec/rails_helper.rb
|
42
27
|
RSpec.configure do |config|
|
43
28
|
config.include RSpec::RequestDescriber, type: :request
|
44
29
|
end
|
@@ -46,15 +31,42 @@ end
|
|
46
31
|
|
47
32
|
## Usage
|
48
33
|
|
49
|
-
|
34
|
+
Write HTTP method and URL path in the top-level description of your request-specs.
|
50
35
|
|
51
|
-
|
36
|
+
```ruby
|
37
|
+
# spec/requests/users/index_spec.rb
|
38
|
+
RSpec.describe 'GET /users' do
|
39
|
+
it 'returns 200' do
|
40
|
+
subject
|
41
|
+
expect(response).to have_http_status(200)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
```
|
52
45
|
|
53
|
-
`RSpec::RequestDescriber`
|
46
|
+
Internally, `RSpec::RequestDescriber` defines `subject` and some `let` from its top-level description like this:
|
54
47
|
|
55
48
|
```ruby
|
56
|
-
# subject will be `get('/users')`.
|
57
49
|
RSpec.describe 'GET /users' do
|
50
|
+
subject do
|
51
|
+
__send__(http_method, path, headers:, params:)
|
52
|
+
end
|
53
|
+
|
54
|
+
let(:http_method) do
|
55
|
+
'get'
|
56
|
+
end
|
57
|
+
|
58
|
+
let(:path) do
|
59
|
+
'/users'
|
60
|
+
end
|
61
|
+
|
62
|
+
let(:headers) do
|
63
|
+
{}
|
64
|
+
end
|
65
|
+
|
66
|
+
let(:params) do
|
67
|
+
{}
|
68
|
+
end
|
69
|
+
|
58
70
|
it 'returns 200' do
|
59
71
|
subject
|
60
72
|
expect(response).to have_http_status(200)
|
@@ -64,10 +76,9 @@ end
|
|
64
76
|
|
65
77
|
### headers
|
66
78
|
|
67
|
-
If you want to modify request headers, change `headers
|
79
|
+
If you want to modify request headers, change `headers`:
|
68
80
|
|
69
81
|
```ruby
|
70
|
-
# `subject` will be `get('/users', headers: { 'Authorization' => 'token 12345' })`.
|
71
82
|
RSpec.describe 'GET /users' do
|
72
83
|
context 'with Authorization header' do
|
73
84
|
before do
|
@@ -84,10 +95,9 @@ end
|
|
84
95
|
|
85
96
|
### params
|
86
97
|
|
87
|
-
If you want to modify request parameters, change `params
|
98
|
+
If you want to modify request parameters, change `params`:
|
88
99
|
|
89
100
|
```ruby
|
90
|
-
# `subject` will be `get('/users', params: { 'sort' => 'id' })`.
|
91
101
|
RSpec.describe 'GET /users' do
|
92
102
|
context 'with sort parameter' do
|
93
103
|
before do
|
@@ -111,10 +121,9 @@ end
|
|
111
121
|
### path parameters
|
112
122
|
|
113
123
|
You can embed variables in URL path like `/users/:user_id`.
|
114
|
-
In this example, the returned value
|
124
|
+
In this example, the returned value from `#user_id` method will be embedded as its real value.
|
115
125
|
|
116
126
|
```ruby
|
117
|
-
# `subject` will be `get("/users/#{user_id}")`.
|
118
127
|
RSpec.describe 'GET /users/:user_id' do
|
119
128
|
let(:user) do
|
120
129
|
User.create(name: 'alice')
|
data/Rakefile
CHANGED
@@ -1,7 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'rspec/request_describer/version'
|
2
4
|
|
3
5
|
module RSpec
|
4
6
|
module RequestDescriber
|
7
|
+
class IncorrectDescribe < StandardError; end
|
8
|
+
|
5
9
|
RESERVED_HEADER_NAMES = %w[
|
6
10
|
content-type
|
7
11
|
host
|
@@ -54,7 +58,7 @@ module RSpec
|
|
54
58
|
let(:env) do
|
55
59
|
headers.inject({}) do |result, (key, value)|
|
56
60
|
key = key.to_s
|
57
|
-
key =
|
61
|
+
key = "HTTP_#{key}" unless RESERVED_HEADER_NAMES.include?(key.downcase)
|
58
62
|
key = key.tr('-', '_').upcase
|
59
63
|
result.merge(key => value)
|
60
64
|
end
|
@@ -62,7 +66,10 @@ module RSpec
|
|
62
66
|
|
63
67
|
let(:endpoint_segments) do
|
64
68
|
current_example = ::RSpec.respond_to?(:current_example) ? ::RSpec.current_example : example
|
65
|
-
current_example.full_description.match(/(#{::Regexp.union(SUPPORTED_METHODS)}) (\S+)/)
|
69
|
+
match = current_example.full_description.match(/(#{::Regexp.union(SUPPORTED_METHODS)}) (\S+)/)
|
70
|
+
raise IncorrectDescribe, 'Please use the format "METHOD /path" for the describe' unless match
|
71
|
+
|
72
|
+
match.to_a
|
66
73
|
end
|
67
74
|
|
68
75
|
# @return [String] e.g. `"get"`
|
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.6.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: 2024-08-02 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email:
|
@@ -17,21 +17,14 @@ executables: []
|
|
17
17
|
extensions: []
|
18
18
|
extra_rdoc_files: []
|
19
19
|
files:
|
20
|
-
- ".github/workflows/test.yml"
|
21
|
-
- ".gitignore"
|
22
20
|
- ".rspec"
|
23
21
|
- ".rubocop.yml"
|
24
22
|
- CHANGELOG.md
|
25
|
-
- Gemfile
|
26
|
-
- Gemfile.lock
|
27
23
|
- LICENSE.txt
|
28
24
|
- README.md
|
29
25
|
- Rakefile
|
30
26
|
- lib/rspec/request_describer.rb
|
31
27
|
- lib/rspec/request_describer/version.rb
|
32
|
-
- rspec-request_describer.gemspec
|
33
|
-
- spec/rspec/request_describer_spec.rb
|
34
|
-
- spec/spec_helper.rb
|
35
28
|
homepage: https://github.com/r7kamura/rspec-request_describer
|
36
29
|
licenses:
|
37
30
|
- MIT
|
@@ -44,17 +37,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
44
37
|
requirements:
|
45
38
|
- - ">="
|
46
39
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
40
|
+
version: '2.7'
|
48
41
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
49
42
|
requirements:
|
50
43
|
- - ">="
|
51
44
|
- !ruby/object:Gem::Version
|
52
45
|
version: '0'
|
53
46
|
requirements: []
|
54
|
-
rubygems_version: 3.
|
47
|
+
rubygems_version: 3.5.11
|
55
48
|
signing_key:
|
56
49
|
specification_version: 4
|
57
50
|
summary: An RSpec plugin to write self-documenting request-specs.
|
58
|
-
test_files:
|
59
|
-
- spec/rspec/request_describer_spec.rb
|
60
|
-
- spec/spec_helper.rb
|
51
|
+
test_files: []
|
data/.github/workflows/test.yml
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
name: test
|
2
|
-
|
3
|
-
on:
|
4
|
-
pull_request:
|
5
|
-
push:
|
6
|
-
branches:
|
7
|
-
- master
|
8
|
-
|
9
|
-
jobs:
|
10
|
-
rspec:
|
11
|
-
uses: r7kamura/workflows/.github/workflows/ruby-rspec.yml@main
|
12
|
-
with:
|
13
|
-
ruby-version: 2.7.4
|
14
|
-
rubocop:
|
15
|
-
uses: r7kamura/workflows/.github/workflows/ruby-rubocop.yml@main
|
16
|
-
with:
|
17
|
-
ruby-version: 2.7.4
|
data/.gitignore
DELETED
data/Gemfile
DELETED
data/Gemfile.lock
DELETED
@@ -1,52 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
rspec-request_describer (0.4.0)
|
5
|
-
|
6
|
-
GEM
|
7
|
-
remote: https://rubygems.org/
|
8
|
-
specs:
|
9
|
-
ast (2.4.0)
|
10
|
-
diff-lcs (1.3)
|
11
|
-
jaro_winkler (1.5.1)
|
12
|
-
parallel (1.12.1)
|
13
|
-
parser (2.5.3.0)
|
14
|
-
ast (~> 2.4.0)
|
15
|
-
powerpack (0.1.2)
|
16
|
-
rainbow (3.0.0)
|
17
|
-
rake (13.0.1)
|
18
|
-
rspec (3.8.0)
|
19
|
-
rspec-core (~> 3.8.0)
|
20
|
-
rspec-expectations (~> 3.8.0)
|
21
|
-
rspec-mocks (~> 3.8.0)
|
22
|
-
rspec-core (3.8.0)
|
23
|
-
rspec-support (~> 3.8.0)
|
24
|
-
rspec-expectations (3.8.2)
|
25
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
26
|
-
rspec-support (~> 3.8.0)
|
27
|
-
rspec-mocks (3.8.0)
|
28
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
29
|
-
rspec-support (~> 3.8.0)
|
30
|
-
rspec-support (3.8.0)
|
31
|
-
rubocop (0.61.1)
|
32
|
-
jaro_winkler (~> 1.5.1)
|
33
|
-
parallel (~> 1.10)
|
34
|
-
parser (>= 2.5, != 2.5.1.1)
|
35
|
-
powerpack (~> 0.1)
|
36
|
-
rainbow (>= 2.2.2, < 4.0)
|
37
|
-
ruby-progressbar (~> 1.7)
|
38
|
-
unicode-display_width (~> 1.4.0)
|
39
|
-
ruby-progressbar (1.10.0)
|
40
|
-
unicode-display_width (1.4.0)
|
41
|
-
|
42
|
-
PLATFORMS
|
43
|
-
ruby
|
44
|
-
|
45
|
-
DEPENDENCIES
|
46
|
-
rake
|
47
|
-
rspec
|
48
|
-
rspec-request_describer!
|
49
|
-
rubocop
|
50
|
-
|
51
|
-
BUNDLED WITH
|
52
|
-
2.2.29
|
@@ -1,18 +0,0 @@
|
|
1
|
-
lib = File.expand_path('lib', __dir__)
|
2
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
-
require 'rspec/request_describer/version'
|
4
|
-
|
5
|
-
Gem::Specification.new do |spec|
|
6
|
-
spec.name = 'rspec-request_describer'
|
7
|
-
spec.version = RSpec::RequestDescriber::VERSION
|
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'
|
13
|
-
|
14
|
-
spec.files = `git ls-files -z`.split("\x0")
|
15
|
-
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
16
|
-
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
17
|
-
spec.require_paths = ['lib']
|
18
|
-
end
|
@@ -1,141 +0,0 @@
|
|
1
|
-
require 'openssl'
|
2
|
-
|
3
|
-
RSpec.describe RSpec::RequestDescriber do
|
4
|
-
include RSpec::RequestDescriber
|
5
|
-
|
6
|
-
def get(*args)
|
7
|
-
[__method__, *args]
|
8
|
-
end
|
9
|
-
|
10
|
-
describe 'GET /users' do
|
11
|
-
it 'calls #get' do
|
12
|
-
is_expected.to eq(
|
13
|
-
[
|
14
|
-
:get,
|
15
|
-
'/users',
|
16
|
-
headers: {},
|
17
|
-
params: {}
|
18
|
-
]
|
19
|
-
)
|
20
|
-
end
|
21
|
-
|
22
|
-
context 'with headers' do
|
23
|
-
let(:headers) do
|
24
|
-
super().merge('Authorization' => 'token 12345')
|
25
|
-
end
|
26
|
-
|
27
|
-
it 'calls #get with HTTP_ prefixed and upper-cased headers' do
|
28
|
-
is_expected.to eq(
|
29
|
-
[
|
30
|
-
:get,
|
31
|
-
'/users',
|
32
|
-
headers: { 'HTTP_AUTHORIZATION' => 'token 12345' },
|
33
|
-
params: {}
|
34
|
-
]
|
35
|
-
)
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
context 'with headers including reserved header name' do
|
40
|
-
let(:headers) do
|
41
|
-
super().merge('Https' => 'on')
|
42
|
-
end
|
43
|
-
|
44
|
-
it 'calls #get with headers with non HTTP_ prefixed and upper-cased headers' do
|
45
|
-
is_expected.to eq(
|
46
|
-
[
|
47
|
-
:get,
|
48
|
-
'/users',
|
49
|
-
headers: { 'HTTPS' => 'on' },
|
50
|
-
params: {}
|
51
|
-
]
|
52
|
-
)
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
context 'with symbolized keys headers' do
|
57
|
-
let(:headers) do
|
58
|
-
super().merge(AUTHORIZATION: 'token 12345')
|
59
|
-
end
|
60
|
-
|
61
|
-
it 'calls #get with HTTP_ prefixed and stringified keys headers' do
|
62
|
-
is_expected.to eq(
|
63
|
-
[
|
64
|
-
:get,
|
65
|
-
'/users',
|
66
|
-
headers: { 'HTTP_AUTHORIZATION' => 'token 12345' },
|
67
|
-
params: {}
|
68
|
-
]
|
69
|
-
)
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
context 'with headers including request body' do
|
74
|
-
before do
|
75
|
-
headers['X-Signature'] = "sha1=#{OpenSSL::HMAC.hexdigest('SHA1', 'secret', request_body.to_s)}"
|
76
|
-
end
|
77
|
-
|
78
|
-
it 'calls #get with HTTP_ prefixed and stringified keys headers' do
|
79
|
-
is_expected.to eq(
|
80
|
-
[
|
81
|
-
:get,
|
82
|
-
'/users',
|
83
|
-
headers: { 'HTTP_X_SIGNATURE' => 'sha1=5d61605c3feea9799210ddcb71307d4ba264225f' },
|
84
|
-
params: {}
|
85
|
-
]
|
86
|
-
)
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
context 'with params' do
|
91
|
-
let(:params) do
|
92
|
-
super().merge('sort' => 'id')
|
93
|
-
end
|
94
|
-
|
95
|
-
it 'calls #get with params' do
|
96
|
-
is_expected.to eq(
|
97
|
-
[
|
98
|
-
:get,
|
99
|
-
'/users',
|
100
|
-
headers: {},
|
101
|
-
params: { 'sort' => 'id' }
|
102
|
-
]
|
103
|
-
)
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
107
|
-
context 'with symbolized keys params' do
|
108
|
-
let(:params) do
|
109
|
-
super().merge(sort: 'id')
|
110
|
-
end
|
111
|
-
|
112
|
-
it 'calls #get with stringified keys params' do
|
113
|
-
is_expected.to eq(
|
114
|
-
[
|
115
|
-
:get,
|
116
|
-
'/users',
|
117
|
-
headers: {},
|
118
|
-
params: { 'sort' => 'id' }
|
119
|
-
]
|
120
|
-
)
|
121
|
-
end
|
122
|
-
end
|
123
|
-
end
|
124
|
-
|
125
|
-
describe 'GET /users/:user_id' do
|
126
|
-
let(:user_id) do
|
127
|
-
1
|
128
|
-
end
|
129
|
-
|
130
|
-
it 'calles #get with embeded variable in URL path' do
|
131
|
-
is_expected.to eq(
|
132
|
-
[
|
133
|
-
:get,
|
134
|
-
'/users/1',
|
135
|
-
headers: {},
|
136
|
-
params: {}
|
137
|
-
]
|
138
|
-
)
|
139
|
-
end
|
140
|
-
end
|
141
|
-
end
|
data/spec/spec_helper.rb
DELETED
@@ -1,21 +0,0 @@
|
|
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
|