I have the following code, which was automagically created, in ~/controllers/articles_controller_spec.rb
describe “GET #new” do
it “returns a success response” do
# See Hassan’s answer in
# Redirecting to Google Groups
byebug
get :new, params: {}, session: valid_session
byebug
expect(response).to be_success
end
end
``
I see the following in STDOUT
something@something:~$ date
Thu Jul 13 15:14:33 MDT 2017
something@something:~$ rspec
. . .
[72, 81] in /home/real-estate-data-mining/spec/controllers/articles_controller_spec.rb
72: # get :new # , params: {}, session: valid_session
73: byebug
74: get :new, params: {}, session: valid_session
75: # get :new, params: {}, session: {valid_session}
76: byebug
=> 77: expect(response).to be_success
78: end
79: end
80: end
81:
(byebug) response.status
302
``
Why am I getting a 302 rather than a 200?
Question 2: Shouldn’t 302 be a type of success?
I have the following code, which was automagically created, in ~/controllers/articles_controller_spec.rb
describe "GET #new" do
it "returns a success response" do
# See Hassan's answer in
# Redirecting to Google Groups
byebug
get :new, params: {}, session: valid_session
byebug
expect(response).to be_success
end
end
I see the following in STDOUT
something@something:~$ date
Thu Jul 13 15:14:33 MDT 2017
something@something:~$ rspec
. . .
[72, 81] in /home/real-estate-data-mining/spec/controllers/articles_controller_spec.rb
72: # get :new # , params: {}, session: valid_session
73: byebug
74: get :new, params: {}, session: valid_session
75: # get :new, params: {}, session: {valid_session}
76: byebug
=> 77: expect(response).to be_success
78: end
79: end
80: end
81:
(byebug) response.status
302
Why am I getting a 302 rather than a 200?
Something in your controller code is redirecting - can't really say without seeing that code
Question 2: Shouldn't 302 be a type of success?
The http standard places responses into 5 groups:
- informational (100)
- success (200)
- redirections (300)
- client error (400)
- server error (500)
So a 302 response is not a successful response by definition (of course from a user point of view this is not always the case: for validation errors rails often renders an error page (so a 200 response) whereas a successful create/edit is normally a redirect.
See HTTP response status codes - HTTP | MDN for example.
Fred