Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kenchan/rspec-default_http_header
https://github.com/kenchan/rspec-default_http_header
Last synced: 3 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/kenchan/rspec-default_http_header
- Owner: kenchan
- License: mit
- Created: 2014-12-04T07:29:31.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2021-10-21T16:01:06.000Z (about 3 years ago)
- Last Synced: 2024-04-24T15:23:56.846Z (9 months ago)
- Language: Ruby
- Size: 13.7 KB
- Stars: 15
- Watchers: 3
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# RSpec::DefaultHttpHeader
Set default http headers in request specs.
## Installation
Add this line to your application's Gemfile:
```ruby
gem 'rspec-default_http_header'
```And then execute:
$ bundle
Or install it yourself as:
$ gem install rspec-default_http_header
## Setup
Include RSpec::DefaultHeader into your RSpec.configuration.
```ruby
RSpec.configure do |config|
config.include RSpec::DefaultHttpHeader, type: :request
end
```## Usage
### let(:default_headers)
```ruby
RSpec.describe 'GET /api/users.json' do
context 'with authorization headers' do
let(:default_headers) { {Authorization: 'your-authorization-token'} }before do
get '/api/users.json'
endit { expect(response).to be_success}
end
end
```### modify default_headers hash
```ruby
RSpec.describe 'GET /api/users.json' do
context 'with authorization headers' do
before do
default_headers[:Authorization] = 'your-authorization-token'get '/api/users.json'
endit { expect(response).to be_success}
end
end
```### set in a batch to tests using the tag
```ruby
RSpec.configure do |config|
config.before(:example, type: :request, authorized: true) do
default_headers[:Authorization] = 'your-authorization-token'
end
endRSpec.describe 'GET /api/users.json' do
context 'with authorization headers', :authorized do
before do
get '/api/users.json'
endit { expect(response).to be_success}
end
end
```## Contributing
1. Fork it ( https://github.com/kenchan/rspec-default_http_header/fork )
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create a new Pull Request