-
-
Save thermistor/350d32db03b5555a2e68f54ef786ac68 to your computer and use it in GitHub Desktop.
Use CSS Selectors in RSpec Request Specs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def css(selector) | |
html.css(selector).text | |
end | |
def html | |
Nokogiri::HTML(response.body) | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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