Skip to content

Instantly share code, notes, and snippets.

@brenes
Created December 27, 2013 10:38
Show Gist options
  • Select an option

  • Save brenes/8145252 to your computer and use it in GitHub Desktop.

Select an option

Save brenes/8145252 to your computer and use it in GitHub Desktop.
Responsive Describe module for running request specs under different resolutions with poltergeist
# This module allows you to run your request specs in a responsive mode quite easily
#
# Requirement: It requries Poltergeist, but could work with any capybara driver with a resize method
#
# Instructions:
#
# 0. Setup Poltergeist and register the driver
# 1. Drop this module in your spec/support folder
# 2. Include this module before your describe
# 3. Use a responsive: true param in describe to enable responsive requests. We will need a js:true to enable poltergeist
#
# Example:
#
### include ResponsiveDescribe
###
### describe "Academic Filter", js: true, responsive: true do
### ...
### end
#
# It will duplicate your describe with a [Responsive] in the description
#
module ResponsiveDescribe
def self.included klass
klass.module_eval do
def self.describe(*args, &example_group_block)
options = args.extract_options!
item_args = args.collect(&:dup) + [options.dup]
item_args.delete(:responsive)
if options.delete(:responsive)
responsive_item_args = args.collect(&:dup) + [options.dup]
responsive_item_args[0] << " [Responsive]"
super(*responsive_item_args) do
class_exec do
before :each do
page.driver.resize(480, 800)
end
after :each do
page.driver.resize(1024, 768)
end
end
class_exec(&example_group_block)
end
end
super(*item_args) do
class_exec(&example_group_block)
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment