waterpig 0.5.0 → 0.6.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 +4 -4
- data/lib/waterpig/browser-console-logger.rb +120 -0
- data/lib/waterpig/browser-integration.rb +11 -0
- metadata +20 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2302e9b10ed3f0a42d946396094cf816e4232996
|
4
|
+
data.tar.gz: f4865aa1135e03154302b85d905d66d15bc22c64
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 14ffed5cfb8bdf24a35e61a417b9a973604b15cc07a1a12519485e30f69c185eb265e82632732f3af483c6c59875651a265da229d4602908c07d883acc60e472
|
7
|
+
data.tar.gz: 78cfec302ed71689e329584dd0144e1bd4a055bc4b20a1fc118df966a3fb58e05716c8fab29bac8d757717a555a32ece1b74d46a84ef43c464c38f0a236fbcee
|
@@ -0,0 +1,120 @@
|
|
1
|
+
require 'singleton'
|
2
|
+
module Waterpig
|
3
|
+
class BrowserConsoleLogger
|
4
|
+
include Singleton
|
5
|
+
|
6
|
+
require 'text-table'
|
7
|
+
attr_writer :file
|
8
|
+
attr_accessor :path
|
9
|
+
|
10
|
+
def file
|
11
|
+
@file ||= File.new(path, "w")
|
12
|
+
end
|
13
|
+
|
14
|
+
def emit_header(string)
|
15
|
+
file.write("#{bold(string)}\n")
|
16
|
+
end
|
17
|
+
|
18
|
+
def emit_log(entry)
|
19
|
+
file.write( entry['time'] + "\n")
|
20
|
+
if entry['type'] == 'table'
|
21
|
+
emit_table(entry['value'])
|
22
|
+
else
|
23
|
+
file.write(entry['value'].to_s + "\n\n")
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
# Tables are either a simple hash, or a hash of hashes. See documentation
|
28
|
+
# on emit_simple_table and emit_complex_table.
|
29
|
+
def emit_table(hash)
|
30
|
+
table = Text::Table.new
|
31
|
+
if hash.values.any?{ |val| val.is_a?(Hash) }
|
32
|
+
emit_complex_table(hash, table)
|
33
|
+
else
|
34
|
+
emit_simple_table(hash, table)
|
35
|
+
end
|
36
|
+
@file.write(table.to_s + "\n\n")
|
37
|
+
end
|
38
|
+
|
39
|
+
# Simple hashes emit as a two-column table, with keys making up the index
|
40
|
+
# column:
|
41
|
+
# { a: 1, b: 4, c: 'foo'}
|
42
|
+
#
|
43
|
+
# Will render as:
|
44
|
+
#
|
45
|
+
# +-------+--------+
|
46
|
+
# | index | Values |
|
47
|
+
# +-------+--------+
|
48
|
+
# | a | 1 |
|
49
|
+
# +-------+--------+
|
50
|
+
# | b | 4 |
|
51
|
+
# +-------+--------+
|
52
|
+
# | c | 'foo' |
|
53
|
+
# +-------+--------+
|
54
|
+
def emit_simple_table(hash, table)
|
55
|
+
table.head = [ "index", "values" ]
|
56
|
+
hash.each do | key, val |
|
57
|
+
table.rows << [ key, val ]
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
# When they are a hash of hashes, used as follows:
|
62
|
+
# * The keys of the top-level hashes will be the leftmost column, "index".
|
63
|
+
# * The merged keys of the inner hashes will be the column headers
|
64
|
+
# * The values of the inner hashes will fill the table cells.
|
65
|
+
#
|
66
|
+
# So for example:
|
67
|
+
# { foo: { a: 1, b: 2 },
|
68
|
+
# bar: { a: 5, c: 3 }}
|
69
|
+
#
|
70
|
+
# Will render as:
|
71
|
+
# +-------+---+---+---+
|
72
|
+
# | index | a | b | c |
|
73
|
+
# +-------+---+---+---+
|
74
|
+
# | foo | 1 | 2 | |
|
75
|
+
# +-------+---+---+---+
|
76
|
+
# | bar | 5 | | 3 |
|
77
|
+
# +-------+---+---+---+
|
78
|
+
def emit_complex_table(hash, table)
|
79
|
+
keys = hash.reduce([]){ |memo, arr| memo + arr[1].keys }.uniq
|
80
|
+
table.head = [ "index" ] + keys
|
81
|
+
hash.each do |name, row|
|
82
|
+
table.rows << [ name ] + keys.map{ |key| row.fetch(key, nil)}
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def bold(string)
|
87
|
+
"\e[1m#{string}\e[0m"
|
88
|
+
end
|
89
|
+
|
90
|
+
class << self
|
91
|
+
def configure(config)
|
92
|
+
config.add_setting :waterpig_browser_console_log_path, :default => nil
|
93
|
+
config.add_setting :waterpig_log_browser_console, :default => ENV['LOG_BROWSER_CONSOLE']
|
94
|
+
|
95
|
+
config.before(:suite) do
|
96
|
+
if config.waterpig_log_browser_console
|
97
|
+
config.waterpig_browser_console_log_path ||= Rails.root.join("log/#{Rails.env}_browser_console.log")
|
98
|
+
config.waterpig_clearable_logs << 'test_browser_console'
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
config.after(:each,:type => proc{|value|
|
103
|
+
config.waterpig_log_types && config.waterpig_log_types.include?(value)
|
104
|
+
}) do |example|
|
105
|
+
if config.waterpig_log_browser_console
|
106
|
+
logger = Waterpig::BrowserConsoleLogger.instance
|
107
|
+
logger.path = config.waterpig_browser_console_log_path
|
108
|
+
logger.emit_header "Browser console for #{example.full_description}"
|
109
|
+
console_entries = page.evaluate_script("console.history");
|
110
|
+
console_entries.each do |entry|
|
111
|
+
logger.emit_log(entry)
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
|
120
|
+
end
|
@@ -10,6 +10,7 @@ require 'waterpig/ckeditor-tools'
|
|
10
10
|
require 'waterpig/tinymce-tools'
|
11
11
|
require 'waterpig/browser-tools'
|
12
12
|
require 'waterpig/browser-size'
|
13
|
+
require 'waterpig/browser-console-logger'
|
13
14
|
require 'waterpig/snap-step'
|
14
15
|
|
15
16
|
module Waterpig
|
@@ -56,6 +57,7 @@ RSpec.configure do |config|
|
|
56
57
|
config.add_setting :waterpig_autosnap, :default => ENV['WATERPIG_AUTOSNAP']
|
57
58
|
config.add_setting :waterpig_driver, :default => ENV['CAPYBARA_DRIVER']
|
58
59
|
config.add_setting :waterpig_js_driver, :default => ENV['CAPYBARA_JS_DRIVER']
|
60
|
+
config.add_setting :waterpig_clearable_logs, :default => [ 'test' ]
|
59
61
|
|
60
62
|
config.add_setting :waterpig_browser_sizes, :default => {
|
61
63
|
:mobile => { :width => 320, :height => 480 },
|
@@ -64,10 +66,18 @@ RSpec.configure do |config|
|
|
64
66
|
:desktop => { :width => 1024, :height => 1024 }
|
65
67
|
}
|
66
68
|
|
69
|
+
Waterpig::BrowserConsoleLogger.configure(config)
|
67
70
|
|
68
71
|
config.before(:suite) do
|
69
72
|
Capybara.default_driver = Waterpig.pick_capybara_driver(config.waterpig_driver)
|
70
73
|
Capybara.javascript_driver = Waterpig.pick_capybara_driver(config.waterpig_js_driver)
|
74
|
+
config.waterpig_clearable_logs.each do |logfile|
|
75
|
+
if File.directory?('log')
|
76
|
+
File::open("log/#{logfile}.log", "w") do |log|
|
77
|
+
log.write ""
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
71
81
|
end
|
72
82
|
|
73
83
|
if defined?(Timecop)
|
@@ -87,6 +97,7 @@ RSpec.configure do |config|
|
|
87
97
|
config.include Waterpig::BrowserSize, :type => proc{|value|
|
88
98
|
config.waterpig_browser_size_types && config.waterpig_browser_size_types.include?(value)
|
89
99
|
}
|
100
|
+
|
90
101
|
end
|
91
102
|
|
92
103
|
RSpec.configure do |config|
|
metadata
CHANGED
@@ -1,14 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: waterpig
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Judson Lester
|
8
|
+
- Evan Dorn
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
date:
|
12
|
+
date: 2015-03-17 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: capybara
|
@@ -52,10 +53,25 @@ dependencies:
|
|
52
53
|
- - '>'
|
53
54
|
- !ruby/object:Gem::Version
|
54
55
|
version: '0'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: text-table
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ~>
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: 1.2.3
|
63
|
+
type: :runtime
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ~>
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 1.2.3
|
55
70
|
description: |2
|
56
71
|
Because waterpig is what the scientific name for a capybara translates to, that's why.
|
57
72
|
email:
|
58
73
|
- nyarly@gmail.com
|
74
|
+
- evan@lrdesign.com
|
59
75
|
executables: []
|
60
76
|
extensions: []
|
61
77
|
extra_rdoc_files: []
|
@@ -68,6 +84,7 @@ files:
|
|
68
84
|
- lib/waterpig/deadbeat-connections.rb
|
69
85
|
- lib/waterpig/tinymce-tools.rb
|
70
86
|
- lib/waterpig/browser-integration.rb
|
87
|
+
- lib/waterpig/browser-console-logger.rb
|
71
88
|
- lib/waterpig/poltergeist.rb
|
72
89
|
- lib/waterpig/warning-suppressor.rb
|
73
90
|
- lib/waterpig/snap-step.rb
|
@@ -86,7 +103,7 @@ rdoc_options:
|
|
86
103
|
- --main
|
87
104
|
- doc/README
|
88
105
|
- --title
|
89
|
-
- waterpig-0.
|
106
|
+
- waterpig-0.6.0 Documentation
|
90
107
|
require_paths:
|
91
108
|
- lib/
|
92
109
|
required_ruby_version: !ruby/object:Gem::Requirement
|