So I'm working on my first Rails project and am working on getting some automated testing set up. Right now, I have a template for a form which has a select
tag, which is getting its information dynamically based on a mocked API response. As of now, my template successfully renders, but I would like to be able to access that select
tag and see if its child options
match with the my mock API response. Haven't been able to find a whole lot in the docs about this particular use case, hoping someone here may be able to point me in the right direction. Here's essentially what I have so far:
RSpec.describe MyController, type: :controller, do
describe "GET my_thing/index" do
it "renders the index template" do
stub_request(:get, "https://outsideapi.net/endpoint").
to_return(status: 200,
body: {
"values" => [
{ "name": "foo", "id": "10000" },
{ "name": "bar", "id": "10001" },
{ "name": "baz", "id": "10002" },
],
}.to_json,
headers: {})
get :index, params: { request_identifier: generate_request_identifier() }
expect(response).to have_http_status(:success)
expect(response).to render_template(:index)
# Some code that will hopefully get elements off the template
end
end