backported_system_tests 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7b8032f1e61ddf84a6fdf8c7459bc607b45a11d9
4
+ data.tar.gz: 3ed7c725c080ede6e4a0866b05ac833a5bdf88fc
5
+ SHA512:
6
+ metadata.gz: 656b682231d4f725cabb1b19c38bb1b21f501df8d93746a6b4ce2e895fc8d0ee7db3c88a0f090fdb3ce3590f6cced3638b07c90ec7e998f2bf92b7f334ec43fb
7
+ data.tar.gz: 4818e44b9de00673a3a4a4068b88cfc63893f123bff2016febccfeee5dd82a64dea3e155439ed14ae24b702867849e631de65641e092b86917637d28c5826578
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.3
5
+ before_install: gem install bundler -v 1.16.0
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at andrew@zerlex.net. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in backported_system_tests.gemspec
6
+ gemspec
@@ -0,0 +1,120 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ backported_system_tests (0.1.0)
5
+ rails (>= 5.0.6)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ actioncable (5.1.4)
11
+ actionpack (= 5.1.4)
12
+ nio4r (~> 2.0)
13
+ websocket-driver (~> 0.6.1)
14
+ actionmailer (5.1.4)
15
+ actionpack (= 5.1.4)
16
+ actionview (= 5.1.4)
17
+ activejob (= 5.1.4)
18
+ mail (~> 2.5, >= 2.5.4)
19
+ rails-dom-testing (~> 2.0)
20
+ actionpack (5.1.4)
21
+ actionview (= 5.1.4)
22
+ activesupport (= 5.1.4)
23
+ rack (~> 2.0)
24
+ rack-test (>= 0.6.3)
25
+ rails-dom-testing (~> 2.0)
26
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
27
+ actionview (5.1.4)
28
+ activesupport (= 5.1.4)
29
+ builder (~> 3.1)
30
+ erubi (~> 1.4)
31
+ rails-dom-testing (~> 2.0)
32
+ rails-html-sanitizer (~> 1.0, >= 1.0.3)
33
+ activejob (5.1.4)
34
+ activesupport (= 5.1.4)
35
+ globalid (>= 0.3.6)
36
+ activemodel (5.1.4)
37
+ activesupport (= 5.1.4)
38
+ activerecord (5.1.4)
39
+ activemodel (= 5.1.4)
40
+ activesupport (= 5.1.4)
41
+ arel (~> 8.0)
42
+ activesupport (5.1.4)
43
+ concurrent-ruby (~> 1.0, >= 1.0.2)
44
+ i18n (~> 0.7)
45
+ minitest (~> 5.1)
46
+ tzinfo (~> 1.1)
47
+ arel (8.0.0)
48
+ builder (3.2.3)
49
+ concurrent-ruby (1.0.5)
50
+ crass (1.0.3)
51
+ erubi (1.7.0)
52
+ globalid (0.4.1)
53
+ activesupport (>= 4.2.0)
54
+ i18n (0.9.1)
55
+ concurrent-ruby (~> 1.0)
56
+ loofah (2.1.1)
57
+ crass (~> 1.0.2)
58
+ nokogiri (>= 1.5.9)
59
+ mail (2.7.0)
60
+ mini_mime (>= 0.1.1)
61
+ method_source (0.9.0)
62
+ mini_mime (1.0.0)
63
+ mini_portile2 (2.3.0)
64
+ minitest (5.11.1)
65
+ nio4r (2.2.0)
66
+ nokogiri (1.8.1)
67
+ mini_portile2 (~> 2.3.0)
68
+ rack (2.0.3)
69
+ rack-test (0.8.2)
70
+ rack (>= 1.0, < 3)
71
+ rails (5.1.4)
72
+ actioncable (= 5.1.4)
73
+ actionmailer (= 5.1.4)
74
+ actionpack (= 5.1.4)
75
+ actionview (= 5.1.4)
76
+ activejob (= 5.1.4)
77
+ activemodel (= 5.1.4)
78
+ activerecord (= 5.1.4)
79
+ activesupport (= 5.1.4)
80
+ bundler (>= 1.3.0)
81
+ railties (= 5.1.4)
82
+ sprockets-rails (>= 2.0.0)
83
+ rails-dom-testing (2.0.3)
84
+ activesupport (>= 4.2.0)
85
+ nokogiri (>= 1.6)
86
+ rails-html-sanitizer (1.0.3)
87
+ loofah (~> 2.0)
88
+ railties (5.1.4)
89
+ actionpack (= 5.1.4)
90
+ activesupport (= 5.1.4)
91
+ method_source
92
+ rake (>= 0.8.7)
93
+ thor (>= 0.18.1, < 2.0)
94
+ rake (10.5.0)
95
+ sprockets (3.7.1)
96
+ concurrent-ruby (~> 1.0)
97
+ rack (> 1, < 3)
98
+ sprockets-rails (3.2.1)
99
+ actionpack (>= 4.0)
100
+ activesupport (>= 4.0)
101
+ sprockets (>= 3.0.0)
102
+ thor (0.20.0)
103
+ thread_safe (0.3.6)
104
+ tzinfo (1.2.4)
105
+ thread_safe (~> 0.1)
106
+ websocket-driver (0.6.5)
107
+ websocket-extensions (>= 0.1.0)
108
+ websocket-extensions (0.1.3)
109
+
110
+ PLATFORMS
111
+ ruby
112
+
113
+ DEPENDENCIES
114
+ backported_system_tests!
115
+ bundler (~> 1.16)
116
+ minitest (~> 5.0)
117
+ rake (~> 10.0)
118
+
119
+ BUNDLED WITH
120
+ 1.16.0
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Andrew Fomera
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,77 @@
1
+ # Back-ported System Tests
2
+
3
+ In 2017, the company I work for wanted System Tests, but with 5.1 released we knew it would be a while before we could upgrade to Rails 5.1, because we were stuck on Rails 4.2. After working for a year, we are now running Rails 5, but wanted to ease the upgrade path for Rails 5.1 and still get the benefits of system tests.
4
+
5
+ But all the credit for this code should go to the Rails contributors, I didn't have to write any code to make this work. If any Rails contributors have an issue with this gem, please let me know on Twitter: [@AndrewFomera](https://twitter.com/AndrewFomera). I spoke with [eileencodes](https://github.com/eileencodes) at RubyConf 2017 in passing asking if it'd be okay to backport this, but if anyone has any issues let me know, happy to take it down.
6
+
7
+ ## Table of contents
8
+
9
+ - [Credits](#credits)
10
+ - [Installation](#installation)
11
+ - [Configuration](#configuration)
12
+ - [Developing](#developing)
13
+ - [License](#license)
14
+
15
+
16
+ ## Credits
17
+
18
+ Credit goes to all of the Rails Contributors that built the System Testing for Rails 5.1+.
19
+
20
+
21
+ ## Installation
22
+
23
+ Add to your Gemfile:
24
+
25
+ ```ruby
26
+ gem 'backported_system_tests'
27
+
28
+ # Ensure gem 'selenium-webdriver' is also in your Gemfile
29
+ # if using the selenium drivers.
30
+ ```
31
+
32
+ Create `test/application_system_test_case.rb`
33
+
34
+ ```ruby
35
+ require 'test_helper'
36
+
37
+ class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
38
+ driven_by :selenium, using: :chrome, screen_size: [1400, 1400]
39
+ # Or you can change it to be using: :headless_chrome for headless chrome
40
+ end
41
+ ```
42
+
43
+ Modify your application Rakefile for a `rails test:system` command.
44
+
45
+ **Rakefile**
46
+ ```ruby
47
+ namespace :test do
48
+ desc "Run only the tests in the `test/system` directory"
49
+ task :system => "test:prepare" do
50
+ $: << "test"
51
+ Rails::TestUnit::Runner.run(["test/system"])
52
+ end
53
+ end
54
+ ```
55
+
56
+ We also recommend creating another rake task for running your other tests, but will leave the implementation up to you.
57
+
58
+ **Note: This does not include the ActiveRecord changes, we recommend running your non-system tests in a separate process**
59
+
60
+ ## Configuration
61
+
62
+ You should get all of the features of the adapters from Rails 5.1+, so you can switch out your adapters per the [Rails docs](http://api.rubyonrails.org/v5.1/classes/ActionDispatch/SystemTestCase.html).
63
+
64
+ Check the docs for more help, or open an issue :)
65
+
66
+ ## Developing
67
+
68
+ 1. Thank you! We love [our contributors](https://github.com/king601/backported_system_tests/graphs/contributors)!
69
+ 1. Clone the repository.
70
+ 1. Make your changes in a thoughtfully-named branch.
71
+ 1. Ensure 1:1 test coverage.
72
+ 1. Submit a [Pull Request](https://github.com/king601/backported_system_tests/pulls)!
73
+ 1. Celebrate! :tada:
74
+
75
+ ## License
76
+
77
+ This project uses MIT-LICENSE.
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList["test/**/*_test.rb"]
8
+ end
9
+
10
+ task :default => :test
@@ -0,0 +1,31 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "backported_system_tests"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "backported_system_tests"
8
+ spec.version = BackportedSystemTests::VERSION
9
+ spec.authors = ["Andrew Fomera"]
10
+ spec.email = ["andrew@zerlex.net"]
11
+
12
+ spec.summary = %q{Backport of the Rails 5.1 System Tests to work in Rails 5.}
13
+ spec.description = %q{This gem backports the work the great contributors of
14
+ Rails have done for getting System Tests on Rails 5.1. This helps to ease the upgrade
15
+ path for applications that are larger.}
16
+ spec.homepage = "https://github.com/king601/backported_system_tests"
17
+ spec.license = "MIT"
18
+
19
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
20
+ f.match(%r{^(test|spec|features)/})
21
+ end
22
+ spec.bindir = "exe"
23
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
+ spec.require_paths = ["lib"]
25
+
26
+ spec.add_dependency "rails", ">= 5.0.6"
27
+
28
+ spec.add_development_dependency "bundler", "~> 1.16"
29
+ spec.add_development_dependency "rake", "~> 10.0"
30
+ spec.add_development_dependency "minitest", "~> 5.0"
31
+ end
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "backported_system_tests"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,146 @@
1
+ # frozen_string_literal: true
2
+ gem "capybara", "~> 2.15"
3
+
4
+ require "capybara/dsl"
5
+ require "capybara/minitest"
6
+ require "action_controller"
7
+ require "action_dispatch/system_testing/driver"
8
+ require "action_dispatch/system_testing/browser"
9
+ require "action_dispatch/system_testing/server"
10
+ require "action_dispatch/system_testing/test_helpers/screenshot_helper"
11
+ require "action_dispatch/system_testing/test_helpers/setup_and_teardown"
12
+ require "action_dispatch/system_testing/test_helpers/undef_methods"
13
+
14
+ module ActionDispatch
15
+ # = System Testing
16
+ #
17
+ # System tests let you test applications in the browser. Because system
18
+ # tests use a real browser experience, you can test all of your JavaScript
19
+ # easily from your test suite.
20
+ #
21
+ # To create a system test in your application, extend your test class
22
+ # from <tt>ApplicationSystemTestCase</tt>. System tests use Capybara as a
23
+ # base and allow you to configure the settings through your
24
+ # <tt>application_system_test_case.rb</tt> file that is generated with a new
25
+ # application or scaffold.
26
+ #
27
+ # Here is an example system test:
28
+ #
29
+ # require 'application_system_test_case'
30
+ #
31
+ # class Users::CreateTest < ApplicationSystemTestCase
32
+ # test "adding a new user" do
33
+ # visit users_path
34
+ # click_on 'New User'
35
+ #
36
+ # fill_in 'Name', with: 'Arya'
37
+ # click_on 'Create User'
38
+ #
39
+ # assert_text 'Arya'
40
+ # end
41
+ # end
42
+ #
43
+ # When generating an application or scaffold, an +application_system_test_case.rb+
44
+ # file will also be generated containing the base class for system testing.
45
+ # This is where you can change the driver, add Capybara settings, and other
46
+ # configuration for your system tests.
47
+ #
48
+ # require "test_helper"
49
+ #
50
+ # class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
51
+ # driven_by :selenium, using: :chrome, screen_size: [1400, 1400]
52
+ # end
53
+ #
54
+ # By default, <tt>ActionDispatch::SystemTestCase</tt> is driven by the
55
+ # Selenium driver, with the Chrome browser, and a browser size of 1400x1400.
56
+ #
57
+ # Changing the driver configuration options is easy. Let's say you want to use
58
+ # the Firefox browser instead of Chrome. In your +application_system_test_case.rb+
59
+ # file add the following:
60
+ #
61
+ # require "test_helper"
62
+ #
63
+ # class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
64
+ # driven_by :selenium, using: :firefox
65
+ # end
66
+ #
67
+ # +driven_by+ has a required argument for the driver name. The keyword
68
+ # arguments are +:using+ for the browser and +:screen_size+ to change the
69
+ # size of the browser screen. These two options are not applicable for
70
+ # headless drivers and will be silently ignored if passed.
71
+ #
72
+ # Headless browsers such as headless Chrome and headless Firefox are also supported.
73
+ # You can use these browsers by setting the +:using+ argument to +:headless_chrome+ or +:headless_firefox+.
74
+ #
75
+ # To use a headless driver, like Poltergeist, update your Gemfile to use
76
+ # Poltergeist instead of Selenium and then declare the driver name in the
77
+ # +application_system_test_case.rb+ file. In this case, you would leave out
78
+ # the +:using+ option because the driver is headless, but you can still use
79
+ # +:screen_size+ to change the size of the browser screen, also you can use
80
+ # +:options+ to pass options supported by the driver. Please refer to your
81
+ # driver documentation to learn about supported options.
82
+ #
83
+ # require "test_helper"
84
+ # require "capybara/poltergeist"
85
+ #
86
+ # class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
87
+ # driven_by :poltergeist, screen_size: [1400, 1400], options:
88
+ # { js_errors: true }
89
+ # end
90
+ #
91
+ # Because <tt>ActionDispatch::SystemTestCase</tt> is a shim between Capybara
92
+ # and Rails, any driver that is supported by Capybara is supported by system
93
+ # tests as long as you include the required gems and files.
94
+ class SystemTestCase < IntegrationTest
95
+ include Capybara::DSL
96
+ include Capybara::Minitest::Assertions
97
+ include SystemTesting::TestHelpers::SetupAndTeardown
98
+ include SystemTesting::TestHelpers::ScreenshotHelper
99
+ include SystemTesting::TestHelpers::UndefMethods
100
+
101
+ def initialize(*) # :nodoc:
102
+ super
103
+ self.class.driver.use
104
+ end
105
+
106
+ def self.start_application # :nodoc:
107
+ Capybara.app = Rack::Builder.new do
108
+ map "/" do
109
+ run Rails.application
110
+ end
111
+ end
112
+
113
+ SystemTesting::Server.new.run
114
+ end
115
+
116
+ class_attribute :driver, instance_accessor: false
117
+
118
+ # System Test configuration options
119
+ #
120
+ # The default settings are Selenium, using Chrome, with a screen size
121
+ # of 1400x1400.
122
+ #
123
+ # Examples:
124
+ #
125
+ # driven_by :poltergeist
126
+ #
127
+ # driven_by :selenium, screen_size: [800, 800]
128
+ #
129
+ # driven_by :selenium, using: :chrome
130
+ #
131
+ # driven_by :selenium, using: :headless_chrome
132
+ #
133
+ # driven_by :selenium, using: :firefox
134
+ #
135
+ # driven_by :selenium, using: :headless_firefox
136
+ def self.driven_by(driver, using: :chrome, screen_size: [1400, 1400], options: {})
137
+ self.driver = SystemTesting::Driver.new(driver, using: using, screen_size: screen_size, options: options)
138
+ end
139
+
140
+ driven_by :selenium
141
+
142
+ ActiveSupport.run_load_hooks(:action_dispatch_system_test_case, self)
143
+ end
144
+
145
+ SystemTestCase.start_application
146
+ end
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActionDispatch
4
+ module SystemTesting
5
+ class Browser # :nodoc:
6
+ attr_reader :name
7
+
8
+ def initialize(name)
9
+ @name = name
10
+ end
11
+
12
+ def type
13
+ case name
14
+ when :headless_chrome
15
+ :chrome
16
+ when :headless_firefox
17
+ :firefox
18
+ else
19
+ name
20
+ end
21
+ end
22
+
23
+ def options
24
+ case name
25
+ when :headless_chrome
26
+ headless_chrome_browser_options
27
+ when :headless_firefox
28
+ headless_firefox_browser_options
29
+ end
30
+ end
31
+
32
+ private
33
+ def headless_chrome_browser_options
34
+ options = ::Selenium::WebDriver::Chrome::Options.new
35
+ options.args << "--headless"
36
+ options.args << "--disable-gpu"
37
+
38
+ options
39
+ end
40
+
41
+ def headless_firefox_browser_options
42
+ options = ::Selenium::WebDriver::Firefox::Options.new
43
+ options.args << "-headless"
44
+
45
+ options
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,59 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActionDispatch
4
+ module SystemTesting
5
+ class Driver # :nodoc:
6
+ def initialize(name, **options)
7
+ @name = name
8
+ @browser = Browser.new(options[:using])
9
+ @screen_size = options[:screen_size]
10
+ @options = options[:options]
11
+ end
12
+
13
+ def use
14
+ register if registerable?
15
+
16
+ setup
17
+ end
18
+
19
+ private
20
+ def registerable?
21
+ [:selenium, :poltergeist, :webkit].include?(@name)
22
+ end
23
+
24
+ def register
25
+ Capybara.register_driver @name do |app|
26
+ case @name
27
+ when :selenium then register_selenium(app)
28
+ when :poltergeist then register_poltergeist(app)
29
+ when :webkit then register_webkit(app)
30
+ end
31
+ end
32
+ end
33
+
34
+ def browser_options
35
+ @options.merge(options: @browser.options).compact
36
+ end
37
+
38
+ def register_selenium(app)
39
+ Capybara::Selenium::Driver.new(app, { browser: @browser.type }.merge(browser_options)).tap do |driver|
40
+ driver.browser.manage.window.size = Selenium::WebDriver::Dimension.new(*@screen_size)
41
+ end
42
+ end
43
+
44
+ def register_poltergeist(app)
45
+ Capybara::Poltergeist::Driver.new(app, @options.merge(window_size: @screen_size))
46
+ end
47
+
48
+ def register_webkit(app)
49
+ Capybara::Webkit::Driver.new(app, Capybara::Webkit::Configuration.to_hash.merge(@options)).tap do |driver|
50
+ driver.resize_window_to(driver.current_window_handle, *@screen_size)
51
+ end
52
+ end
53
+
54
+ def setup
55
+ Capybara.current_driver = @name
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActionDispatch
4
+ module SystemTesting
5
+ class Server # :nodoc:
6
+ class << self
7
+ attr_accessor :silence_puma
8
+ end
9
+
10
+ self.silence_puma = false
11
+
12
+ def run
13
+ setup
14
+ end
15
+
16
+ private
17
+ def setup
18
+ set_server
19
+ set_port
20
+ end
21
+
22
+ def set_server
23
+ Capybara.server = :puma, { Silent: self.class.silence_puma } if Capybara.server == Capybara.servers[:default]
24
+ end
25
+
26
+ def set_port
27
+ Capybara.always_include_port = true
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,96 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActionDispatch
4
+ module SystemTesting
5
+ module TestHelpers
6
+ # Screenshot helper for system testing.
7
+ module ScreenshotHelper
8
+ # Takes a screenshot of the current page in the browser.
9
+ #
10
+ # +take_screenshot+ can be used at any point in your system tests to take
11
+ # a screenshot of the current state. This can be useful for debugging or
12
+ # automating visual testing.
13
+ #
14
+ # The screenshot will be displayed in your console, if supported.
15
+ #
16
+ # You can set the +RAILS_SYSTEM_TESTING_SCREENSHOT+ environment variable to
17
+ # control the output. Possible values are:
18
+ # * [+simple+ (default)] Only displays the screenshot path.
19
+ # This is the default value.
20
+ # * [+inline+] Display the screenshot in the terminal using the
21
+ # iTerm image protocol (https://iterm2.com/documentation-images.html).
22
+ # * [+artifact+] Display the screenshot in the terminal, using the terminal
23
+ # artifact format (https://buildkite.github.io/terminal/inline-images/).
24
+ def take_screenshot
25
+ save_image
26
+ puts display_image
27
+ end
28
+
29
+ # Takes a screenshot of the current page in the browser if the test
30
+ # failed.
31
+ #
32
+ # +take_failed_screenshot+ is included in <tt>application_system_test_case.rb</tt>
33
+ # that is generated with the application. To take screenshots when a test
34
+ # fails add +take_failed_screenshot+ to the teardown block before clearing
35
+ # sessions.
36
+ def take_failed_screenshot
37
+ take_screenshot if failed? && supports_screenshot?
38
+ end
39
+
40
+ private
41
+ def image_name
42
+ failed? ? "failures_#{method_name}" : method_name
43
+ end
44
+
45
+ def image_path
46
+ @image_path ||= absolute_image_path.relative_path_from(Pathname.pwd).to_s
47
+ end
48
+
49
+ def absolute_image_path
50
+ Rails.root.join("tmp/screenshots/#{image_name}.png")
51
+ end
52
+
53
+ def save_image
54
+ page.save_screenshot(absolute_image_path)
55
+ end
56
+
57
+ def output_type
58
+ # Environment variables have priority
59
+ output_type = ENV["RAILS_SYSTEM_TESTING_SCREENSHOT"] || ENV["CAPYBARA_INLINE_SCREENSHOT"]
60
+
61
+ # Default to outputting a path to the screenshot
62
+ output_type ||= "simple"
63
+
64
+ output_type
65
+ end
66
+
67
+ def display_image
68
+ message = "[Screenshot]: #{image_path}\n".dup
69
+
70
+ case output_type
71
+ when "artifact"
72
+ message << "\e]1338;url=artifact://#{absolute_image_path}\a\n"
73
+ when "inline"
74
+ name = inline_base64(File.basename(absolute_image_path))
75
+ image = inline_base64(File.read(absolute_image_path))
76
+ message << "\e]1337;File=name=#{name};height=400px;inline=1:#{image}\a\n"
77
+ end
78
+
79
+ message
80
+ end
81
+
82
+ def inline_base64(path)
83
+ Base64.encode64(path).gsub("\n", "")
84
+ end
85
+
86
+ def failed?
87
+ !passed? && !skipped?
88
+ end
89
+
90
+ def supports_screenshot?
91
+ Capybara.current_driver != :rack_test
92
+ end
93
+ end
94
+ end
95
+ end
96
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActionDispatch
4
+ module SystemTesting
5
+ module TestHelpers
6
+ module SetupAndTeardown # :nodoc:
7
+ DEFAULT_HOST = "http://127.0.0.1"
8
+
9
+ def host!(host)
10
+ super
11
+ Capybara.app_host = host
12
+ end
13
+
14
+ def before_setup
15
+ host! DEFAULT_HOST
16
+ super
17
+ end
18
+
19
+ def after_teardown
20
+ take_failed_screenshot
21
+ Capybara.reset_sessions!
22
+ super
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActionDispatch
4
+ module SystemTesting
5
+ module TestHelpers
6
+ module UndefMethods # :nodoc:
7
+ extend ActiveSupport::Concern
8
+ included do
9
+ METHODS = %i(get post put patch delete).freeze
10
+
11
+ METHODS.each do |verb|
12
+ undef_method verb
13
+ end
14
+
15
+ def method_missing(method, *args, &block)
16
+ if METHODS.include?(method)
17
+ raise NoMethodError, "System tests cannot make direct requests via ##{method}; use #visit and #click_on instead. See http://www.rubydoc.info/github/teamcapybara/capybara/master#The_DSL for more information."
18
+ else
19
+ super
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,3 @@
1
+ module BackportedSystemTests
2
+ VERSION = '0.1.0'.freeze
3
+ end
@@ -0,0 +1,51 @@
1
+ require_relative '../action_dispatch/system_test_case'
2
+
3
+ # Make double-sure the RAILS_ENV is not set to production,
4
+ # so fixtures aren't loaded into that environment
5
+ abort("Abort testing: Your Rails environment is running in production mode!") if Rails.env.production?
6
+
7
+ require "active_support/test_case"
8
+ require "action_controller"
9
+ require "action_controller/test_case"
10
+ require "action_dispatch/testing/integration"
11
+
12
+ require "active_support/testing/autorun"
13
+
14
+ if defined?(ActiveRecord::Base)
15
+ begin
16
+ ActiveRecord::Migration.maintain_test_schema!
17
+ rescue ActiveRecord::PendingMigrationError => e
18
+ puts e.to_s.strip
19
+ exit 1
20
+ end
21
+
22
+ module ActiveSupport
23
+ class TestCase
24
+ include ActiveRecord::TestFixtures
25
+ self.fixture_path = "#{Rails.root}/test/fixtures/"
26
+ self.file_fixture_path = fixture_path + "files"
27
+ end
28
+ end
29
+
30
+ ActionDispatch::IntegrationTest.fixture_path = ActiveSupport::TestCase.fixture_path
31
+
32
+ def create_fixtures(*fixture_set_names, &block)
33
+ FixtureSet.create_fixtures(ActiveSupport::TestCase.fixture_path, fixture_set_names, {}, &block)
34
+ end
35
+ end
36
+
37
+ # :enddoc:
38
+
39
+ class ActionController::TestCase
40
+ def before_setup # :nodoc:
41
+ @routes = Rails.application.routes
42
+ super
43
+ end
44
+ end
45
+
46
+ class ActionDispatch::IntegrationTest
47
+ def before_setup # :nodoc:
48
+ @routes = Rails.application.routes
49
+ super
50
+ end
51
+ end
metadata ADDED
@@ -0,0 +1,123 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: backported_system_tests
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Andrew Fomera
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-01-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 5.0.6
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 5.0.6
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.16'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.16'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '5.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '5.0'
69
+ description: |-
70
+ This gem backports the work the great contributors of
71
+ Rails have done for getting System Tests on Rails 5.1. This helps to ease the upgrade
72
+ path for applications that are larger.
73
+ email:
74
+ - andrew@zerlex.net
75
+ executables: []
76
+ extensions: []
77
+ extra_rdoc_files: []
78
+ files:
79
+ - ".gitignore"
80
+ - ".travis.yml"
81
+ - CODE_OF_CONDUCT.md
82
+ - Gemfile
83
+ - Gemfile.lock
84
+ - LICENSE.txt
85
+ - README.md
86
+ - Rakefile
87
+ - backported_system_tests.gemspec
88
+ - bin/console
89
+ - bin/setup
90
+ - lib/action_dispatch/system_test_case.rb
91
+ - lib/action_dispatch/system_testing/browser.rb
92
+ - lib/action_dispatch/system_testing/driver.rb
93
+ - lib/action_dispatch/system_testing/server.rb
94
+ - lib/action_dispatch/system_testing/test_helpers/screenshot_helper.rb
95
+ - lib/action_dispatch/system_testing/test_helpers/setup_and_teardown.rb
96
+ - lib/action_dispatch/system_testing/test_helpers/undef_methods.rb
97
+ - lib/backported_system_tests.rb
98
+ - lib/rails/test_help.rb
99
+ homepage: https://github.com/king601/backported_system_tests
100
+ licenses:
101
+ - MIT
102
+ metadata: {}
103
+ post_install_message:
104
+ rdoc_options: []
105
+ require_paths:
106
+ - lib
107
+ required_ruby_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ required_rubygems_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ requirements: []
118
+ rubyforge_project:
119
+ rubygems_version: 2.6.13
120
+ signing_key:
121
+ specification_version: 4
122
+ summary: Backport of the Rails 5.1 System Tests to work in Rails 5.
123
+ test_files: []