chemlab 0.2.1 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +6 -0
  3. data/bin/chemlab +10 -0
  4. data/bin/chemlab-suite +1 -0
  5. data/bin/chemlab-test +1 -0
  6. data/lib/chemlab.rb +27 -17
  7. data/lib/chemlab/attributable.rb +16 -10
  8. data/lib/chemlab/cli/fixtures/new_library/.gitignore +63 -0
  9. data/lib/chemlab/cli/fixtures/new_library/Gemfile +5 -0
  10. data/lib/chemlab/cli/fixtures/new_library/README.md.erb +1 -0
  11. data/lib/chemlab/cli/fixtures/new_library/lib/new_library.rb.erb +7 -0
  12. data/lib/chemlab/cli/fixtures/new_library/lib/page/sample.rb.erb +9 -0
  13. data/lib/chemlab/cli/fixtures/new_library/new_library.gemspec.erb +23 -0
  14. data/lib/chemlab/cli/fixtures/new_library/spec/integration/page/sample_spec.rb.erb +17 -0
  15. data/lib/chemlab/cli/fixtures/new_library/spec/unit/page/sample_spec.rb.erb +19 -0
  16. data/lib/chemlab/cli/generator.rb +46 -0
  17. data/lib/chemlab/cli/generator/templates/page.erb +3 -0
  18. data/lib/chemlab/cli/new_library.rb +62 -0
  19. data/lib/chemlab/cli/stub.erb +65 -0
  20. data/lib/chemlab/cli/stubber.rb +74 -0
  21. data/lib/chemlab/component.rb +78 -8
  22. data/lib/chemlab/configuration.rb +61 -13
  23. data/lib/chemlab/element.rb +5 -0
  24. data/lib/chemlab/page.rb +20 -2
  25. data/lib/chemlab/runtime/browser.rb +19 -25
  26. data/lib/chemlab/runtime/env.rb +13 -9
  27. data/lib/chemlab/runtime/logger.rb +16 -13
  28. data/lib/chemlab/version.rb +1 -1
  29. data/lib/tasks/generate.rake +22 -0
  30. data/lib/tasks/generate_stubs.rake +20 -0
  31. data/lib/tasks/help.rake +24 -0
  32. data/lib/tasks/new.rake +19 -0
  33. data/lib/tasks/version.rake +8 -0
  34. metadata +68 -58
  35. data/lib/chemlab/api_fabricator.rb +0 -134
  36. data/lib/chemlab/resource.rb +0 -169
  37. data/lib/chemlab/runtime/api_client.rb +0 -18
  38. data/lib/chemlab/support/api.rb +0 -71
  39. data/lib/chemlab/support/logging.rb +0 -176
  40. data/lib/chemlab/support/repeater.rb +0 -65
  41. data/lib/chemlab/support/waiter.rb +0 -39
@@ -1,65 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'active_support/inflector'
4
-
5
- module Chemlab
6
- module Support
7
- module Repeater
8
- DEFAULT_MAX_WAIT_TIME = 60
9
-
10
- RetriesExceededError = Class.new(RuntimeError)
11
- WaitExceededError = Class.new(RuntimeError)
12
-
13
- def repeat_until(max_attempts: nil, max_duration: nil, reload_page: nil, sleep_interval: 0, raise_on_failure: true, retry_on_exception: false, log: true)
14
- attempts = 0
15
- start = Time.now
16
-
17
- begin
18
- while remaining_attempts?(attempts, max_attempts) && remaining_time?(start, max_duration)
19
- QA::Runtime::Logger.debug("Attempt number #{attempts + 1}") if max_attempts && log
20
-
21
- result = yield
22
- return result if result
23
-
24
- sleep_and_reload_if_needed(sleep_interval, reload_page)
25
- attempts += 1
26
- end
27
- rescue StandardError, RSpec::Expectations::ExpectationNotMetError
28
- raise unless retry_on_exception
29
-
30
- attempts += 1
31
- if remaining_attempts?(attempts, max_attempts) && remaining_time?(start, max_duration)
32
- sleep_and_reload_if_needed(sleep_interval, reload_page)
33
-
34
- retry
35
- else
36
- raise
37
- end
38
- end
39
-
40
- if raise_on_failure
41
- raise RetriesExceededError, "Retry condition not met after #{max_attempts} #{'attempt'.pluralize(max_attempts)}" unless remaining_attempts?(attempts, max_attempts)
42
-
43
- raise WaitExceededError, "Wait condition not met after #{max_duration} #{'second'.pluralize(max_duration)}"
44
- end
45
-
46
- false
47
- end
48
-
49
- private
50
-
51
- def sleep_and_reload_if_needed(sleep_interval, reload_page)
52
- sleep(sleep_interval)
53
- reload_page.refresh if reload_page
54
- end
55
-
56
- def remaining_attempts?(attempts, max_attempts)
57
- max_attempts ? attempts < max_attempts : true
58
- end
59
-
60
- def remaining_time?(start, max_duration)
61
- max_duration ? Time.now - start < max_duration : true
62
- end
63
- end
64
- end
65
- end
@@ -1,39 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Chemlab
4
- module Support
5
- module Waiter
6
- extend Repeater
7
-
8
- module_function
9
-
10
- def wait_until(max_duration: singleton_class::DEFAULT_MAX_WAIT_TIME, reload_page: nil, sleep_interval: 0.1, raise_on_failure: true, retry_on_exception: false, log: true)
11
- if log
12
- QA::Runtime::Logger.debug(
13
- <<~MSG.tr("\n", ' ')
14
- with wait_until: max_duration: #{max_duration};
15
- reload_page: #{reload_page};
16
- sleep_interval: #{sleep_interval};
17
- raise_on_failure: #{raise_on_failure}
18
- MSG
19
- )
20
- end
21
-
22
- result = nil
23
- self.repeat_until(
24
- max_duration: max_duration,
25
- reload_page: reload_page,
26
- sleep_interval: sleep_interval,
27
- raise_on_failure: raise_on_failure,
28
- retry_on_exception: retry_on_exception,
29
- log: log
30
- ) do
31
- result = yield
32
- end
33
- QA::Runtime::Logger.debug("ended wait_until") if log
34
-
35
- result
36
- end
37
- end
38
- end
39
- end