dom_glancy 0.1.0 → 1.0.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.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.travis.yml +1 -3
  4. data/CHANGELOG.md +5 -0
  5. data/Gemfile +1 -2
  6. data/README.md +69 -2
  7. data/app/assets/javascripts/application.js +7 -1
  8. data/app/assets/stylesheets/dom_glancy.css +19 -3
  9. data/app/controllers/dom_glancy_controller.rb +15 -15
  10. data/app/views/dom_glancy/index.html.erb +15 -10
  11. data/app/views/dom_glancy/path_config.html.erb +3 -3
  12. data/app/views/dom_glancy/show.html.erb +4 -4
  13. data/app/views/layouts/dom_glancy.html.erb +7 -7
  14. data/dom_glancy.gemspec +2 -2
  15. data/lib/dom_glancy/analysis.rb +108 -108
  16. data/lib/dom_glancy/configuration.rb +22 -0
  17. data/lib/dom_glancy/dom_glancy.rb +110 -96
  18. data/lib/dom_glancy/engine.rb +4 -0
  19. data/lib/dom_glancy/locations.rb +10 -43
  20. data/lib/dom_glancy/svg.rb +45 -43
  21. data/lib/dom_glancy/version.rb +1 -1
  22. data/lib/dom_glancy.rb +5 -1
  23. data/test/selenium/mapping_test.rb +14 -14
  24. data/test/selenium/viewer_test.rb +4 -9
  25. data/test/selenium_test_helper.rb +86 -85
  26. data/test/test_app/Gemfile +0 -2
  27. data/test/test_app/Rakefile +3 -0
  28. data/test/test_app/app/views/layouts/local.html.erb +2 -3
  29. data/test/test_app/config/application.rb +29 -0
  30. data/test/test_app/config/boot.rb +6 -0
  31. data/test/test_app/config/environment.rb +2 -0
  32. data/test/test_app/config/initializers/dom_glancy_initializer.rb +8 -4
  33. data/test/test_app/config.ru +2 -29
  34. data/test/test_app/script/rails +6 -0
  35. data/test/test_helper.rb +5 -7
  36. data/test/test_helpers/location_helpers.rb +23 -21
  37. data/test/test_objects/test_objects.rb +40 -42
  38. data/test/unit/analysis_test.rb +9 -10
  39. data/test/unit/{kracker_test.rb → dom_glancy_test.rb} +20 -21
  40. data/test/unit/element_test.rb +8 -8
  41. data/test/unit/location_test.rb +8 -7
  42. metadata +25 -13
  43. data/lib/dom_glancy/rails/engine.rb +0 -7
  44. data/test/test_app/config/database.yml +0 -13
  45. data/test/test_app/test_app.rb +0 -30
  46. data/test/test_helpers/kracker_class_for_stubbing.rb +0 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2c84851470a93ba9650102b600020afe44d0e015
4
- data.tar.gz: c76baf99580a6abd4080152d24748419bb584dbc
3
+ metadata.gz: 2652a65dec1c5c98ff34e5c08d53fee7f2d37491
4
+ data.tar.gz: f6a4fcfef1372c84781e2af456e85f2c27e79cd1
5
5
  SHA512:
6
- metadata.gz: e2734c33ad4d12c6a97c94b7c683e7e243406c20f7c4e0c14d5da809ee501635f295158c3529d2d3ea76939c78799dfe57ec83a7de161d931a08cf62a2fa78c8
7
- data.tar.gz: ac4244455dc406913eb676a4e9f2c32f9868d1d3175bdf82b602aa0ffe7d78c0f876a76f5cb9f8db5872a7304e6e621d32000f791f1b6996669be636095067ea
6
+ metadata.gz: bfb04f669881c5e6c30f05a4015b93ecfd5f712a207ef02a67b880e297ea9fcf6a0044a4606fc2655d98f07734d84200ee97d640a93dc1c2af37f86fe19ad39a
7
+ data.tar.gz: 066fe6d51d913d860d17b5140a2c43adc8f9275b48eebbb51c3ce387a3579f758213b2cf0208259c72a62acb36aa302277a1951cd66df066ecd332e609a0a8e2
data/.gitignore CHANGED
@@ -19,3 +19,4 @@ tmp
19
19
  *.DS_store
20
20
  test/test_app/log
21
21
  test/test_app/tmp
22
+ test/test_app/db/*.sqlite3
data/.travis.yml CHANGED
@@ -4,12 +4,10 @@ rvm:
4
4
  - "2.0.0"
5
5
  - "2.1.0"
6
6
  - "2.1.2"
7
- env:
8
- - DB=sqlite
9
7
  before_script:
10
8
  - export DISPLAY=:99.0
11
9
  - sh -e /etc/init.d/xvfb start
12
10
  script:
13
11
  - bundle exec rake
14
12
  addons:
15
- firefox: "19.0.1"
13
+ firefox: "31.0"
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## 1.0.0
2
+
3
+ - Change configuration syntax
4
+ - Convert gem to use DomGlancy instances
5
+ - Make page mappings account for scrollbar width by widening browser accordingly
data/Gemfile CHANGED
@@ -10,7 +10,6 @@ gem 'minitest-reporters'
10
10
  gem 'awesome_print'
11
11
  gem 'mocha'
12
12
 
13
- gem 'selenium-webdriver', '2.42.0'
13
+ gem 'selenium-webdriver', '2.44.0'
14
14
  gem 'capybara', '2.2.1'
15
15
  gem 'ae_page_objects', '1.0.0'
16
-
data/README.md CHANGED
@@ -10,7 +10,7 @@ _you know. like taking a quick glance at the DOM, but make it sound kinda like T
10
10
 
11
11
  ## Installation
12
12
 
13
- Add this line to your application's Gemfile:
13
+ Add this line to your application's Gemfile in the test and development groups:
14
14
 
15
15
  gem 'dom_glancy'
16
16
 
@@ -24,7 +24,74 @@ Or install it yourself as:
24
24
 
25
25
  ## Usage
26
26
 
27
- Don't know yet. I'll let you know when i figure something out.
27
+ Using [Capybara](http://jnicklas.github.io/capybara/), visit a page to test. Use dom_glancy's `page_map_same?` to analyze the page.
28
+
29
+ ### Setup
30
+
31
+ Before the current page can be mapped and the comparison performed, the dom_glancy library must be configured with some location parameters:
32
+
33
+ DomGlancy.configure do |c|
34
+ c.master_file_location = '/path/to/master/files'
35
+ c.current_file_location = '/path/to/current/files'
36
+ c.diff_file_location = '/path/to/difference/files'
37
+ end
38
+
39
+ This setup can be done in a test helper; however, if it is done in a rails initializer the helper route `/dom_glancy` is added to the application and can be used to analyze the results and bless files easily.
40
+
41
+ ### Perform Comparison
42
+
43
+ The return value of `page_map_same?('page_name_key')` is an array with the first element being a boolean representing same TRUE or FALSE. the second element is an message describing the differences and a suggestion on what to do next. examples of messages can be found below.
44
+
45
+ def test_responsive
46
+ # do some browser setup so the page is displayed like you want to test.
47
+ # for example, set the browser width to 635.
48
+
49
+ # visit the page however you like. we like PageObjects around here.
50
+
51
+ jack_ryan = DomGlancy::DomGlancy.new
52
+ same, msg = jack_ryan.page_map_same?('page_name_key') # the dom_glancy magic!
53
+
54
+ assert same, msg # use whatever assertion library you like.
55
+
56
+ # interact with the page. maybe expand or edit something.
57
+ same, msg = jack_ryan.page_map_same?('page_name_key__edit')
58
+
59
+ assert same, msg
60
+ end
61
+
62
+ _in both this example and the error messages, the test name of `page_name_key` is used. this string needs to be unique to every test as it is used to look for master files, generate current map files, and produce a difference file at the completion of the comparison._
63
+
64
+ ### Error Messages
65
+
66
+ The following error message would have been returned if the pages were not the same. Specifically, 2 new dom elements were found that were not in the master file, 1 element that was in the master file but not on the current page, and 35 elements were found to have changed from master to current.
67
+
68
+ ------- DOM Comparison Failure ------
69
+ Elements not in master: 2
70
+ Elements not in current: 1
71
+ Changed elements: 35
72
+ Files:
73
+ current: /path/to/current/files/page_name_key.yaml
74
+ master: /path/to/master/files/page_name_key_master.yaml
75
+ difference: /path/to/difference/files/page_name_key_diff.html
76
+ Bless this current data set:
77
+ cp /path/to/current/files/page_name_key.yaml /path/to/master/files/page_name_key_master.yaml
78
+ -------------------------------------
79
+
80
+ The following error message would be returned if there was no master file found matching the test parameters.
81
+
82
+ ------- DOM Comparison Failure ------
83
+ Master file does not exist. To make a new master from
84
+ the current page, use this command:
85
+ cp /path/to/current/files/page_name_key.yaml /path/to/master/files/page_name_key_master.yaml
86
+ -------------------------------------
87
+
88
+ Notice that in both cases there is a line of code that can be used to copy the current map file to the master file location and name it appropriately. in these examples, that line is `cp /path/to/current/maps/page_name_key.yaml /path/to/master/maps/page_name_key_master.yaml`.
89
+
90
+ ### DOM Glancy Visualizer
91
+
92
+ If the dom_glancy gem is included in the application's development environment, then the route `/dom_glancy` can be visited to help deal with new files and test failures.
93
+
94
+ For this to work, the initialization of dom_glancy must be done in an initializer or some other way that is included when the environment is loaded.
28
95
 
29
96
  ## Contributing
30
97
 
@@ -1 +1,7 @@
1
-
1
+ function checkByParent(aId, aChecked) {
2
+ var collection = document.getElementById(aId).getElementsByTagName('INPUT');
3
+ for (var x=0; x<collection.length; x++) {
4
+ if (collection[x].type.toUpperCase()=='CHECKBOX')
5
+ collection[x].checked = aChecked;
6
+ }
7
+ }
@@ -52,15 +52,15 @@ a.kr:active { text-decoration:none; color: #A3906D; }
52
52
  }
53
53
 
54
54
  .kr--ul {
55
+ line-height: 1.8em;
55
56
  list-style-type: none;
56
- padding:0;
57
57
  margin:0;
58
+ padding: 20px 0;
58
59
  }
59
60
 
60
-
61
61
  .kr--dom_review_table td {
62
62
  padding: 1em;
63
- border: 0px solid;
63
+ border: 0 solid;
64
64
  background-color: transparent;
65
65
  vertical-align: top;
66
66
  min-width: 250px;
@@ -132,3 +132,19 @@ a.kr:active { text-decoration:none; color: #A3906D; }
132
132
  padding-left: 7px;
133
133
  padding-right: 7px;
134
134
  }
135
+
136
+ .kr--button {
137
+ font-family: inherit;
138
+ font-size: 100%;
139
+ padding: .5em 1em;
140
+ color: #956C1F;
141
+ border: 1px solid #956C1F;
142
+ background-color: #ffffff;
143
+ text-decoration: none;
144
+ border-radius: 10px;
145
+ }
146
+
147
+ .kr--button-small {
148
+ border-radius: 5px;
149
+ font-size: 75%;
150
+ }
@@ -4,8 +4,8 @@ class DomGlancyController < DomGlancyApplicationController
4
4
  require 'kramdown'
5
5
 
6
6
  def index
7
- @files = if DomGlancy.diff_file_location
8
- Dir[File.join(DomGlancy.diff_file_location, "*_diff.html")].map{|f| File.basename(f)}
7
+ @files = if DomGlancy.configuration.diff_file_location
8
+ Dir[File.join(DomGlancy.configuration.diff_file_location, "*_diff.html")].map{|f| File.basename(f)}
9
9
  else
10
10
  []
11
11
  end
@@ -26,16 +26,16 @@ class DomGlancyController < DomGlancyApplicationController
26
26
  end
27
27
 
28
28
  def new
29
- @files_current = Dir[File.join(DomGlancy.current_file_location, '*.yaml')].map { |f| File.basename(f).gsub('.yaml', '') }
30
- @files_master = Dir[File.join(DomGlancy.master_file_location, '*.yaml')].map { |f| File.basename(f).gsub('.yaml', '') }
29
+ @files_current = Dir[File.join(DomGlancy.configuration.current_file_location, '*.yaml')].map { |f| File.basename(f).gsub('.yaml', '') }
30
+ @files_master = Dir[File.join(DomGlancy.configuration.master_file_location, '*.yaml')].map { |f| File.basename(f).gsub('.yaml', '') }
31
31
 
32
32
  @extra_files = @files_current.select { |f| !@files_master.include?("#{f}_master")}.sort
33
33
  end
34
34
 
35
35
  def make_master
36
36
  test_root = params[:file]
37
- src = DomGlancy.current_filename(test_root)
38
- dst = DomGlancy.master_filename(test_root)
37
+ src = DomGlancy.configuration.current_filename(test_root)
38
+ dst = DomGlancy.configuration.master_filename(test_root)
39
39
  FileUtils.cp src, dst
40
40
 
41
41
  redirect_to '/dom_glancy/new'
@@ -43,7 +43,7 @@ class DomGlancyController < DomGlancyApplicationController
43
43
 
44
44
  def delete_current
45
45
  test_root = params[:file]
46
- src = DomGlancy.current_filename(test_root)
46
+ src = DomGlancy.configuration.current_filename(test_root)
47
47
  FileUtils.rm_rf src
48
48
 
49
49
  redirect_to '/dom_glancy/new'
@@ -81,8 +81,8 @@ class DomGlancyController < DomGlancyApplicationController
81
81
  end
82
82
 
83
83
  def clear
84
- Dir[File.join(DomGlancy.diff_file_location, '*.yaml'), File.join(DomGlancy.diff_file_location, '*.html')].each { |f| FileUtils.rm_rf(f) }
85
- Dir[File.join(DomGlancy.current_file_location, '*.yaml')].each { |f| FileUtils.rm_rf(f) }
84
+ Dir[File.join(DomGlancy.configuration.diff_file_location, '*.yaml'), File.join(DomGlancy.configuration.diff_file_location, '*.html')].each { |f| FileUtils.rm_rf(f) }
85
+ Dir[File.join(DomGlancy.configuration.current_file_location, '*.yaml')].each { |f| FileUtils.rm_rf(f) }
86
86
  redirect_to dom_glancy_path
87
87
  end
88
88
 
@@ -93,16 +93,16 @@ class DomGlancyController < DomGlancyApplicationController
93
93
  blessings.each do |blessing|
94
94
  base_test_name = blessing
95
95
 
96
- src_yaml = DomGlancy.current_filename(base_test_name)
97
- dst_yaml = DomGlancy.master_filename(base_test_name)
96
+ src_yaml = DomGlancy::DomGlancy.current_filename(base_test_name)
97
+ dst_yaml = DomGlancy::DomGlancy.master_filename(base_test_name)
98
98
 
99
99
  FileUtils.cp src_yaml, dst_yaml if File.exist?(src_yaml)
100
100
 
101
101
  if params['delete_on_bless'] == 'true'
102
- files_to_remove = [DomGlancy.diff_filename(base_test_name)]
103
- files_to_remove << File.join(DomGlancy.diff_file_location, blessing + '__current_not_master__diff.yaml')
104
- files_to_remove << File.join(DomGlancy.diff_file_location, blessing + '__master_not_current__diff.yaml')
105
- files_to_remove << File.join(DomGlancy.diff_file_location, blessing + '__changed_master__diff.yaml')
102
+ files_to_remove = [DomGlancy::DomGlancy.diff_filename(base_test_name)]
103
+ files_to_remove << File.join(DomGlancy.configuration.diff_file_location, blessing + '__current_not_master__diff.yaml')
104
+ files_to_remove << File.join(DomGlancy.configuration.diff_file_location, blessing + '__master_not_current__diff.yaml')
105
+ files_to_remove << File.join(DomGlancy.configuration.diff_file_location, blessing + '__changed_master__diff.yaml')
106
106
 
107
107
  files_to_remove.each { |f| FileUtils.rm_rf f }
108
108
  end
@@ -1,12 +1,17 @@
1
1
  <h2>difference files</h2>
2
- <% if @files.length > 0 %>
3
- <p>file location: <%= DomGlancy.diff_file_location %></p>
4
- <% else %>
5
- <p>There were no differences files found.</p>
6
- <% end %>
2
+ <p id="js--file_location">file location: <%= DomGlancy.configuration.diff_file_location %></p>
3
+ <form name="bessing" action="/dom_glancy/bless" method="POST">
4
+ <p id="js--input"><input type="checkbox" name="delete_on_bless" value='true' checked> Remove difference files on blessing</p>
5
+ <input class="kr--button kr--button-small" type="button" value="Check All" onclick="checkByParent('kr--files', true);">
6
+ <input class="kr--button kr--button-small" type="button" value="Uncheck All" onclick="checkByParent('kr--files', false);">
7
7
 
8
- <ul id="kr--files" class="kr--ul">
9
- <% @files.each do |file| %>
10
- <li class="kr--file"><%= link_to file, "/dom_glancy/show/#{file}", :class => 'kr' %></li>
11
- <% end %>
12
- </ul>
8
+ <ul id="kr--files" class="kr--ul">
9
+ <% @files.each_with_index do |file, i| %>
10
+ <li class="kr--file">
11
+ <input type="checkbox" name="option_<%= i %>" value="<%= File.basename(file).gsub('_diff.html', '') %>">
12
+ <%= link_to File.basename(file).gsub('_diff.html', ''), "/dom_glancy/show/#{file}", :class => 'kr' %>
13
+ </li>
14
+ <% end %>
15
+ </ul>
16
+ <input type="submit" value="Bless Selected" class="kr--button">
17
+ </form>
@@ -1,8 +1,8 @@
1
1
  <h2>Path Configuration</h2>
2
2
  <table class="kr">
3
3
  <tbody>
4
- <tr><th>master</th><td id="js-config_master"><%= DomGlancy.master_file_location %></td></tr>
5
- <tr><th>current</th><td id="js-config_current"><%= DomGlancy.current_file_location %></td></tr>
6
- <tr><th>diff</th><td id="js-config_diffs"><%= DomGlancy.diff_file_location %></td></tr>
4
+ <tr><th>master</th><td id="js-config_master"><%= DomGlancy.configuration.master_file_location %></td></tr>
5
+ <tr><th>current</th><td id="js-config_current"><%= DomGlancy.configuration.current_file_location %></td></tr>
6
+ <tr><th>diff</th><td id="js-config_diffs"><%= DomGlancy.configuration.diff_file_location %></td></tr>
7
7
  </tbody>
8
8
  </table>
@@ -7,20 +7,20 @@
7
7
  <table class="kr--dom_review_table">
8
8
  <tr>
9
9
  <td>
10
- <% contents = File.read(File.join(DomGlancy.diff_file_location, "#{@file_diff}")) %>
10
+ <% contents = File.read(File.join(DomGlancy.configuration.diff_file_location, "#{@file_diff}")) %>
11
11
  <%= raw(contents) %>
12
12
  </td>
13
13
  <td>
14
14
  <h2>in current dom, not master</h2>
15
- <% elements = YAML::load_file(File.join(DomGlancy.diff_file_location, @file_set_not_master)) %>
15
+ <% elements = YAML::load_file(File.join(DomGlancy.configuration.diff_file_location, @file_set_not_master)) %>
16
16
  <%= render :partial => "shared/dom_set", :locals => {:elements => elements, :finder_id => 'js--not_master'} %>
17
17
 
18
18
  <h2>in master dom, not current</h2>
19
- <% elements = YAML::load_file(File.join(DomGlancy.diff_file_location, @file_set_not_current)) %>
19
+ <% elements = YAML::load_file(File.join(DomGlancy.configuration.diff_file_location, @file_set_not_current)) %>
20
20
  <%= render :partial => "shared/dom_set", :locals => {:elements => elements, :finder_id => 'js--not_current'} %>
21
21
 
22
22
  <h2>changed</h2>
23
- <% elements = YAML::load_file(File.join(DomGlancy.diff_file_location, @file_set_changed)) %>
23
+ <% elements = YAML::load_file(File.join(DomGlancy.configuration.diff_file_location, @file_set_changed)) %>
24
24
  <%= render :partial => "shared/dom_set", :locals => {:elements => elements, :finder_id => 'js--changed'} %>
25
25
 
26
26
  </td>
@@ -3,13 +3,13 @@
3
3
  <head>
4
4
  <title>DOM Glancy</title>
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
6
-
7
- <%= stylesheet_link_tag "noramlize.css", :media => "all" %>
8
- <%= stylesheet_link_tag "720_grid.css", :media => "screen and (min-width: 720px)" %>
9
- <%= stylesheet_link_tag "986_grid.css", :media => "screen and (min-width: 986px)" %>
10
- <%= stylesheet_link_tag "1236_grid.css", :media => "screen and (min-width: 1236px)" %>
11
-
12
- <%= stylesheet_link_tag "dom_glancy", :media => "all" %>
6
+ <%= javascript_include_tag 'application'
7
+ %>
8
+ <%= stylesheet_link_tag 'normalize.css', :media => 'all' %>
9
+ <%= stylesheet_link_tag '720_grid.css', :media => 'screen and (min-width: 720px)' %>
10
+ <%= stylesheet_link_tag '986_grid.css', :media => 'screen and (min-width: 986px)' %>
11
+ <%= stylesheet_link_tag '1236_grid.css', :media => 'screen and (min-width: 1236px)' %>
12
+ <%= stylesheet_link_tag 'dom_glancy', :media => 'all' %>
13
13
 
14
14
  <%= csrf_meta_tags %>
15
15
  </head>
data/dom_glancy.gemspec CHANGED
@@ -21,6 +21,6 @@ Gem::Specification.new do |spec|
21
21
  spec.add_development_dependency "bundler", "~> 1.3"
22
22
  spec.add_development_dependency "rake"
23
23
 
24
- spec.add_dependency(%q<kramdown>, ["~> 1.1.0"])
25
- spec.add_dependency 'capybara'
24
+ spec.add_dependency 'kramdown', '~> 1.1.0'
25
+ spec.add_dependency 'capybara', ['>= 1.0', '< 3']
26
26
  end
@@ -1,141 +1,141 @@
1
1
  module DomGlancy
2
+ class DomGlancy
3
+ def analyze(master_data, current_data, test_root = nil)
4
+ output_hash = {}
2
5
 
3
- def analyze(master_data, current_data, test_root = nil)
4
- output_hash = {}
6
+ master_set = master_data.to_set
7
+ current_set = current_data.to_set
5
8
 
6
- master_set = master_data.to_set
7
- current_set = current_data.to_set
9
+ set_current_not_master = current_set - master_set
10
+ set_master_not_current = master_set - current_set
11
+ set_changed_master = Set.new
8
12
 
9
- set_current_not_master = current_set - master_set
10
- set_master_not_current = master_set - current_set
11
- set_changed_master = Set.new
13
+ changed_element_pairs = []
14
+ if set_master_not_current.count > 0 || set_current_not_master.count > 0
12
15
 
13
- changed_element_pairs = []
14
- if set_master_not_current.count > 0 || set_current_not_master.count > 0
16
+ ok_pairs = pairs_that_are_close_enough(set_current_not_master, set_master_not_current)
15
17
 
16
- ok_pairs = pairs_that_are_close_enough(set_current_not_master, set_master_not_current)
17
-
18
- ok_pairs.each do |item1, item2|
19
- set_current_not_master.delete(item1)
20
- set_master_not_current.delete(item2)
21
- end
18
+ ok_pairs.each do |item1, item2|
19
+ set_current_not_master.delete(item1)
20
+ set_master_not_current.delete(item2)
21
+ end
22
22
 
23
- changed_element_pairs = get_set_of_same_but_different(set_current_not_master, set_master_not_current)
23
+ changed_element_pairs = get_set_of_same_but_different(set_current_not_master, set_master_not_current)
24
24
 
25
- changed_element_pairs.each do |item1, item2|
26
- set_current_not_master.delete(item1)
27
- set_current_not_master.delete(item2)
25
+ changed_element_pairs.each do |item1, item2|
26
+ set_current_not_master.delete(item1)
27
+ set_current_not_master.delete(item2)
28
28
 
29
- set_master_not_current.delete(item1)
30
- set_master_not_current.delete(item2)
31
- end
29
+ set_master_not_current.delete(item1)
30
+ set_master_not_current.delete(item2)
31
+ end
32
32
 
33
- changed_element_pairs.select!{ |pair| !DOMElement.new(pair[0]).close_enough?(DOMElement.new(pair[1])) }
34
- changed_element_pairs.each do |pair|
35
- set_changed_master.add(pair.first)
33
+ changed_element_pairs.select!{ |pair| !DOMElement.new(pair[0]).close_enough?(DOMElement.new(pair[1])) }
34
+ changed_element_pairs.each do |pair|
35
+ set_changed_master.add(pair.first)
36
+ end
36
37
  end
37
- end
38
38
 
39
- all_same = set_current_not_master.count == 0 && set_master_not_current.count == 0 && changed_element_pairs.count == 0
39
+ all_same = set_current_not_master.count == 0 && set_master_not_current.count == 0 && changed_element_pairs.count == 0
40
40
 
41
- create_diff_file(set_current_not_master, set_master_not_current, set_changed_master, test_root) if test_root && !all_same
41
+ create_diff_file(set_current_not_master, set_master_not_current, set_changed_master, test_root) if test_root && !all_same
42
42
 
43
- output_hash[:not_in_master] = set_current_not_master
44
- output_hash[:not_in_current] = set_master_not_current
45
- output_hash[:changed_element_pairs] = changed_element_pairs
46
- output_hash[:same] = all_same
47
- output_hash[:test_root] = test_root
48
- output_hash
49
- end
50
-
51
- def make_svg(set_master_not_current, set_current_not_master, set_changed_master)
52
- js_id = 0
53
- set_master_not_current.each do |item|
54
- item[:js_id] = js_id
55
- js_id += 1
56
- end
57
- set_current_not_master.each do |item|
58
- item[:js_id] = js_id
59
- js_id += 1
60
- end
61
- set_changed_master.each do |item|
62
- item[:js_id] = js_id
63
- js_id += 1
43
+ output_hash[:not_in_master] = set_current_not_master
44
+ output_hash[:not_in_current] = set_master_not_current
45
+ output_hash[:changed_element_pairs] = changed_element_pairs
46
+ output_hash[:same] = all_same
47
+ output_hash[:test_root] = test_root
48
+ output_hash
64
49
  end
65
50
 
66
- rectangles = set_current_not_master.map { |item| item.merge(format__not_in_master) }
67
- rectangles << set_master_not_current.map { |item| item.merge(format__not_in_current) }
68
- rectangles << set_changed_master.map { |item| item.merge(format__same_but_different) }
69
- rectangles.flatten!
51
+ def make_svg(set_master_not_current, set_current_not_master, set_changed_master)
52
+ js_id = 0
53
+ set_master_not_current.each do |item|
54
+ item[:js_id] = js_id
55
+ js_id += 1
56
+ end
57
+ set_current_not_master.each do |item|
58
+ item[:js_id] = js_id
59
+ js_id += 1
60
+ end
61
+ set_changed_master.each do |item|
62
+ item[:js_id] = js_id
63
+ js_id += 1
64
+ end
70
65
 
71
- generate_svg(rectangles)
72
- end
66
+ rectangles = set_current_not_master.map { |item| item.merge(format__not_in_master) }
67
+ rectangles << set_master_not_current.map { |item| item.merge(format__not_in_current) }
68
+ rectangles << set_changed_master.map { |item| item.merge(format__same_but_different) }
69
+ rectangles.flatten!
73
70
 
74
- def create_diff_file(set_current_not_master, set_master_not_current, set_changed_master, test_root)
75
- filename = DomGlancy.diff_filename(test_root)
76
- svg = make_svg(set_current_not_master, set_master_not_current, set_changed_master)
77
- File.open(filename, 'w') { |file| file.write(svg) }
78
- save_set_info(test_root, 'current_not_master', set_current_not_master)
79
- save_set_info(test_root, 'master_not_current', set_master_not_current)
80
- save_set_info(test_root, 'changed_master', set_changed_master)
81
- end
71
+ generate_svg(rectangles)
72
+ end
82
73
 
83
- def save_set_info(test_root, suffix, data_set)
84
- filename = File.join(DomGlancy.diff_file_location, "#{test_root}__#{suffix}__diff.yaml")
74
+ def create_diff_file(set_current_not_master, set_master_not_current, set_changed_master, test_root)
75
+ filename = DomGlancy.diff_filename(test_root)
76
+ svg = make_svg(set_current_not_master, set_master_not_current, set_changed_master)
77
+ File.open(filename, 'w') { |file| file.write(svg) }
78
+ save_set_info(test_root, 'current_not_master', set_current_not_master)
79
+ save_set_info(test_root, 'master_not_current', set_master_not_current)
80
+ save_set_info(test_root, 'changed_master', set_changed_master)
81
+ end
85
82
 
86
- data_array = data_set.to_a
83
+ def save_set_info(test_root, suffix, data_set)
84
+ filename = File.join(::DomGlancy.configuration.diff_file_location, "#{test_root}__#{suffix}__diff.yaml")
87
85
 
88
- File.open(filename, 'w') { |file| file.write(data_array.to_yaml) }
89
- end
86
+ data_array = data_set.to_a
87
+
88
+ File.open(filename, 'w') { |file| file.write(data_array.to_yaml) }
89
+ end
90
90
 
91
- def get_set_of_same_but_different(set1, set2)
92
- same_but_different_pairs = []
93
- set1.each do |item1|
94
- element1 = DOMElement.new(item1)
95
- set2.each do |item2|
96
- element2 = DOMElement.new(item2)
97
- if element1.same_element?(element2)
98
- same_but_different_pairs << [item1, item2] #unless element1.close_enough?(element2)
91
+ def get_set_of_same_but_different(set1, set2)
92
+ same_but_different_pairs = []
93
+ set1.each do |item1|
94
+ element1 = DOMElement.new(item1)
95
+ set2.each do |item2|
96
+ element2 = DOMElement.new(item2)
97
+ if element1.same_element?(element2)
98
+ same_but_different_pairs << [item1, item2] #unless element1.close_enough?(element2)
99
+ end
99
100
  end
100
101
  end
102
+ same_but_different_pairs
101
103
  end
102
- same_but_different_pairs
103
- end
104
104
 
105
- def pairs_that_are_close_enough(set1, set2)
106
- ok_pairs = []
107
- set1.each do |item1|
108
- element1 = DOMElement.new(item1)
109
- set2.each do |item2|
110
- element2 = DOMElement.new(item2)
111
- if element1.same_element?(element2) && element1.close_enough?(element2)
112
- ok_pairs << [item1, item2]
105
+ def pairs_that_are_close_enough(set1, set2)
106
+ ok_pairs = []
107
+ set1.each do |item1|
108
+ element1 = DOMElement.new(item1)
109
+ set2.each do |item2|
110
+ element2 = DOMElement.new(item2)
111
+ if element1.same_element?(element2) && element1.close_enough?(element2)
112
+ ok_pairs << [item1, item2]
113
+ end
113
114
  end
114
115
  end
116
+ ok_pairs
115
117
  end
116
- ok_pairs
117
- end
118
118
 
119
- def make_analysis_failure_report(analysis_data)
120
- return '' if analysis_data[:same]
121
-
122
- msg = ["\n------- DOM Comparison Failure ------"]
123
- msg << "Elements not in master: #{analysis_data[:not_in_master].count}"
124
- msg << "Elements not in current: #{analysis_data[:not_in_current].count}"
125
- msg << "Changed elements: #{analysis_data[:changed_element_pairs].count}"
126
- msg << "Files:"
127
- msg << "\tcurrent: #{DomGlancy.current_filename(analysis_data[:test_root])}"
128
- msg << "\tmaster: #{DomGlancy.master_filename(analysis_data[:test_root])}"
129
- msg << "\tdifference: #{DomGlancy.diff_filename(analysis_data[:test_root])}"
130
- msg << "Bless this current data set:"
131
- msg << "\t#{blessing_copy_string(analysis_data[:test_root])}"
132
- msg<< "-------------------------------------"
133
-
134
- msg.join("\n")
135
- end
119
+ def make_analysis_failure_report(analysis_data)
120
+ return '' if analysis_data[:same]
121
+
122
+ msg = ["\n------- DOM Comparison Failure ------"]
123
+ msg << "Elements not in master: #{analysis_data[:not_in_master].count}"
124
+ msg << "Elements not in current: #{analysis_data[:not_in_current].count}"
125
+ msg << "Changed elements: #{analysis_data[:changed_element_pairs].count}"
126
+ msg << "Files:"
127
+ msg << "\tcurrent: #{DomGlancy.current_filename(analysis_data[:test_root])}"
128
+ msg << "\tmaster: #{DomGlancy.master_filename(analysis_data[:test_root])}"
129
+ msg << "\tdifference: #{DomGlancy.diff_filename(analysis_data[:test_root])}"
130
+ msg << "Bless this current data set:"
131
+ msg << "\t#{blessing_copy_string(analysis_data[:test_root])}"
132
+ msg<< "-------------------------------------"
133
+
134
+ msg.join("\n")
135
+ end
136
136
 
137
- def blessing_copy_string(test_root)
138
- "cp #{DomGlancy.current_filename(test_root)} #{DomGlancy.master_filename(test_root)}"
137
+ def blessing_copy_string(test_root)
138
+ "cp #{DomGlancy.current_filename(test_root)} #{DomGlancy.master_filename(test_root)}"
139
+ end
139
140
  end
140
-
141
141
  end
@@ -0,0 +1,22 @@
1
+ module DomGlancy
2
+ class << self
3
+ attr_accessor :configuration
4
+ end
5
+
6
+ def self.configure
7
+ self.configuration ||= Configuration.new
8
+ yield(configuration)
9
+ end
10
+
11
+ class Configuration
12
+ attr_accessor :master_file_location
13
+ attr_accessor :diff_file_location
14
+ attr_accessor :current_file_location
15
+
16
+ def initialize
17
+ @master_file_location = nil
18
+ @diff_file_location = nil
19
+ @current_file_location = nil
20
+ end
21
+ end
22
+ end