Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/uiur/rspec-request-printer
prints json api response as pretty format in request spec
https://github.com/uiur/rspec-request-printer
Last synced: about 1 month ago
JSON representation
prints json api response as pretty format in request spec
- Host: GitHub
- URL: https://github.com/uiur/rspec-request-printer
- Owner: uiur
- License: mit
- Created: 2021-01-20T10:29:48.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2021-04-28T12:21:25.000Z (over 3 years ago)
- Last Synced: 2024-10-12T19:30:59.249Z (3 months ago)
- Language: Ruby
- Homepage:
- Size: 10.7 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# rspec-request-printer
`rspec-request-printer` prints response of JSON API as pretty format when running request specs.
It prints a summary of a request like this format:
```ruby
$ RSPEC_REQUEST_PRINTER=1 bundle exec rspec spec/requests/menus_spec.rb
...
GET http://example.com/menus/72e1c777-547e-450d-ad83-0bf70e5786ca
{}{
"id": "72e1c777-547e-450d-ad83-0bf70e5786ca",
"name": "foobar",
"status": "published",
"created_at": "2021-04-05T18:30:49+09:00"
}
```It's helpful for cases like:
- Check the response body with your eyes when you write JSON API
- Copy it as an example of API response and paste it in a pull request to explain to others## Usage
Run rspec with `RSPEC_REQUEST_PRINTER=1`.
```ruby
$ RSPEC_REQUEST_PRINTER=1 bundle exec rspec spec/requests/menus_spec.rb
GET http://example.com/menus/72e1c777-547e-450d-ad83-0bf70e5786ca
{}{
"id": "72e1c777-547e-450d-ad83-0bf70e5786ca",
"name": "foobar",
"status": "published",
"created_at": "2021-04-05T18:30:49+09:00"
}
```With `dotenv`, you can set `RSPEC_REQUEST_PRINTER=1` in `.env.test` file.
## Installation
Add this line to your application's Gemfile:
```ruby
gem 'rspec-request-printer', github: 'uiur/rspec-request-printer'
```And then execute:
$ bundle install
Or install it yourself as:
$ gem install rspec-request-printer
## License
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).