README.md in rspec-request_describer-0.3.2 vs README.md in rspec-request_describer-0.4.0
- old
+ new
@@ -1,8 +1,8 @@
# RSpec::RequestDescriber
-[![CircleCI](https://circleci.com/gh/r7kamura/rspec-request_describer.svg?style=svg)](https://circleci.com/gh/r7kamura/rspec-request_describer)
+[![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)
[![Gem Version](https://badge.fury.io/rb/rspec-request_describer.svg)](https://rubygems.org/gems/rspec-request_describer)
An RSpec plugin to write self-documenting request-specs.
This gem is designed for:
@@ -37,23 +37,30 @@
Include `RSpec::RequestDescriber` to your example groups like this:
```ruby
require 'rspec/request_describer'
-RSpec.configuration.include RSpec::RequestDescriber, type: :request
+RSpec.configure do |config|
+ config.include RSpec::RequestDescriber, type: :request
+end
```
## Usage
+Note that this is an example in a Rails app.
+
### subject
`RSpec::RequestDescriber` provides `subject` from its top-level description.
```ruby
# subject will be `get('/users')`.
RSpec.describe 'GET /users' do
- it { is_expected.to eq(200) }
+ it 'returns 200' do
+ subject
+ expect(response).to have_http_status(200)
+ end
end
```
### headers
@@ -64,11 +71,15 @@
RSpec.describe 'GET /users' do
context 'with Authorization header' do
before do
headers['Authorization'] = 'token 12345'
end
- it { is_expected.to eq(200) }
+
+ it 'returns 200' do
+ subject
+ expect(response).to have_http_status(200)
+ end
end
end
```
### params
@@ -81,25 +92,28 @@
context 'with sort parameter' do
before do
params['sort'] = 'id'
end
- it 'returns users in ID order' do
- is_expected.to eq(200)
-
- users = JSON.parse(response.body)
- expect(users[0]['id']).to eq(1)
- expect(users[1]['id']).to eq(2)
+ it 'returns 200 with expected JSON body' do
+ subject
+ expect(response).to have_http_status(200)
+ expect(response.parsed_body).to match(
+ [
+ hash_including('id' => 1),
+ hash_including('id' => 2),
+ ]
+ )
end
end
end
```
-### variables in URL path
+### path parameters
-You can embed variables in URL path like `/users/:id`.
-In this example, the returned value of `id` method will be emobeded as its real value.
+You can embed variables in URL path like `/users/:user_id`.
+In this example, the returned value of `user_id` method will be emobeded as its real value.
```ruby
# `subject` will be `get("/users/#{user_id}")`.
RSpec.describe 'GET /users/:user_id' do
let(:user) do
@@ -108,8 +122,11 @@
let(:user_id) do
user.id
end
- it { is_expected.to eq(200) }
+ it 'returns 200' do
+ subject
+ expect(response).to have_http_status(200)
+ end
end
```