jeudi 27 août 2020

RSpec Request Tests

Slightly at my wits end here. Been trying to find a simple version of using request_spec.rb to write some basic controller tests in RSpec to better understand them, however so many are either complex, written in the controller_spec which i've read is now deprecated or built for purely a rails app not a Rails API.

 RSpec.describe "Users", type: :request do
  it "request list of all users" do
    user = User.create(name: "Ben", age: 20, favourite_mums_dish: "Spaghetti")
    get("/users")
    expect(response).to be_successful
    expect(response).to have_http_status(:success)
    expect(response.body).to include("Ben")
  end
end

The last does not work with an

     Failure/Error: expect(response.body).to include("Ben")
   expected "" to include "Ben"

How would I create a basic test to simply test that this user has been created and the response contains it?

Thanks so much for your help in advance. Any documentation even would be helpful as I don't fully understand the Relish one either.

Aucun commentaire:

Enregistrer un commentaire