capybara-chromedriver-logger 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6bf949569140cd895d2e29fb9c168b933a362c71
4
- data.tar.gz: 932cc9b2c08c52af54a05728428ac100621024d6
3
+ metadata.gz: a2adb7cdaeb7970c7f543a69bade1af3c1dd37bf
4
+ data.tar.gz: 5296595dcd28304754d3c6bc122463fc0b965363
5
5
  SHA512:
6
- metadata.gz: 77de57767e12fcac2eade8c81795e1e413bbdcb6ab169696f6a1b18d3c786e83542f66ceae06c1b92cb44f7d4064e15383e8ecc5dc38ae3727ab29f07f42c968
7
- data.tar.gz: 8edc993525de574405a2cb840956281040f8f9689de0d84d7439a072d1edc86bb781abe3313ebb9f50ed854222bcba9c35ae74fad79e8f1262f5779d801cabcf
6
+ metadata.gz: f99ad48a1477114a5323163a535a7ed112bee149ab8a4dccc668562c9187a256e2821b1370176de5496010ee5f21a8a0b4fd53c36b4ac93228764a0df10972bd
7
+ data.tar.gz: 27578f35e27085a1a800890545c85d49a9f03a65f27c642ca5b018b02713b9ccde3d5ba8d696609ea0f6a11c11e5cf0232b7fb13cdaa7dde8cf4d3642c047823
@@ -1,3 +1,9 @@
1
+ # 0.2.0 [Feb 17, 2018]
2
+
3
+ * Stop using threads, it's a fool's errand. We now output logs at the end of each test
4
+ * Update colors
5
+ * Drop dependencies on net-http-persistent + selenium-webdriver
6
+
1
7
  # 0.1.2 [Feb 16, 2018]
2
8
 
3
9
  * Use a new instance with each spec example to avoid issues with code reloading
@@ -1,11 +1,9 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- capybara-chromedriver-logger (0.1.2)
4
+ capybara-chromedriver-logger (0.2.0)
5
5
  capybara
6
6
  colorize
7
- net-http-persistent
8
- selenium-webdriver
9
7
 
10
8
  GEM
11
9
  remote: https://rubygems.org/
@@ -28,15 +26,12 @@ GEM
28
26
  nokogiri (~> 1.8)
29
27
  coderay (1.1.2)
30
28
  colorize (0.8.1)
31
- connection_pool (2.2.1)
32
29
  diff-lcs (1.3)
33
30
  ffi (1.9.21)
34
31
  io-like (0.3.0)
35
32
  method_source (0.9.0)
36
33
  mini_mime (1.0.0)
37
34
  mini_portile2 (2.3.0)
38
- net-http-persistent (3.0.0)
39
- connection_pool (~> 2.2)
40
35
  nokogiri (1.8.2)
41
36
  mini_portile2 (~> 2.3.0)
42
37
  pry (0.11.3)
@@ -79,6 +74,7 @@ DEPENDENCIES
79
74
  pry
80
75
  rake (~> 10.0)
81
76
  rspec (~> 3.0)
77
+ selenium-webdriver
82
78
  stub_server
83
79
 
84
80
  BUNDLED WITH
data/README.md CHANGED
@@ -1,13 +1,12 @@
1
1
  # capybara-chromedriver-logger
2
2
 
3
- This gem provides real-time `console.log` debug output for Ruby feature specs running under Chromedriver.
3
+ This gem provides `console.log` debug output for Ruby feature specs running under Chromedriver.
4
4
 
5
5
  We currently assume you're running:
6
6
 
7
7
  * capybara
8
- * chromedriver
8
+ * chromedriver + selenium-webdriver
9
9
  * rspec
10
- * selenium-webdriver
11
10
 
12
11
  to handle your JS feature specs. I'd love to expand support for other combinations of test environments!
13
12
 
@@ -42,14 +41,10 @@ Capybara.register_driver(:chrome) do |app|
42
41
  }
43
42
  )
44
43
 
45
- # Selenium needs to use a thread-safe HTTP client
46
- client = Capybara::Chromedriver::Logger::SeleniumHttpClient.new
47
-
48
44
  Capybara::Selenium::Driver.new(
49
45
  app,
50
46
  browser: :chrome,
51
- desired_capabilities: capabilities,
52
- http_client: client
47
+ desired_capabilities: capabilities
53
48
  )
54
49
  end
55
50
 
@@ -57,8 +52,15 @@ end
57
52
  Capybara.default_driver = :chrome
58
53
  Capybara.javascript_driver = :chrome
59
54
 
60
- # Setup before/after hooks for your feature specs
55
+ # Option 1: Setup hooks for your feature specs
61
56
  Capybara::Chromedriver::Logger::TestHooks.for_rspec!
57
+
58
+ # Option 2: if you prefer to hook it in manually:
59
+ RSpec.configure do |config|
60
+ config.after :each, type: :feature do
61
+ Capybara::Chromedriver::Logger::TestHooks.after_example!
62
+ end
63
+ end
62
64
  ```
63
65
 
64
66
  ## Configuration
@@ -31,13 +31,12 @@ Gem::Specification.new do |spec|
31
31
 
32
32
  spec.add_dependency "capybara"
33
33
  spec.add_dependency "colorize"
34
- spec.add_dependency "net-http-persistent"
35
- spec.add_dependency "selenium-webdriver"
36
34
 
37
35
  spec.add_development_dependency "bundler", "~> 1.16"
38
36
  spec.add_development_dependency "chromedriver-helper"
39
37
  spec.add_development_dependency "pry"
40
38
  spec.add_development_dependency "rake", "~> 10.0"
41
39
  spec.add_development_dependency "rspec", "~> 3.0"
40
+ spec.add_development_dependency "selenium-webdriver"
42
41
  spec.add_development_dependency "stub_server"
43
42
  end
@@ -1,24 +1,15 @@
1
1
  require 'capybara'
2
2
  require 'selenium-webdriver'
3
- require 'selenium/webdriver/remote/http/persistent'
4
3
 
5
4
  require "capybara/chromedriver/logger/test_hooks"
6
5
  require "capybara/chromedriver/logger/version"
7
6
  require "capybara/chromedriver/logger/js_error"
8
7
  require "capybara/chromedriver/logger/message"
9
- require "capybara/chromedriver/logger/watcher"
10
- require "capybara/chromedriver/logger/selenium_thread_safe_bridge"
11
-
12
- class Selenium::WebDriver::Remote::Bridge
13
- prepend Capybara::Chromedriver::Logger::SeleniumThreadSafeBridge
14
- end
8
+ require "capybara/chromedriver/logger/collector"
15
9
 
16
10
  module Capybara
17
11
  module Chromedriver
18
12
  module Logger
19
- # This HTTP client is thread-safe, unlike the default client.
20
- SeleniumHttpClient = ::Selenium::WebDriver::Remote::Http::Persistent
21
-
22
13
  extend self
23
14
 
24
15
  def filters
@@ -1,45 +1,22 @@
1
- require 'thread'
2
-
3
1
  module Capybara
4
2
  module Chromedriver
5
3
  module Logger
6
- class Watcher
4
+ class Collector
7
5
  def initialize(log_destination: $stdout, filters: nil)
8
6
  @log_destination = log_destination
9
- @last_timestamp = 0
10
- @mutex = Mutex.new
11
- @thread = nil
12
- @paused = true
13
7
  @filters = filters || Capybara::Chromedriver::Logger.filters
14
8
  @errors = []
15
9
  end
16
10
 
17
- def before_example!
18
- unpause!
19
- start_listener!
20
- end
21
-
22
- def after_example!
23
- pause!
11
+ def flush_and_check_errors!
24
12
  flush_logs!
25
13
 
26
14
  raise_errors_if_needed!
27
15
  clear_errors!
28
- ensure
29
- thread.kill if thread
30
16
  end
31
17
 
32
18
  private
33
19
 
34
- def start_listener!
35
- @thread = Thread.new do
36
- loop do
37
- flush_logs! unless paused?
38
- sleep 0.1
39
- end
40
- end
41
- end
42
-
43
20
  def raise_errors_if_needed!
44
21
  return unless Capybara::Chromedriver::Logger.raise_js_errors?
45
22
  return if errors.empty?
@@ -53,13 +30,9 @@ module Capybara
53
30
 
54
31
  def flush_logs!
55
32
  browser_logs.each do |log|
56
- next if log.timestamp < last_timestamp
57
-
58
- @last_timestamp = log.timestamp
59
-
60
33
  message = Message.new(log)
61
-
62
34
  errors << message if message.error?
35
+
63
36
  log_destination.puts message.to_s unless should_filter?(message)
64
37
  end
65
38
  end
@@ -73,14 +46,12 @@ module Capybara
73
46
  end
74
47
 
75
48
  def logs(type)
76
- mutex.synchronize do
77
- Capybara
78
- .current_session
79
- .driver.browser
80
- .manage
81
- .logs
82
- .get(type)
83
- end
49
+ Capybara
50
+ .current_session
51
+ .driver.browser
52
+ .manage
53
+ .logs
54
+ .get(type)
84
55
  end
85
56
 
86
57
  def should_filter?(message)
@@ -91,37 +62,13 @@ module Capybara
91
62
  @errors
92
63
  end
93
64
 
94
- def unpause!
95
- @paused = false
96
- end
97
-
98
- def pause!
99
- @paused = true
100
- end
101
-
102
- def mutex
103
- @mutex
104
- end
105
-
106
65
  def filters
107
66
  @filters
108
67
  end
109
68
 
110
- def last_timestamp
111
- @last_timestamp
112
- end
113
-
114
- def paused?
115
- !!@paused
116
- end
117
-
118
69
  def log_destination
119
70
  @log_destination
120
71
  end
121
-
122
- def thread
123
- @thread
124
- end
125
72
  end
126
73
  end
127
74
  end
@@ -36,6 +36,7 @@ module Capybara
36
36
  COLORS = {
37
37
  'SEVERE' => :light_red,
38
38
  'INFO' => :light_green,
39
+ 'WARNING' => :light_cyan,
39
40
  'DEBUG' => :light_blue
40
41
  }.freeze
41
42
 
@@ -2,17 +2,15 @@ module Capybara
2
2
  module Chromedriver
3
3
  module Logger
4
4
  class TestHooks
5
+ def self.after_example!
6
+ collector = Capybara::Chromedriver::Logger::Collector.new
7
+ collector.flush_and_check_errors!
8
+ end
9
+
5
10
  def self.for_rspec!
6
11
  ::RSpec.configure do |config|
7
- filters = { type: :feature }
8
-
9
- config.before :each, filters do
10
- @_log_watcher = Capybara::Chromedriver::Logger::Watcher.new
11
- @_log_watcher.before_example!
12
- end
13
-
14
- config.after :each, filters do
15
- @_log_watcher.after_example!
12
+ config.after :each, type: :feature do
13
+ Capybara::Chromedriver::Logger::TestHooks.after_example!
16
14
  end
17
15
  end
18
16
  end
@@ -1,7 +1,7 @@
1
1
  module Capybara
2
2
  module Chromedriver
3
3
  module Logger
4
- VERSION = "0.1.2"
4
+ VERSION = "0.2.0"
5
5
  end
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capybara-chromedriver-logger
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Balatero
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-02-17 00:00:00.000000000 Z
11
+ date: 2018-02-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: capybara
@@ -38,34 +38,6 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
- - !ruby/object:Gem::Dependency
42
- name: net-http-persistent
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - ">="
46
- - !ruby/object:Gem::Version
47
- version: '0'
48
- type: :runtime
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- version: '0'
55
- - !ruby/object:Gem::Dependency
56
- name: selenium-webdriver
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - ">="
60
- - !ruby/object:Gem::Version
61
- version: '0'
62
- type: :runtime
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - ">="
67
- - !ruby/object:Gem::Version
68
- version: '0'
69
41
  - !ruby/object:Gem::Dependency
70
42
  name: bundler
71
43
  requirement: !ruby/object:Gem::Requirement
@@ -136,6 +108,20 @@ dependencies:
136
108
  - - "~>"
137
109
  - !ruby/object:Gem::Version
138
110
  version: '3.0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: selenium-webdriver
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
139
125
  - !ruby/object:Gem::Dependency
140
126
  name: stub_server
141
127
  requirement: !ruby/object:Gem::Requirement
@@ -171,12 +157,11 @@ files:
171
157
  - capybara-chromedriver-logger.gemspec
172
158
  - images/example.png
173
159
  - lib/capybara/chromedriver/logger.rb
160
+ - lib/capybara/chromedriver/logger/collector.rb
174
161
  - lib/capybara/chromedriver/logger/js_error.rb
175
162
  - lib/capybara/chromedriver/logger/message.rb
176
- - lib/capybara/chromedriver/logger/selenium_thread_safe_bridge.rb
177
163
  - lib/capybara/chromedriver/logger/test_hooks.rb
178
164
  - lib/capybara/chromedriver/logger/version.rb
179
- - lib/capybara/chromedriver/logger/watcher.rb
180
165
  homepage: https://github.com/dbalatero/capybara-chromedriver-logger
181
166
  licenses:
182
167
  - MIT
@@ -1,16 +0,0 @@
1
- module Capybara
2
- module Chromedriver
3
- module Logger
4
- # Ensure our polling thread doesn't compete with the main spec example
5
- module SeleniumThreadSafeBridge
6
- def __execute_lock
7
- @__execute_lock ||= Mutex.new
8
- end
9
-
10
- def execute(*args)
11
- __execute_lock.synchronize { super }
12
- end
13
- end
14
- end
15
- end
16
- end