evil_systems 0.0.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6c39ae0b47c7d330afb6daa3ef1c8137d190f861905a4a3cdc45305740927ec1
4
- data.tar.gz: e3c40f2764522b1796d11053aecd530267704d87f0ce6732b7d58374a2c030e9
3
+ metadata.gz: c6d3ebd5d518e616a3322a78a4556837b8b81866832e0b6436098c838142d183
4
+ data.tar.gz: 64b2e8ecd7f030691ec8e8a81dd088fb42cb79d9933cf0d6fcc1a9bc2ddd99a3
5
5
  SHA512:
6
- metadata.gz: fed0a5eebfba465c8d2d36228e7b05e6da431a464ee540b34f867c34e64d6263e7cc52d7e9612b679c198514f81ae1fbaff833dc8430600a561e89617ad8a407
7
- data.tar.gz: 992f7b9646ecf70c5c07c032f40af6422e52785897ef7cc29c56cc45b08f875e684fec1a5a9b90c81687a1a67b660159fb3bde20490f7f8e9d2226aea59101f5
6
+ metadata.gz: 45ad267ef6df0f634912e658384d19a5ec4f5422becbd7e9e413d6a8dffe3a130d0bcb2b55faa4f8ebfe598ed56e80b7757b342594de18a63b544a52ba34f31e
7
+ data.tar.gz: f3e7f6da2b5ccaaebe13cb26d35907dc05d38673492f874d0fc317c39c7899a2e8ad206f417b095db1b84e55c5cb9c91b920af66e89450ed3b7b35ddf68a45ef
data/CHANGELOG.md CHANGED
@@ -1,3 +1,16 @@
1
- ## 0.0.1
1
+ ## 0.1.1
2
+
3
+ - Fix readme issue
4
+ - Remove mark_all_banners_as_read
5
+ - Remove selenium-webdriver
6
+
7
+ ## 0.1.0
8
+
9
+ - Allow the Cuprite driver to be configured with ENV variables for headless mode and process_timeouts.
10
+ - Increase process_timeout default to 5
11
+ - Add GH actions testing with a remote chrome instance
12
+ - Minor API cleanup
13
+
14
+ ## 0.0.3
2
15
 
3
16
  Initial release!
data/README.md CHANGED
@@ -1,20 +1,44 @@
1
- # EvilSystemTests
1
+ # Purpose
2
2
 
3
- Why does this exist?
3
+ I write tests using Minitest and routinely reference [EvilMartians System
4
+ of a Test blog post](https://evilmartians.com/chronicles/system-of-a-test-setting-up-end-to-end-rails-testing)
5
+ for best practices for system tests. In this blog post,
6
+ they also have an opinionated way of setting up System Tests.
4
7
 
5
- I wanted a quick, easy, reusable way to use the settings put forth in
6
- [EvilMartians System of a Test blog post] (https://evilmartians.com/chronicles/system-of-a-test-setting-up-end-to-end-rails-testing)
7
- for Minitest. System of a test is currently written for RSpec.
8
+ `EvilSystems` offers 3 distinct advantages over the setup provided by
9
+ EvilMartians System of a Test:
10
+
11
+ 1.) The blog post was built with RSpec in mind, but we use Minitest
12
+ here!
13
+
14
+ 2.) Constantly copying 5 files over into every new Rails app is annoying. Lets make that easier!
15
+
16
+ 3.) File changes can end up out of sync, a gem makes sure updates can be
17
+ pushed to all users.
18
+
19
+ `EvilSystems` is a quick, easy, reusable way to apply the SoaT concepts and settings
20
+ to projects for system tests using Minitest.
8
21
 
9
22
  Full API documentation can be found here:
10
23
 
24
+ https://rdoc.info/github/paramagicdev/evil_systems/main
11
25
 
12
26
  ## Installation
13
27
 
14
- Add this line to your application's Gemfile:
28
+ ```ruby
29
+ # Gemfile
30
+ group :test do
31
+ gem 'evil_systems', '~> 0.1.0'
32
+ end
33
+ ```
34
+
35
+ Make sure the following 3 gems are in your `Gemfile` as well:
15
36
 
16
37
  ```ruby
17
- gem 'evil_system_tests'
38
+ # Gemfile
39
+ gem 'capybara'
40
+ gem 'cuprite' # Optional
41
+ gem 'selenium-webdriver' # Not required if using Cuprite and using Rails >= 6.1
18
42
  ```
19
43
 
20
44
  And then execute:
@@ -31,25 +55,23 @@ Navigate to `test/application_system_test_case.rb` in your Rails app.
31
55
 
32
56
  Setup your file like so:
33
57
 
34
- ```rb
58
+ ```ruby
35
59
  # test/application_system_test_case.rb
36
60
 
37
61
  require 'test_helper'
38
62
 
39
- + # 'capybara' and 'capybara/cuprite' need to be defined for EvilSystems to
40
- work properly.
41
- + require 'capybara'
42
- + require 'capybara/cuprite'
63
+ # 'capybara' and 'capybara/cuprite' need to be defined for EvilSystems to work properly.
64
+ require 'capybara'
65
+ require 'capybara/cuprite'
43
66
 
44
- + require 'evil_systems'
67
+ require 'evil_systems'
45
68
 
46
- + EvilSystems.initial_setup
69
+ EvilSystems.initial_setup
47
70
 
48
71
  class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
49
- - driven_by :selenium, using: :chrome, screen_size: [1400, 1400]
50
- + driven_by :cuprite
72
+ driven_by :cuprite
51
73
 
52
- + include EvilSystems::Helpers
74
+ include EvilSystems::Helpers
53
75
  end
54
76
  ```
55
77
 
@@ -65,18 +87,28 @@ end
65
87
  `silent`.
66
88
 
67
89
  Both arguments have to do with precompiling assets.
90
+
68
91
  `:silent` by default is set to `true` and will only tell you when assets
69
- are compiling, and how long it took.
92
+ are compiling, and how long the compilation took.
93
+
70
94
  `:task` defaults to `assets:precompile`, System of a test uses
71
95
  `webpacker:compile`.
72
96
 
97
+ Example:
98
+
99
+ ```rb
100
+ EvilSystems.initial_setup(task: "webpacker:compile", silent: false)
101
+ ```
102
+
73
103
  ### Settings
74
104
 
75
- [x] - Automatically registers a `:cuprite` driver if `Capybara::Cuprite`
105
+ - [x] - Automatically registers a `:cuprite` driver if `Capybara::Cuprite`
76
106
  is defined.
77
- [x] - Automatically sets Capybara's default and javascript driver to
107
+
108
+ - [x] - Automatically sets Capybara's default and javascript driver to
78
109
  `:cuprite`
79
- [x] - Automatically sets `Capybara.app_host`
110
+
111
+ - [x] - Automatically sets `Capybara.app_host`
80
112
 
81
113
  <details>
82
114
  <summary>How `app_host` is set</summary>
@@ -87,14 +119,17 @@ If neither are defined, it will then default to `"0.0.0.0"`
87
119
 
88
120
  </details>
89
121
 
90
- [x] - `Capybara.server_host = "0.0.0.0"`
91
- [x] - `Capybara.default_max_wait_time = 2`
92
- [x] - `Capybara.default_normalize_ws = true` normalizes whitespace in
93
- `has_text?` and similar matchers.
94
- [x] - Sets the `Capybara.save_path` Uses `ENV["CAPYBARA_ARTIFACTS"]` and
95
- falls back to `"./tmp/capybara"`
96
- [x] - Sets a `REMOTE_CHROME` instance if a `ENV["CHROME_URL"]` is found
97
- [x] - Prepends a `last_used_session` attribute accessor to Capybara.
122
+ - [x] - `Capybara.server_host = "0.0.0.0"` Make server listening on all hosts
123
+
124
+ - [x] - `Capybara.default_max_wait_time = 2` Dont spend forever waiting for matchers
125
+
126
+ - [x] - `Capybara.default_normalize_ws = true` normalizes whitespace in `has_text?` and similar matchers.
127
+
128
+ - [x] - Sets the `Capybara.save_path` Uses `ENV["CAPYBARA_ARTIFACTS"]` and falls back to `"./tmp/capybara"`
129
+
130
+ - [x] - Sets a `REMOTE_CHROME` instance if a `ENV["CHROME_URL"]` is found
131
+
132
+ - [x] - Prepends a `last_used_session` attribute accessor to Capybara.
98
133
 
99
134
  ### Helpers
100
135
 
@@ -129,12 +164,8 @@ dom_id(*args)
129
164
  #### SessionHelpers
130
165
 
131
166
  ```rb
132
- # Small wrapper around Capybara.using_session thats easy to call from an
133
- instance
167
+ # Small wrapper around Capybara.using_session thats easy to call from an instance
134
168
  within_session(name_or_session, &block)
