Last active
August 29, 2015 14:08
-
-
Save IdahoEv/6be0a2b1dd55b75474fa to your computer and use it in GitHub Desktop.
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
| #backend/spec/support/browser_size.rb | |
| # note, our Rails app is not in the repo root. We have: | |
| # <root>/backend (Rails back-end app) | |
| # <root>/frontend (AngularJS front-end SPA) | |
| module BrowserSize | |
| SIZES = { | |
| :mobile => { :width => 320, :height => 480 }, | |
| :small => { :width => 550, :height => 700 }, | |
| :medium => { :width => 800, :height => 900 }, | |
| :desktop => { :width => 1024, :height => 1024 } | |
| } | |
| RSpec.configure do |config| | |
| config.before(:each) do | |
| if RSpec.current_example.metadata[:js] | |
| BrowserSize.resize_browser_window(SIZES[BrowserSize.current_size]) | |
| end | |
| end | |
| end | |
| def self.resize_browser_window(size) | |
| Capybara.current_session.driver.browser.manage.window.resize_to(size[:width], size[:height]) | |
| end | |
| def self.current_size | |
| (RSpec.current_example.metadata[:size] || ENV['BROWSER_SIZE'] || :desktop).to_sym | |
| end | |
| end | |
| RSpec.configure do |config| | |
| config.include BrowserSize, :type => :feature | |
| 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
| namespace :spec do | |
| # ... other stuff ... | |
| desc "Run all feature specs, repeating with each browser width as default" | |
| task :responsivity, [:spec_files] => [:links, 'backend:setup'] do |t, args| | |
| Bundler.with_clean_env do | |
| %w{mobile small medium desktop}.each do |size| | |
| Dir.chdir("backend"){ | |
| ENV['BROWSER_SIZE']=size | |
| commands = ["bundle", "exec", "rspec", "-o", "tmp/rspec_#{size}.txt"] | |
| if args[:spec_files] | |
| commands.push(args[:spec_files]) | |
| else | |
| commands.push('spec/features') | |
| end | |
| sh *commands rescue true | |
| } | |
| end | |
| end | |
| end | |
| 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
| #backend/spec/support/session_helpers.rb | |
| module Features | |
| module SessionHelpers | |
| COLLAPSED_MENU_SIZES=[ :mobile, :small ] | |
| def visit_login | |
| visit '/' | |
| expand_menu_if_necessary | |
| within ".session-links" do | |
| click_link "Sign In" | |
| end | |
| end | |
| def expand_menu_if_necessary | |
| # On pages with collapsed menu, click to expand the menu | |
| # before trying to click the sign-in link. I'm doing it this | |
| # way instead of inspecting the page for .session-links because | |
| # the latter triggers a capybara wait, which is much slower. | |
| if COLLAPSED_MENU_SIZES.include?(BrowserSize.current_size) | |
| click_on('Menu') | |
| end | |
| end | |
| def sign_up_with(email, password) | |
| visit '/' | |
| expand_menu_if_necessary | |
| click_on "Sign Up" | |
| fill_in "Email", :with => email | |
| fill_in "Email Confirmation", :with => email | |
| fill_in "Password", :with => password | |
| fill_in "Password Confirmation", :with => password | |
| click_button "Sign Up" | |
| end | |
| def sign_in_with(email, password) | |
| visit_login | |
| fill_in "Email", :with => email | |
| fill_in "Password", :with => password | |
| click_button "Sign In" | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment