poltergeist-screenshot_overview 0.1.8 → 0.2.1

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
  SHA1:
3
- metadata.gz: d55dfe2d1810db2618c72c957dcc8e43a3649fb4
4
- data.tar.gz: e27d5ee0e8469ba9b6ca5ce2a261b6e515a48a39
3
+ metadata.gz: b91cf4b227b7cb2262672190cc89ab4c1ea3e8cc
4
+ data.tar.gz: b38d9f89fe29f258da38b2f991091c25918e03e7
5
5
  SHA512:
6
- metadata.gz: 64af1d99ebddd35de6459781cc9f6b760623497d3877af3a4ee83731792af9c1f5878c763f982fadd2bedc9a50c982620ecdb0d1979dc3fc87006988e1f464ea
7
- data.tar.gz: 6ed18399397448b422c890e78ae209a6f8193ce479d8859e9bd7916751cd2f3817e58a5b277bf10a7b14476ae9420b7563c5fedc73757aad38ec2d18d71d3213
6
+ metadata.gz: 27f3e49938bc7d6f40cef9b5e213c58d3d142eaa86e0c4b1a7c82198363a88c9235070d393db5453c8eeb902fb8743df7d4f1a14030497e2420c56e9b079510b
7
+ data.tar.gz: d940561a9de23b6a0f2d52b344838c2517e51b216047d9255a2efa1b2edd6e5fba7f53480a7cf9d85222391180af5e3e8ec894f439829a6a71fc4b090868041d
@@ -0,0 +1,49 @@
1
+ module Poltergeist::ScreenshotOverview
2
+ module CapybaraPatch
3
+
4
+ extend ActiveSupport::Concern
5
+ included do
6
+
7
+ # @override
8
+ def visit(url)
9
+ with_screenshot(url, page.visit(url))
10
+ end
11
+
12
+ # @override
13
+ def click_button(*args)
14
+ # page.send method, *args, &block
15
+ with_screenshot(args.first, page.click_button(*args))
16
+ end
17
+
18
+ # @override
19
+ def click_link(*args)
20
+ with_screenshot(args.first, page.click_link(*args))
21
+ end
22
+
23
+ # @override
24
+ def click_on(*args)
25
+ with_screenshot(args.first, page.click_on(*args))
26
+ end
27
+ end
28
+
29
+ private
30
+
31
+ def with_screenshot(url, result)
32
+ make_screenshot(url)
33
+ result
34
+ end
35
+
36
+ def make_screenshot(argument)
37
+ if defined?(RSpec.current_example)
38
+ ex = RSpec.current_example
39
+ else
40
+ ex = example
41
+ end
42
+ if ex && (ex.metadata[:js] || ex.metadata[:screenshot])
43
+ filename = Manager.instance.add_image_from_rspec(argument, ex, current_path)
44
+ page.driver.render(Rails.root.join(filename).to_s, full: true)
45
+ end
46
+ end
47
+
48
+ end
49
+ end
@@ -1,7 +1,7 @@
1
1
  require "erb"
2
2
  require "ostruct"
3
3
  module Poltergeist::ScreenshotOverview
4
- class ScreenshotGroup
4
+ class ExampleFile
5
5
  attr_accessor :screenshots, :file_name
6
6
 
7
7
  def initialize(file,screenshots)
@@ -12,6 +12,24 @@ module Poltergeist::ScreenshotOverview
12
12
  def to_id
13
13
  file_name.gsub(/\W+/, "-").gsub(/^-/, "")
14
14
  end
15
+
16
+ def examples
17
+ screenshots.group_by{|i| i.example_description }.map do |_,screenshots|
18
+ Example.new(screenshots)
19
+ end
20
+ end
21
+ end
22
+
23
+ class Example
24
+ attr_accessor :screenshots
25
+ def initialize(screenshots)
26
+ @screenshots = screenshots.sort_by{|i| i.file_with_line }
27
+ end
28
+
29
+ def title
30
+ (screenshots.first.group_description + [screenshots.first.example_description]).join(' >> ')
31
+ end
32
+
15
33
  end
16
34
 
17
35
  class Screenshot
@@ -38,11 +56,11 @@ module Poltergeist::ScreenshotOverview
38
56
  end
39
57
 
40
58
  def snippet
41
- File.read(full_test_path).lines[ line_number - 3, 5].join
59
+ File.read(full_test_path).lines[ line_number - 5, 9].tap{|i| i[4] = ">>" + i[4].gsub(/^ /,'')}.join
42
60
  end
43
61
 
44
62
  def test_file
45
- full_test_path.gsub(Dir.pwd, "").gsub("spec/features/","")
63
+ file_with_line.gsub(Dir.pwd, '').gsub(/:\d+$/,'')
46
64
  end
47
65
 
48
66
  def render
@@ -92,10 +110,11 @@ module Poltergeist::ScreenshotOverview
92
110
  end
93
111
 
94
112
 
95
- def groups
96
- @files.
113
+ def example_files
114
+ @example_files ||=
115
+ @files.
97
116
  group_by{ |screenshot| screenshot.test_file}.
98
- map{|file,screenshots| ScreenshotGroup.new(file,screenshots.sort_by{|s| s.file_with_line }) }
117
+ map{|file,screenshots| ExampleFile.new(file,screenshots.sort_by{|s| s.file_with_line }) }
99
118
  end
100
119
 
101
120
  end
@@ -1,5 +1,11 @@
1
+ require 'capybara'
2
+ # require 'poltergeist'
1
3
  require "poltergeist/screenshot_overview"
2
4
  require "poltergeist/screenshot_overview/manager"
5
+ require "poltergeist/screenshot_overview/capybara_patch"
6
+
7
+ Capybara::DSL.send(:include, Poltergeist::ScreenshotOverview::CapybaraPatch)
8
+
3
9
  RSpec.configure do |config|
4
10
  config.before(:suite) do
5
11
  Poltergeist::ScreenshotOverview::Manager.instance.start
@@ -7,7 +13,4 @@ RSpec.configure do |config|
7
13
  config.after(:suite) do
8
14
  Poltergeist::ScreenshotOverview::Manager.instance.generate_html
9
15
  end
10
-
11
- config.include Poltergeist::ScreenshotOverview, :type => :feature, :js => true
12
-
13
16
  end
@@ -1,5 +1,5 @@
1
1
  module Poltergeist
2
2
  module ScreenshotOverview
3
- VERSION = "0.1.8"
3
+ VERSION = "0.2.1"
4
4
  end
5
5
  end
@@ -20,39 +20,5 @@ module Poltergeist
20
20
  end
21
21
  end
22
22
 
23
- # @override
24
- def visit(*args)
25
- super
26
- make_screenshot(args.first)
27
- end
28
-
29
- # @override
30
- def click_button(*args)
31
- super
32
- make_screenshot(args.first)
33
- end
34
-
35
- # @override
36
- def click_link(*args)
37
- super
38
- make_screenshot(args.first)
39
- end
40
-
41
- def click_on(*args)
42
- super
43
- make_screenshot(args.first)
44
- end
45
-
46
- private
47
-
48
- def make_screenshot(argument)
49
- return if !defined?(RSpec.current_example)
50
- ex = RSpec.current_example
51
- if ex && (ex.metadata[:js] || ex.metadata[:screenshot])
52
- filename = Manager.instance.add_image_from_rspec(argument, ex, current_path)
53
- page.driver.render(Rails.root.join(filename).to_s,full: true)
54
- end
55
- end
56
-
57
23
  end
58
24
  end
data/templates/layout.erb CHANGED
@@ -1,79 +1,90 @@
1
1
  <!DOCTYPE html>
2
2
  <html class="no-js"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
3
3
  <title><%= title %></title>
4
- <meta name="description" content="">
5
- <meta name="viewport" content="width=device-width">
6
- <link href="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/css/bootstrap-combined.min.css" rel="stylesheet">
4
+ <meta name="description" content="">
5
+ <meta name="viewport" content="width=device-width">
6
+ <link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet">
7
7
 
8
- <style type='text/css'>
9
- .screenshot {
10
- margin-bottom: 15px;
11
- padding-bottom: 15px;
12
- border-bottom: 2px solid #aaa;
13
- }
14
- #container {
15
- width: 80%;
16
- margin: 0 auto;
17
- padding: 0 20px;
18
- font-family: Calibri, Candara, Segoe, "Segoe UI", Optima, Arial, sans-serif;
19
- }
20
- #toc {
21
- width: 200px;
22
- background-color: #FFFFFF;
23
- border-radius: 6px 6px 6px 6px;
24
- box-shadow: 0 1px 4px rgba(0, 0, 0, 0.067);
25
- margin: 30px 0 0;
26
- padding: 0;
27
- }
28
- #toc a {
29
- border: 1px solid #E5E5E5;
30
- display: block;
31
- margin: 0 0 -1px;
32
- padding: 8px 14px;
33
- text-shadow: 0 1px 0 rgba(255, 255, 255, 0.5);
34
- }
35
- </style>
8
+ <style type='text/css'>
9
+ .screenshot {
10
+ margin-bottom: 15px;
11
+ padding-bottom: 15px;
12
+ border-bottom: 2px solid #aaa;
13
+ vertical-align: top;
14
+ display: inline-block;
15
+ }
16
+ #container {
17
+ width: 80%;
18
+ margin: 0 auto;
19
+ padding: 0 20px;
20
+ font-family: Calibri, Candara, Segoe, "Segoe UI", Optima, Arial, sans-serif;
21
+ }
22
+ #toc {
23
+ width: 200px;
24
+ background-color: #FFFFFF;
25
+ border-radius: 6px 6px 6px 6px;
26
+ box-shadow: 0 1px 4px rgba(0, 0, 0, 0.067);
27
+ margin: 30px 0 0;
28
+ padding: 0;
29
+ }
30
+ #toc a {
31
+ border: 1px solid #E5E5E5;
32
+ display: block;
33
+ margin: 0 0 -1px;
34
+ padding: 8px 14px;
35
+ text-shadow: 0 1px 0 rgba(255, 255, 255, 0.5);
36
+ }
37
+ </style>
36
38
 
37
- <script type='text/javascript'>
38
- //url = window.location.toString();
39
- //console.log(url)
40
- //if (!/\/$/.test(url)) {
41
- // url = url + '/';
42
- // window.location = url
43
- //}
44
- </script>
39
+ <script type='text/javascript'>
40
+ //url = window.location.toString();
41
+ //console.log(url)
42
+ //if (!/\/$/.test(url)) {
43
+ // url = url + '/';
44
+ // window.location = url
45
+ //}
46
+ </script>
45
47
 
46
48
  </head>
47
49
 
48
50
  <body data-spy="scroll" data-target=".navbar">
51
+ <div class='container-fluid'>
49
52
 
50
- <div id='container' class='row'>
51
- <div class='span10'>
52
- <h1><%= title %></h1>
53
- <% groups.each do |group| %>
54
- <div class='group'>
55
- <h2 id='<%=group.to_id%>'><%= group.file_name %></h2>
56
- <% group.screenshots.each do |screenshot| %>
57
- <%= screenshot.render %>
58
- <% end %>
59
- </div>
60
- <% end %>
61
- </div>
53
+ <div id='container' class='row'>
54
+ <div class='col-sm-8 col-lg-10'>
55
+ <h1><%= title %></h1>
56
+ <% example_files.each do |file| %>
57
+ <div class='group'>
58
+ <h2 id='<%=file.to_id%>'><%= file.file_name %></h2>
59
+ <% file.examples.each do |example| %>
60
+ <h4><%= example.title %></h4>
61
+ <% example.screenshots.each do |screenshot| %>
62
+ <%= screenshot.render %>
63
+ <% end %>
64
+ <% end %>
65
+ </div>
66
+ <% end %>
67
+ </div>
62
68
 
63
- <div class='span2'>
64
- <div class='navbar' id='toc' data-spy="affix" data-offset-top="200">
65
- <ul class='nav nav-list'>
66
- <% groups.each do |group| %>
67
- <li>
68
- <a href='#<%=group.to_id %>'><%= group.file_name %></a>
69
- </li>
70
- <% end %>
69
+ <div class='col-sm-4 col-lg-2'>
70
+ <div class='navbar' id='toc' data-spy="affix" data-offset-top="200">
71
+ <ul class='nav nav-list'>
72
+ <% example_files.each do |group| %>
73
+ <li>
74
+ <a href='#<%=group.to_id %>'><%= group.file_name %></a>
75
+ </li>
76
+ <% end %>
77
+ </div>
78
+ </div>
71
79
  </div>
72
80
  </div>
73
- </div>
74
81
 
75
- <script src="http://code.jquery.com/jquery-1.10.0.min.js"></script>
76
- <script src="http://code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
77
- <script src="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/js/bootstrap.min.js"></script>
78
- </body>
82
+ <script src="http://code.jquery.com/jquery-1.10.0.min.js"></script>
83
+ <script src="http://code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
84
+ <script type='application/javascript' src='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js'></script>
85
+ <link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/8.7/styles/default.min.css">
86
+ <script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/8.7/highlight.min.js"></script>
87
+ <script>hljs.initHighlightingOnLoad();</script>
88
+
89
+ </body>
79
90
  </html>
@@ -1,12 +1,24 @@
1
1
  <div class='screenshot'>
2
- <img src='<%= local_image %>' alt=''/>
3
- <ul>
4
- <li>
5
- <strong><%= group_description.join(" >> ") %> <%= example_description %></strong>
6
- </li>
7
- <li>URL: <code><%= url %></code></li>
8
- <li>clicked on: <code><%= argument %></code></li>
9
- <li><a href='file://<%= file_with_line %>'><%= file_with_line %></a></li>
10
- <code><pre><%= snippet %></pre></code>
11
- </table>
2
+ <% id = 'modal' + Digest::MD5.hexdigest(file_with_line) %>
3
+ <a href='#<%=id%>' data-toggle='modal'>
4
+ <img src='<%= local_image %>' alt='' style='width: 100px'/>
5
+ </a>
6
+
7
+ <div class="modal fade" id='<%=id%>'>
8
+ <div class="modal-dialog modal-lg">
9
+ <div class="modal-content">
10
+ <div class="modal-header">
11
+ <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
12
+ <h3 class='modal-title'><%= group_description.join(" >> ") %> <%= example_description %></h3>
13
+ </div>
14
+ <div class="modal-body">
15
+ <p>URL: <code><%= url %></code></p>
16
+ <p>clicked on: <code><%= argument %></code></p>
17
+ <p><a href='file://<%= file_with_line %>'><%= file_with_line %></a></p>
18
+ <pre><code lang='ruby' class='ruby'><%= snippet %></code></pre>
19
+ <img src='<%= local_image %>' alt='' class='img-responsive'/>
20
+ </div>
21
+ </div>
22
+ </div>
23
+ </div>
12
24
  </div>
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: poltergeist-screenshot_overview
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stefan Wienert
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-23 00:00:00.000000000 Z
11
+ date: 2015-08-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: poltergeist
@@ -66,6 +66,7 @@ files:
66
66
  - README.md
67
67
  - Rakefile
68
68
  - lib/poltergeist/screenshot_overview.rb
69
+ - lib/poltergeist/screenshot_overview/capybara_patch.rb
69
70
  - lib/poltergeist/screenshot_overview/manager.rb
70
71
  - lib/poltergeist/screenshot_overview/rspec.rb
71
72
  - lib/poltergeist/screenshot_overview/version.rb