capybara-timeout_reporter 0.1.0 → 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: 4f0646abc4e26f1a83ce008075560a65dd0ebc15
4
- data.tar.gz: 8727dfe5305601ff5a67d016a4f573ad5ca760b7
3
+ metadata.gz: 30c1dea4661adbef47e1053dbc7eec87dc7f59c3
4
+ data.tar.gz: d58c47b443ca37792a26dc7b6ecb35f0724872a7
5
5
  SHA512:
6
- metadata.gz: ade055a63ab7a32c1afefd80e847e93f3003bc9be9b40f26baa8a5922e7489544460080ae4bfab820069c9cdbe8d49d43308985b17afd8a4dfe2f0205c66c544
7
- data.tar.gz: 0420c94652ad40370a345fbce36a62286811abb75dc41d1a968a2eb124ab1b44b8e1a1fbc9cb51f21b5daceb977143054b99cce5f9e12e536898fcd409bdc58e
6
+ metadata.gz: e64008ecc7b8bd942985d1f6031158eb00ed3a084eb0c45dfdbd73756119b7cf0db81bf5ae8664aca9998096c9d8d6fb7fecf5eba2913531329fc6c3a90af05f
7
+ data.tar.gz: a55103f903dc0e864a5ef4b0c21418a5cf5997500ddfb75fa28f80a523572a27a9f14f4fecced89c1aaabdbf1fa77109fbce54242c6f1338bba5becc3ec0a393
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = "capybara-timeout_reporter"
5
- spec.version = "0.1.0"
5
+ spec.version = "0.2.0"
6
6
  spec.authors = ["Vitalii Grygoruk"]
7
7
  spec.email = ["vitaliy[dot]grigoruk[at]gmail[dot]com"]
8
8
  spec.summary = %q{Detecting and reporting capybara sync timeouts}
@@ -3,7 +3,13 @@ require 'capybara'
3
3
  module Capybara
4
4
  class TimeoutReporter
5
5
 
6
+ @exclude_patterns = [/capybara-timeout_reporter/, /gems\/capybara\//]
7
+ @include_patterns = [/.*/]
8
+
6
9
  class << self
10
+ attr_accessor :exclude_patterns
11
+ attr_accessor :include_patterns
12
+
7
13
  def on_timeout(&block)
8
14
  @block = block
9
15
  end
@@ -11,6 +17,10 @@ module Capybara
11
17
  def report(seconds, src_line)
12
18
  @block.call(seconds, src_line)
13
19
  end
20
+
21
+ def default_wait_time
22
+ Capybara.respond_to?(:default_max_wait_time) ? Capybara.default_max_wait_time : Capybara.default_wait_time
23
+ end
14
24
  end
15
25
 
16
26
  on_timeout do |seconds, src_line|
@@ -20,14 +30,21 @@ module Capybara
20
30
 
21
31
  module Node
22
32
  class Base
23
- def synchronize_with_warning(seconds=Capybara.default_max_wait_time, options = {}, &block)
33
+ def synchronize_with_warning(seconds=Capybara::TimeoutReporter.default_wait_time, options = {}, &block)
24
34
  start_time = Time.now
25
35
  synchronize_without_warning(seconds, options, &block)
26
36
  rescue Capybara::ElementNotFound => e
27
37
  if Time.now-start_time > seconds
28
- trace_line = Thread.current.backtrace.find { |l| !l.include?('gems/capybara') }
29
- src_line = trace_line.match(/(.*):.*/).captures.first
30
- Capybara::TimeoutReporter.report(seconds, src_line)
38
+ backtrace = Thread.current.backtrace
39
+ Capybara::TimeoutReporter.exclude_patterns.each do |pattern|
40
+ backtrace.reject! { |line| line =~ pattern }
41
+ end
42
+ backtrace.select! do |line|
43
+ Capybara::TimeoutReporter.include_patterns.any? { |pattern| (line =~ pattern) }
44
+ end
45
+ trace_line = backtrace.length > 0 ? backtrace[0] : nil
46
+ src_line = trace_line ? trace_line.match(/(.*):.*/).captures.first : "Can't find line that matches the pattern"
47
+ Capybara::TimeoutReporter.report(seconds, src_line) if src_line
31
48
  end
32
49
  raise e
33
50
  end
@@ -36,4 +53,4 @@ module Capybara
36
53
  alias_method :synchronize, :synchronize_with_warning
37
54
  end
38
55
  end
39
- end
56
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capybara-timeout_reporter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vitalii Grygoruk
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-16 00:00:00.000000000 Z
11
+ date: 2015-11-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler