Last active
November 29, 2017 01:57
-
-
Save sathiyaseelan/88a92bdf477b225a80e206657ad5e18d to your computer and use it in GitHub Desktop.
Helpers for Responsive feature Specs in Capybara
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
# spec/support/feature/responsive_helpers.rb | |
module Feature | |
module ResponsiveHelpers | |
shared_context 'for mobile view', shared_context: :mobile do | |
before { resize_window_to_mobile } | |
after { resize_window_to_default } | |
end | |
shared_context 'for tablet view', shared_context: :tablet do | |
before { resize_window_to_tablet } | |
after { resize_window_to_default } | |
end | |
def resize_window_to_mobile | |
resize_window_by([375, 667]) | |
end | |
def resize_window_to_tablet | |
resize_window_by([768, 1024]) | |
end | |
def resize_window_to_default | |
resize_window_by([1280, 1024]) | |
end | |
def resize_window_by(size) | |
Capybara.current_session.driver.browser.manage.window.resize_to(size[0], size[1]) | |
end | |
end | |
end | |
RSpec.configure do |config| | |
config.include Feature::ResponsiveHelpers, type: :feature | |
config.include_context 'for mobile view', mobile: true | |
config.include_context 'for tablet view', tablet: true | |
end |
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
require 'rails_helper' | |
feature 'header is responsive', :js do | |
background { visit root_path } | |
scenario 'In desktop view, header does not display mobile components' do | |
assert_desktop_components_present | |
end | |
scenario 'In tablet view, header displays the mobile components', :tablet do | |
assert_tablet_components_present | |
end | |
scenario 'In mobile view, header displays the mobile components', :mobile do | |
assert_mobile_components_present | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment