integration-tests-rails 1.0.9 → 1.1.0

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: 8565c51a68e4a566e3a2c24beac10c56e34135db4d21d75c877b9014d94093f2
4
- data.tar.gz: 3bc4334e481beec869779f050d8ba9993e5696739ab75544e2f7835970697fcd
3
+ metadata.gz: a76f78f94ceebb76953e47c1d45a2e4b39f3f5260e3238721861bf6102522690
4
+ data.tar.gz: 2e2c200ec76728898e642ece116eb1ad163490f55a6a855c7dc8a96dc7f03cb1
5
5
  SHA512:
6
- metadata.gz: 6580bf376345a375c56a051c237ec5b0937c03313f2967a708716d231f03034629b610bd41f9ef8c0901266984ac25f76d17b80746c1896f4ddc273ed30f50bd
7
- data.tar.gz: e5471e16f941749f504575705f3e4992084a6e34b2c9d794a65273dfb690edadb3a150f1d31c5019fcbf8d266f7b38ba515c8ac130e25906d1d708190d095dcf
6
+ metadata.gz: cb4e8d66540dd7b3a854af21a5fad11c439fc3c8a31b8aa96f7a9dcab74e9a2f97c6d30478201b9e2afb057121f5ca89a8c36a1019a0548e93d241c4e96171c5
7
+ data.tar.gz: 52227cad3110ba38c617a671614419fb321a0f58a05249ed5957a5d46f2881c0ff3cf09a3e792f28e8b9881b073be97303a53329c2f73a8970e1bce5d3061347
data/README.md CHANGED
@@ -66,6 +66,8 @@ IntegrationTestsRails.setup do |config|
66
66
  config.max_server_retries = 1000 # Before running the tests, Cuprite starts a server to communicate with Chrome. This sets the maximum number of retries to connect to that server.
67
67
  config.puma_threads = '1:1' # Number of threads for the Puma server used by Cuprite.
68
68
  config.remote = false # Whether to use a remote Chrome instance.
69
+ config.retry_attempts = 1 # Number of times to retry a test if an example fails inside a retry_on_fail block.
70
+ config.retry_sleep_duration = 0 # Number of seconds to wait between retries inside a retry_on_fail block.
69
71
  config.server_host = '0.0.0.0' # Host for the Puma server used by Cuprite.
70
72
  config.server_port = nil # Port for the Puma server used by Cuprite.
71
73
  config.source_dir = 'app/javascript' # Directory containing the JavaScript files to be instrumented.
@@ -221,6 +223,34 @@ In such cases where `script` is an array, the `result` component will contain th
221
223
 
222
224
  Refer to [Cuprite](https://github.com/rubycdp/cuprite) and [Capybara](https://github.com/teamcapybara/capybara). Use them as normally in integration tests.
223
225
 
226
+ ## Retrying Flaky Tests
227
+
228
+ In practice, this is frowned upon. However, in such cases where there exists a flaky test (e.g. network issues, timing issues, third-party services respnsiveness, etc.), the gem provides a way to retry tests through `retry_on_fail`.
229
+
230
+ ```ruby
231
+ RSpec.describe 'Flaky Test', type: :feature do
232
+ describe 'Flaky Behavior' do
233
+ it 'must succeed' do
234
+ visit '/form_with_complex_javascript'
235
+ retry_on_fail do
236
+ check 'Checkbox that executes scripts with animations'
237
+ expect(page).to have_css('div#animated-element', visible: :visible, wait: 5)
238
+ end
239
+
240
+ expect(page).to have_content('Complex Modal Opened')
241
+ end
242
+ end
243
+ end
244
+ ```
245
+
246
+ The above will retry the test if the browser was not able to find the checkbox or the page was not able to find the animated element. The number of retries and sleep duration between retries can be configured through `retry_attempts` and `retry_sleep_duration` configuration options respectively. The default number of retries is 1 and the default sleep duration is 0 seconds. You can also pass them as arguments:
247
+
248
+ ```ruby
249
+ retry_on_fail(retry_attempts: 3, retry_sleep_duration: 1) do
250
+ expect(page).to have_css('div#animated-element', visible: :visible, wait: 5)
251
+ end
252
+ ```
253
+
224
254
  ## JavaScript Coverage Reports
225
255
 
226
256
  After the tests (successful, failed or cancelled), coverage reports will be generated in `coverage/javascript` by default.
@@ -268,6 +298,11 @@ IntegrationTestsRails.setup do |config|
268
298
  end
269
299
  ```
270
300
 
301
+ ## TODO
302
+
303
+ 1. JavaScript unit testing needs to have a way to define the JavaScript loader in the spec file itself instead of in `IntegrationTestsRails.configuration.tests_page_html`.
304
+ 2. There is no graceful way to stop failing CDNs from being retried. Find a way to wait for them to complete loading. It should respect the `IntegrationTestsRails.configuration.timeout` setting.
305
+
271
306
  ## Contributing
272
307
 
273
308
  1. Fork the repository.
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module IntegrationTestsRails
4
+ module Capybara
5
+ # This module provides the main DSL for writing integration tests with Capybara.
6
+ module Dsl
7
+ def retry_on_fail(attempts: nil, sleep_duration: nil)
8
+ config = IntegrationTestsRails.configuration
9
+ attempts ||= config.retry_attempts
10
+ sleep_duration ||= config.retry_sleep_duration
11
+ counter = 0
12
+
13
+ begin
14
+ yield
15
+ rescue RSpec::Expectations::ExpectationNotMetError, Capybara::ElementNotFound => e
16
+ counter += 1
17
+ Util.log("Attempt #{counter} for #{RSpec.current_example.full_description} failed!")
18
+ raise e if counter >= attempts
19
+
20
+ sleep(sleep_duration) if sleep_duration.positive?
21
+ retry
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -36,6 +36,7 @@ module IntegrationTestsRails
36
36
 
37
37
  def configure_rspec
38
38
  RSpec.configure do |config|
39
+ config.include Dsl, type: :feature
39
40
  config.before(:each, type: :feature) do
40
41
  ::Capybara.current_driver = ::Capybara.javascript_driver
41
42
  IntegrationTestsRails::Capybara::Util.ensure_server_ready(self)
@@ -39,7 +39,8 @@ module IntegrationTestsRails
39
39
 
40
40
  attr_accessor :source_dir, :output_dir, :backup_dir, :coverage_path, :wait_time, :remote,
41
41
  :chrome_url, :tests_page_html, :window_size, :max_server_retries,
42
- :verbose, :timeout, :server_host, :server_port, :puma_threads, :experimental_features
42
+ :verbose, :timeout, :server_host, :server_port, :puma_threads, :experimental_features,
43
+ :retry_attempts, :retry_sleep_duration
43
44
 
44
45
  def initialize
45
46
  @backup_dir = 'tmp/js_backup'
@@ -50,6 +51,8 @@ module IntegrationTestsRails
50
51
  @output_dir = 'tmp/instrumented_js'
51
52
  @puma_threads = '1:1'
52
53
  @remote = false
54
+ @retry_attempts = 1
55
+ @retry_sleep_duration = 0
53
56
  @server_host = '0.0.0.0' # rubocop:disable Style/IpAddresses
54
57
  @server_port = nil
55
58
  @source_dir = 'app/javascript'
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module IntegrationTestsRails
4
- VERSION = '1.0.9'
4
+ VERSION = '1.1.0'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: integration-tests-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.9
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tien
@@ -90,6 +90,7 @@ files:
90
90
  - lib/integration-tests-rails.rb
91
91
  - lib/integration_tests_rails.rb
92
92
  - lib/integration_tests_rails/capybara.rb
93
+ - lib/integration_tests_rails/capybara/dsl.rb
93
94
  - lib/integration_tests_rails/capybara/helpers.rb
94
95
  - lib/integration_tests_rails/capybara/local.rb
95
96
  - lib/integration_tests_rails/capybara/remote.rb