From 18dba79bf27a370c823b34380120bff49cec08e2 Mon Sep 17 00:00:00 2001 From: Pierre Hedkvist Date: Mon, 27 Nov 2017 12:24:29 +0000 Subject: Example of mobile configuration for system test in guide [ci skip] --- guides/source/testing.md | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'guides/source/testing.md') diff --git a/guides/source/testing.md b/guides/source/testing.md index e0a2d281d9..d9227f3c0a 100644 --- a/guides/source/testing.md +++ b/guides/source/testing.md @@ -778,6 +778,34 @@ send a POST request to create the new article in the database. We will be redirected back to the the articles index page and there we assert that the text from the new article's title is on the articles index page. +#### Testing for multiple screen sizes +If you want to test for mobile sizes on top of testing for desktop, +you can create another class that inherits from SystemTestCase and use in your +test suite. In this example a file called `mobile_system_test_case.rb` is created +in the `/test` directory with the following configuration. + +```ruby +require "test_helper" + +class MobileSystemTestCase < ActionDispatch::SystemTestCase + driven_by :selenium, using: :chrome, screen_size: [375, 667] +end +``` +To use this configuration, create a test inside `test/system` that inherits from `MobileSystemTestCase`. +Now you can test your app using multiple different configurations. + +```ruby +require "mobile_system_test_case" + +class PostsTest < MobileSystemTestCase + + test "visiting the index" do + visit posts_url + assert_selector "h1", text: "Posts" + end +end +``` + #### Taking it further The beauty of system testing is that it is similar to integration testing in -- cgit v1.2.3