forked from rspec/rspec-rails
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathheaders.feature
50 lines (40 loc) · 1.32 KB
/
headers.feature
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
Feature: Headers
We recommend you to switch to request spec instead of controller spec
if you want to set headers in your call.
If you still want to set headers in controller spec, you can use
`request.headers` as mentioned bellow.
Scenario: Set header's value in controller spec
Given a file named "spec/controllers/application_controller_spec.rb" with:
"""ruby
require "rails_helper"
RSpec.describe ApplicationController, :type => :controller do
controller do
def show
if request.headers["Authorization"] == "foo"
head :ok
else
head :forbidden
end
end
end
before do
routes.draw { get "show" => "anonymous#show" }
end
context "valid Authorization header" do
it "returns a 200" do
request.headers["Authorization"] = "foo"
get :show
expect(response).to have_http_status(:ok)
end
end
context "invalid Authorization header" do
it "returns a 403" do
request.headers["Authorization"] = "bar"
get :show
expect(response).to have_http_status(:forbidden)
end
end
end
"""
When I run `rspec spec`
Then the example should pass