135
-
136
- # Remove all cookie banners
137
- mark_all_banners_as_read!
138
169
  ```
139
170
 
140
171
  #### Cuprite Helpers
@@ -144,21 +175,22 @@ mark_all_banners_as_read!
144
175
  pause
145
176
 
146
177
  # Opens a Pry or IRB repl. Will use Pry if Pry is defined, fallsback
147
- to debugging with IRB
148
- debug
178
+ # to debugging with IRB
179
+ debug binding
149
180
  ```
150
181
 
151
182
  ### Env Variables
152
183
 
184
+ ENV variables used by this gem.
185
+
153
186
  ```rb
154
187
  ENV["APP_HOST"] # used for Capybara.app_host
155
188
  ENV["CAPYBARA_ARTIFACTS"] # used for Capybara.save_path
156
- ENV["CHROME_URL"] # used for setting a remote chrome instance for
157
- Cuprite
189
+ ENV["CHROME_URL"] # used for setting a remote chrome instance for Cuprite
190
+ ENV["PROCESS_TIMEOUT"] # How long to wait before killing the process, default is 5 seconds
191
+ ENV["CI"] # Whether or not to run Cuprite in headless mode, defaults to true.
158
192
  ```
159
193
 
160
- ENV variables used by this gem.
161
-
162
194
  ## I don't want to use Cuprite.
163
195
 
164
196
  Thats fine! I totally get it. Selenium is battle tested. Simply remove
@@ -12,13 +12,22 @@ module EvilSystems
12
12
  def self.initial_setup
13
13
  return unless defined? Capybara::Cuprite
14
14
 
15
+ begin
16
+ process_timeout = Integer(ENV.fetch("PROCESS_TIMEOUT", 5))
17
+ rescue
18
+ process_timeout = 5
19
+ end
20
+
15
21
  remote_options = RemoteChrome.options
22
+
16
23
  ::Capybara.register_driver(:cuprite) do |app|
17
24
  ::Capybara::Cuprite::Driver.new(
18
25
  app,
19
26
  **{
20
27
  window_size: [1200, 800],
21
- browser_options: {"no-sandbox" => nil},
28
+ browser_options: RemoteChrome.connected? ? {"no-sandbox" => nil} : {},
29
+ headless: ENV.fetch("CI", "true") == "true",
30
+ process_timeout: process_timeout,
22
31
  inspector: true
23
32
  }.merge(remote_options)
24
33
  )
@@ -23,12 +23,12 @@ module EvilSystems
23
23
  def self.options
24
24
  # Check whether the remote chrome is running and configure the Capybara
25
25
  # driver for it.
26
- remote_chrome ? {url: url} : {}
26
+ connected? ? {url: url} : {}
27
27
  end
28
28
 
29
29
  # Whether or not the socket could be connected
30
30
  # @return [Boolean]
31
- def self.remote_chrome
31
+ def self.connected?
32
32
  if url.nil?
33
33
  false
34
34
  else
@@ -5,10 +5,5 @@ module EvilSystems
5
5
  def within_session(name_or_session, &block)
6
6
  ::Capybara.using_session(name_or_session, &block)
7
7
  end
8
-
9
- # Remove all banners
10
- def mark_all_banners_as_read!
11
- page.driver.set_cookie "show_banners", "N"
12
- end
13
8
  end
14
9
  end
@@ -29,6 +29,9 @@ module EvilSystems
29
29
  # Make server listening on all hosts
30
30
  ::Capybara.server_host = "0.0.0.0"
31
31
 
32
+ # Silence puma
33
+ ::Capybara.server = :puma, {Silent: true}
34
+
32
35
  # Don't wait too long in `have_xyz` matchers
33
36
  ::Capybara.default_max_wait_time = 2
34
37
 
@@ -1,3 +1,3 @@
1
1
  module EvilSystems
2
- VERSION = "0.0.1"
2
+ VERSION = "0.1.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: evil_systems
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - ParamagicDev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-04-05 00:00:00.000000000 Z
11
+ date: 2021-06-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: zeitwerk
@@ -95,7 +95,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
97
  requirements: []
98
- rubygems_version: 3.1.4
98
+ rubygems_version: 3.1.6
99
99
  signing_key:
100
100
  specification_version: 4
101
101
  summary: Fully integrated setup based on EvilMartians system of a test