Skip to content

Instantly share code, notes, and snippets.

@dsisnero
Forked from dogweather/request_helpers.rb
Created October 12, 2023 11:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dsisnero/21f995d87b00a9992a0275e494413bda to your computer and use it in GitHub Desktop.
Save dsisnero/21f995d87b00a9992a0275e494413bda to your computer and use it in GitHub Desktop.
Use CSS Selectors in RSpec Request Specs
def css(selector)
html.css(selector).text
end
def html
Nokogiri::HTML(response.body)
end
# How to use the above helpers.
RSpec.describe 'Test some page', type: :request do
it 'has a <p> with "Title"' do
get '/my-page'
expect( css 'p' ).to include 'Title'
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment