Reputation: 83
To validated that my layout works on different screen sizes my acceptance tests actually looks like this:
require "spec_helper"
[:small, :medium, :large].each do |size|
feature "Some feature", js: true, screen_size: size do
scenario "Some scenario" do
# ...
end
end
end
In my spec helper I configued rspec to use a before(:each)
block to resize my browser window.
RSpec.configure do |config|
config.before(:each) do
if example.metadata[:js]
if example.metadata[:screen_size]
resize_browser_window(example.metadata[:screen_size])
else
resize_browser_window(:large)
end
end
end
What I actually wanted to do was something like this:
require "spec_helper"
feature "Some feature", js: true, devices: [:small, :medium, :large] do
scenario "Some scenario" do
# ...
end
end
and then use a around(:each)
block to run the scenarios for each screen size:
RSpec.configure do |config|
config.around(:each) do |example|
if example.metadata[:devices]
example.metadata[:devices].each do |size|
resize_browser_window(size)
example.run
end
end
end
end
This works just partially. The example runs for each defined device, but the window doesn't resize at all.
Does anybody have a hint for me?
Upvotes: 1
Views: 163
Reputation: 83
I found a workaround to archive the required behaviour:
RSpec.configure do |config|
config.around(:each) do |example|
if example.metadata[:devices]
example.metadata[:devices].each do |size|
example.metadata[:screen_size] = size
example.run
end
end
end
config.before(:each) do
if example.metadata[:js]
if example.metadata[:screen_size]
resize_browser_window(example.metadata[:screen_size])
end
end
end
end
Upvotes: 1