I found lots of similar questions posted by others but none of the solutions worked.
My /spec/requests/questions_spec.rb is
require 'rails_helper'
RSpec.describe "Questions", type: :request do
describe "GET /questions" do
it "works! (now write some real specs)" do
get questions_path
expect(response).to have_http_status(200)
end
end
end
Now my rspec error
Questions GET /questions works! (now write some real specs)
Failure/Error: expect(response).to have_http_status(200)
expected the response to have status code 200 but it was 302
# ./spec/requests/questions_spec.rb:7:in `block (3 levels) in <top (required)>'
Can anyone help me? How do I customize my code to get the status code 200 ?
A 200 status code is the most popular code sent by servers on the Internet. If a site sends this response, it means the response is a success. For example, let’s assume that you landed on this very page. Our server responded with an HTTP status code 200. The server found the resource (this page), and everything was a success.
Status codes let us know whether the HTTP request was a success, a failure, or something in between. Some status codes are more common than others. For example, when you're doing digital marketing, you'll often come across status code 200, status code 301 and status code 404 - but you may never see status code 206 or 307.
You would usually only see this response when you're using a digital marketing tool that shows you the status code specifically. In general, you want to see 200 requests. They are good! Let's talk about how the HTTP protocol works. At its very foundation, the Internet is made up of two core things: clients and servers.
That means something went wrong with the response (website/server) and not the request (client/user). They include: Looking for more on a particular status code? We have a series of short guides on every HTTP response, so you can optimize your digital marketing strategy.
302 - Found
. I think you are using rails scaffold. Scaffold syntax return 302 status on get method. If you need 200. Youcan customize your code.
I think you are missing authentication.
use login_user
https://github.com/heartcombo/devise/wiki/How-To:-Test-controllers-with-Rails-(and-RSpec)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With