Created
January 11, 2021 08:03
-
-
Save mathewtrivett/c17fe33ab10e94184d21fef7145f9446 to your computer and use it in GitHub Desktop.
Testing Print CSS - spec/features/print_styles.rb
This file contains 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
# Capybara is designed to test visible HTML elements, i.e. your user interface. | |
# The link tags used for stylesheets are not visible to Capybara by default. | |
# We need to pass visible: false to `have_selector` to tell Capybara the link element is not visible. | |
RSpec.describe 'Print CSS', type: :feature do | |
context 'with params[:medium] == "print"' do | |
it 'loads the print stylesheet with the media=screen' do | |
is_expected.to have_selector( | |
'link[id="print_styles"][media="screen"]', | |
visible: false | |
) | |
end | |
it 'does not load our other stylesheets' do | |
# write tests to check your other stylesheets do not load | |
end | |
end | |
context 'without params[:medium] == "print"' do | |
it 'does not load the print stylesheet with media=screen' do | |
is_expected.not_to have_selector( | |
'link[id="print_styles"][media="screen"]', | |
visible: false | |
) | |
end | |
it 'loads the print stylesheet with media=print' do | |
is_expected.to have_selector( | |
'link[id="print_styles"][media="print"]' | |
visible: false | |
) | |
end | |
it 'loads our other stylesheets' do | |
# Test your other stylesheets load correctly here | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment