kracker 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +21 -0
- data/.ruby-version +1 -0
- data/.travis.yml +14 -0
- data/Gemfile +16 -0
- data/LICENSE.txt +22 -0
- data/README.md +33 -0
- data/Rakefile +23 -0
- data/app/assets/javascripts/application.js +1 -0
- data/app/assets/stylesheets/1236_grid.css +21 -0
- data/app/assets/stylesheets/720_grid.css +33 -0
- data/app/assets/stylesheets/986_grid.css +24 -0
- data/app/assets/stylesheets/kracker.css +134 -0
- data/app/assets/stylesheets/normalize.css +425 -0
- data/app/controllers/kracker_application_controller.rb +8 -0
- data/app/controllers/kracker_controller.rb +114 -0
- data/app/views/kracker/about.html.erb +3 -0
- data/app/views/kracker/artifacts.html.erb +16 -0
- data/app/views/kracker/index.html.erb +12 -0
- data/app/views/kracker/new.html.erb +15 -0
- data/app/views/kracker/path_config.html.erb +8 -0
- data/app/views/kracker/show.html.erb +42 -0
- data/app/views/layouts/kracker.html.erb +32 -0
- data/app/views/shared/_dom_set.html.erb +35 -0
- data/app/views/shared/_kracker_nav.html.erb +8 -0
- data/config/routes.rb +17 -0
- data/kracker.gemspec +27 -0
- data/lib/kracker/analysis.rb +114 -0
- data/lib/kracker/element.rb +92 -0
- data/lib/kracker/kracker.rb +112 -0
- data/lib/kracker/locations.rb +49 -0
- data/lib/kracker/rails/engine.rb +7 -0
- data/lib/kracker/svg.rb +71 -0
- data/lib/kracker/version.rb +3 -0
- data/lib/kracker.rb +7 -0
- data/test/page_objects/kracker/about_page.rb +7 -0
- data/test/page_objects/kracker/artifacts_page.rb +7 -0
- data/test/page_objects/kracker/config_page.rb +19 -0
- data/test/page_objects/kracker/index_page.rb +9 -0
- data/test/page_objects/kracker/local_index_page.rb +7 -0
- data/test/page_objects/kracker/new_page.rb +7 -0
- data/test/page_objects/kracker/show_page.rb +15 -0
- data/test/page_objects/kracker/viewer_page.rb +15 -0
- data/test/page_objects/navigation.rb +34 -0
- data/test/page_objects.rb +13 -0
- data/test/selenium/mapping_test.rb +98 -0
- data/test/selenium/viewer_test.rb +25 -0
- data/test/selenium_test_helper.rb +102 -0
- data/test/test_app/Gemfile +10 -0
- data/test/test_app/app/assets/stylesheets/local_app.css +25 -0
- data/test/test_app/app/controllers/application_controller.rb +2 -0
- data/test/test_app/app/controllers/local_controller.rb +8 -0
- data/test/test_app/app/views/layouts/local.html.erb +14 -0
- data/test/test_app/app/views/local/index.html.erb +45 -0
- data/test/test_app/config/database.yml +13 -0
- data/test/test_app/config/initializers/kracker_initializer.rb +5 -0
- data/test/test_app/config/routes.rb +4 -0
- data/test/test_app/config.ru +31 -0
- data/test/test_app/test_app.rb +30 -0
- data/test/test_helper.rb +41 -0
- data/test/test_helpers/kracker_class_for_stubbing.rb +3 -0
- data/test/test_helpers/location_helpers.rb +29 -0
- data/test/test_objects/test_objects.rb +30 -0
- data/test/unit/analysis_test.rb +87 -0
- data/test/unit/element_test.rb +47 -0
- data/test/unit/kracker_test.rb +79 -0
- data/test/unit/location_test.rb +23 -0
- data/watchr_script.rb +3 -0
- metadata +199 -0
@@ -0,0 +1,34 @@
|
|
1
|
+
module PageObjects
|
2
|
+
class Navigation < ::AePageObjects::Element
|
3
|
+
|
4
|
+
def home!
|
5
|
+
node.find_link('home').click
|
6
|
+
PageObjects::Kracker::IndexPage.new
|
7
|
+
end
|
8
|
+
|
9
|
+
def config!
|
10
|
+
node.find_link('config').click
|
11
|
+
PageObjects::Kracker::ConfigPage.new
|
12
|
+
end
|
13
|
+
|
14
|
+
def new_page!
|
15
|
+
node.find_link('new').click
|
16
|
+
PageObjects::Kracker::NewPage.new
|
17
|
+
end
|
18
|
+
|
19
|
+
def artifacts!
|
20
|
+
node.find_link('artifacts').click
|
21
|
+
PageObjects::Kracker::ArtifactsPage.new
|
22
|
+
end
|
23
|
+
|
24
|
+
def clear_results!
|
25
|
+
node.find_link('clear').click
|
26
|
+
PageObjects::Kracker::IndexPage.new
|
27
|
+
end
|
28
|
+
|
29
|
+
def about!
|
30
|
+
node.find_link('about').click
|
31
|
+
PageObjects::Kracker::AboutPage.new
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,98 @@
|
|
1
|
+
require 'selenium_test_helper'
|
2
|
+
|
3
|
+
class MappingTest < Kracker::SeleniumTestCase
|
4
|
+
|
5
|
+
def test_full_mapping__same
|
6
|
+
visit_index
|
7
|
+
|
8
|
+
map_current_page_and_save_as_master('kracker_index')
|
9
|
+
|
10
|
+
same, msg = page_map_same?('kracker_index')
|
11
|
+
|
12
|
+
assert same, msg
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_mapping__no_master
|
16
|
+
visit_index
|
17
|
+
same, msg = page_map_same?('poop')
|
18
|
+
refute same, msg
|
19
|
+
assert_match 'Master file does not exist', msg, 'the missing master error message'
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_full_mapping__one_added__bless
|
23
|
+
visit_index
|
24
|
+
|
25
|
+
map_current_page_and_save_as_master('kracker_index')
|
26
|
+
|
27
|
+
add_centered_element('Back In Black')
|
28
|
+
|
29
|
+
same, msg = page_map_same?('kracker_index')
|
30
|
+
|
31
|
+
refute same, msg
|
32
|
+
|
33
|
+
index_page = visit_index
|
34
|
+
|
35
|
+
assert_equal 1, index_page.files.count, 'number of difference files'
|
36
|
+
assert_match 'kracker_index_diff.html', index_page.files.first.text, 'file name displayed'
|
37
|
+
|
38
|
+
index_page.files.first.find('a').click
|
39
|
+
show_page = PageObjects::Kracker::ShowPage.new
|
40
|
+
|
41
|
+
assert_equal 1, show_page.not_master.count, 'elements listed as not in master'
|
42
|
+
assert_equal 0, show_page.not_current.count, 'elements listed as not in current'
|
43
|
+
assert_equal 0, show_page.changed.count, 'elements listed as changed'
|
44
|
+
|
45
|
+
assert_artifacts_on_difference('kracker_index')
|
46
|
+
|
47
|
+
index_page = show_page.navigation.clear_results!
|
48
|
+
assert_equal 0, index_page.files.count, 'should be no difference files now'
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_full_mapping__one_missing__bless
|
52
|
+
visit_index
|
53
|
+
|
54
|
+
map_current_page_and_save_as_master('kracker_index')
|
55
|
+
|
56
|
+
remove_about_element
|
57
|
+
|
58
|
+
same, msg = page_map_same?('kracker_index')
|
59
|
+
|
60
|
+
refute same, msg
|
61
|
+
|
62
|
+
index_page = visit_index
|
63
|
+
|
64
|
+
assert_equal 1, index_page.files.count, 'number of difference files'
|
65
|
+
assert_match 'kracker_index_diff.html', index_page.files.first.text, 'file name displayed'
|
66
|
+
|
67
|
+
index_page.files.first.find('a').click
|
68
|
+
show_page = PageObjects::Kracker::ShowPage.new
|
69
|
+
|
70
|
+
assert_equal 0, show_page.not_master.count, 'elements listed as not in master'
|
71
|
+
assert_equal 8, show_page.not_current.count, 'elements listed as not in current'
|
72
|
+
assert_equal 5, show_page.changed.count, 'elements listed as changed'
|
73
|
+
|
74
|
+
assert_artifacts_on_difference('kracker_index')
|
75
|
+
|
76
|
+
index_page = show_page.bless!
|
77
|
+
assert_equal 0, index_page.files.count, 'number of difference files'
|
78
|
+
|
79
|
+
end
|
80
|
+
|
81
|
+
def test_non_kracker_page
|
82
|
+
local_page = PageObjects::Kracker::LocalIndexPage.visit
|
83
|
+
|
84
|
+
map_current_page_and_save_as_master('test_page')
|
85
|
+
|
86
|
+
same, msg = page_map_same?('test_page')
|
87
|
+
|
88
|
+
assert same, msg
|
89
|
+
end
|
90
|
+
|
91
|
+
private
|
92
|
+
|
93
|
+
def map_current_page_and_save_as_master(test_root)
|
94
|
+
map_data = perform_mapping_operation
|
95
|
+
File.open(Kracker.master_filename(test_root), 'w') { |file| file.write(map_data.to_yaml) }
|
96
|
+
end
|
97
|
+
|
98
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'selenium_test_helper'
|
2
|
+
|
3
|
+
class ViewerTest < Kracker::SeleniumTestCase
|
4
|
+
|
5
|
+
def test_navigation
|
6
|
+
index_page = visit_index
|
7
|
+
config_page = index_page.navigation.config!
|
8
|
+
|
9
|
+
assert_equal Kracker.master_file_location.to_s, config_page.master, 'master file location'
|
10
|
+
assert_equal Kracker.current_file_location.to_s, config_page.current, 'current file location'
|
11
|
+
assert_equal Kracker.diff_file_location.to_s, config_page.diffs, 'difference file location'
|
12
|
+
|
13
|
+
new_page = config_page.navigation.new_page!
|
14
|
+
assert page.has_content?('do not have a corresponding master file in the expected file location'), 'new masters page content.'
|
15
|
+
|
16
|
+
artifacts_page = new_page.navigation.artifacts!
|
17
|
+
assert page.has_content?('TeamCity Artifacts'), 'artifacts page needs some content.'
|
18
|
+
|
19
|
+
about_page = artifacts_page.navigation.about!
|
20
|
+
assert page.has_content?('Add this line to your'), 'about page line from README.md'
|
21
|
+
|
22
|
+
index_page = about_page.navigation.home!
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
@@ -0,0 +1,102 @@
|
|
1
|
+
ENV['RAILS_ENV'] = 'test'
|
2
|
+
|
3
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
4
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '.'))
|
5
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..'))
|
6
|
+
|
7
|
+
require 'rubygems'
|
8
|
+
require 'bundler'
|
9
|
+
|
10
|
+
begin
|
11
|
+
Bundler.setup(:default, :development)
|
12
|
+
rescue Bundler::BundlerError => e
|
13
|
+
$stderr.puts e.message
|
14
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
15
|
+
exit e.status_code
|
16
|
+
end
|
17
|
+
|
18
|
+
require 'rails/all'
|
19
|
+
require 'kracker'
|
20
|
+
require 'test_app/test_app'
|
21
|
+
|
22
|
+
require 'minitest/autorun'
|
23
|
+
|
24
|
+
require 'awesome_print'
|
25
|
+
|
26
|
+
require 'capybara'
|
27
|
+
require 'capybara/dsl'
|
28
|
+
require 'capybara/rails'
|
29
|
+
require 'selenium-webdriver'
|
30
|
+
|
31
|
+
require 'page_objects'
|
32
|
+
|
33
|
+
test_objects_location = File.expand_path('../test_objects/*', __FILE__)
|
34
|
+
Dir[test_objects_location].each { |f| require f }
|
35
|
+
|
36
|
+
test_helper_location = File.expand_path('../test_helpers/**/*.rb', __FILE__)
|
37
|
+
Dir[test_helper_location].each { |f| require f }
|
38
|
+
|
39
|
+
Capybara.default_driver = :selenium
|
40
|
+
|
41
|
+
module Kracker
|
42
|
+
class SeleniumTestCase < Minitest::Test
|
43
|
+
include Kracker
|
44
|
+
include Kracker::TestObjects
|
45
|
+
include Kracker::TestHelpers::Location
|
46
|
+
|
47
|
+
include Capybara::DSL
|
48
|
+
|
49
|
+
def setup
|
50
|
+
delete_contents_from_kracker_locations
|
51
|
+
end
|
52
|
+
|
53
|
+
def teardown
|
54
|
+
delete_contents_from_kracker_locations
|
55
|
+
end
|
56
|
+
|
57
|
+
def visit_index
|
58
|
+
PageObjects::Kracker::IndexPage.visit
|
59
|
+
end
|
60
|
+
|
61
|
+
def remove_about_element
|
62
|
+
js = <<-JS
|
63
|
+
var element = document.getElementById('js-kr--nav');
|
64
|
+
element.parentNode.removeChild(element);
|
65
|
+
JS
|
66
|
+
|
67
|
+
page.driver.browser.execute_script(js)
|
68
|
+
end
|
69
|
+
|
70
|
+
def add_centered_element(text_content)
|
71
|
+
js = <<-JS
|
72
|
+
var centeredElement = document.createElement('div');
|
73
|
+
centeredElement.style.textAlign = 'center';
|
74
|
+
centeredElement.style.fontSize = '2em';
|
75
|
+
centeredElement.style.width = '400px';
|
76
|
+
centeredElement.style.marginLeft = 'auto';
|
77
|
+
centeredElement.style.marginRight = 'auto';
|
78
|
+
centeredElement.id = 'hack-element';
|
79
|
+
centeredElement.textContent = '#{text_content}';
|
80
|
+
centeredElement.style.backgroundColor = '#ff0000'
|
81
|
+
document.getElementsByTagName('body')[0].appendChild(centeredElement);
|
82
|
+
JS
|
83
|
+
|
84
|
+
page.driver.browser.execute_script(js)
|
85
|
+
end
|
86
|
+
|
87
|
+
def assert_artifacts_on_difference(test_root)
|
88
|
+
filename = Kracker.diff_filename(test_root)
|
89
|
+
assert File.exists?(filename), "Diff file should exist: #{filename}"
|
90
|
+
|
91
|
+
filename = File.join(Kracker.diff_file_location, "#{test_root}__changed_master__diff.yaml")
|
92
|
+
assert File.exists?(filename), "Changed master file should exist: #{filename}"
|
93
|
+
|
94
|
+
filename = File.join(Kracker.diff_file_location, "#{test_root}__current_not_master__diff.yaml")
|
95
|
+
assert File.exists?(filename), "Current, not master, file should exist: #{filename}"
|
96
|
+
|
97
|
+
filename = File.join(Kracker.diff_file_location, "#{test_root}__master_not_current__diff.yaml")
|
98
|
+
assert File.exists?(filename), "Master, not current, file should exist: #{filename}"
|
99
|
+
end
|
100
|
+
|
101
|
+
end
|
102
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
body {
|
2
|
+
background-color: #c0c0c0;
|
3
|
+
color: #ffff00;
|
4
|
+
}
|
5
|
+
|
6
|
+
table {
|
7
|
+
margin: auto;
|
8
|
+
padding: 20px;
|
9
|
+
color: #ff9933;
|
10
|
+
font-family: Verdana, Arial, Helvetica, sans-serif;
|
11
|
+
border: 1px #ff0000 solid;
|
12
|
+
}
|
13
|
+
|
14
|
+
td {
|
15
|
+
padding: 0 10px 0 20px;
|
16
|
+
text-align: center;
|
17
|
+
}
|
18
|
+
|
19
|
+
.big_text {
|
20
|
+
width: 100%;
|
21
|
+
max-width: 600px;
|
22
|
+
float: right;
|
23
|
+
font-size: 1.5em;
|
24
|
+
font-family: monospace, arial, helvetica, sans-serif;
|
25
|
+
}
|
@@ -0,0 +1,45 @@
|
|
1
|
+
<table>
|
2
|
+
<thead>
|
3
|
+
<tr>
|
4
|
+
<th>name</th>
|
5
|
+
<th>phone</th>
|
6
|
+
<th>address</th>
|
7
|
+
<th>member?</th>
|
8
|
+
</tr>
|
9
|
+
</thead>
|
10
|
+
<tbody>
|
11
|
+
<% 5.times do |i| %>
|
12
|
+
<tr>
|
13
|
+
<td><%= "Person #{i}" %></td>
|
14
|
+
<td><%= "555-1#{i}1#{i}" %></td>
|
15
|
+
<td><%= "#{i}#{i}#{i}#{i} Main St." %></td>
|
16
|
+
<td><%= i % 2 == 0 ? 'yes' : 'no' %></td>
|
17
|
+
</tr>
|
18
|
+
<% end %>
|
19
|
+
</tbody>
|
20
|
+
</table>
|
21
|
+
<h1><%= @data %></h1>
|
22
|
+
<%= form_for '#' do |f| %>
|
23
|
+
<%= f.label :first_name %>:
|
24
|
+
<%= f.text_field :first_name %>
|
25
|
+
<br/>
|
26
|
+
<%= f.label :last_name %>:
|
27
|
+
<%= f.text_field :last_name %>
|
28
|
+
<br/>
|
29
|
+
<%= f.label :comments %>:
|
30
|
+
<%= f.text_area :comments %>
|
31
|
+
<br/>
|
32
|
+
<%= f.label :comment_type %>:
|
33
|
+
<br/>
|
34
|
+
<%= f.label :car %><%= f.radio_button :comment_type, 'car', :checked => true %>
|
35
|
+
<%= f.label :truck %><%= f.radio_button :comment_type, 'truck' %>
|
36
|
+
<%= f.label :bike %><%= f.radio_button :comment_type, 'bike' %>
|
37
|
+
<br/>
|
38
|
+
<%= f.submit%>
|
39
|
+
<% end %>
|
40
|
+
|
41
|
+
<div class="big_text">
|
42
|
+
<p>Hashtag art party trust fund, twee Terry Richardson direct trade mlkshk cornhole pickled Bushwick cardigan kale chips butcher. Polaroid chillwave direct trade, squid American Apparel literally semiotics 90's High Life twee ethical vinyl Odd Future Bushwick. Chillwave scenester authentic, try-hard Neutra pug wayfarers cornhole. Chambray next level wayfarers, ethical mixtape chillwave Etsy pour-over Cosby sweater. Ennui bespoke Echo Park umami banjo, Pinterest gastropub retro paleo next level. Tonx Schlitz stumptown Intelligentsia small batch, pickled roof party literally synth bitters irony. Wayfarers tousled chambray farm-to-table fanny pack, street art Thundercats cornhole fap pickled.</p>
|
43
|
+
<p>Do you need some dummy text? *sigh* Of course you do.</p>
|
44
|
+
<p>I bet you still use Helvetica too…</p>
|
45
|
+
</div>
|
@@ -0,0 +1,5 @@
|
|
1
|
+
Kracker.master_file_location = Rails.root.join('tmp', 'data', 'map', 'masters')
|
2
|
+
Kracker.current_file_location = Rails.root.join('tmp', 'data', 'map', 'current')
|
3
|
+
Kracker.diff_file_location = Rails.root.join('tmp', 'data', 'map', 'diff')
|
4
|
+
|
5
|
+
Kracker.create_comparison_directories
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# This file is used by Rack-based servers to start the application.
|
2
|
+
ENV['RAILS_ENV'] = 'development'
|
3
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
4
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..'))
|
5
|
+
|
6
|
+
require 'rubygems'
|
7
|
+
require 'bundler'
|
8
|
+
|
9
|
+
# Set up gems listed in the Gemfile.
|
10
|
+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __FILE__)
|
11
|
+
|
12
|
+
require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
|
13
|
+
|
14
|
+
begin
|
15
|
+
Bundler.setup(:default, :development)
|
16
|
+
rescue Bundler::BundlerError => e
|
17
|
+
$stderr.puts e.message
|
18
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
19
|
+
exit e.status_code
|
20
|
+
end
|
21
|
+
|
22
|
+
require "action_controller/railtie"
|
23
|
+
require "sprockets/railtie"
|
24
|
+
require 'rails'
|
25
|
+
|
26
|
+
require 'kracker'
|
27
|
+
|
28
|
+
Rails.backtrace_cleaner.remove_silencers!
|
29
|
+
|
30
|
+
require 'test_app'
|
31
|
+
run KrackerApp::Application
|
@@ -0,0 +1,30 @@
|
|
1
|
+
db_name = "kracker_#{Rails.env}"
|
2
|
+
|
3
|
+
`mysql -uroot -e "DROP DATABASE IF EXISTS #{db_name}; CREATE DATABASE IF NOT EXISTS #{db_name};"`
|
4
|
+
|
5
|
+
log_file = File.expand_path(File.join(__FILE__, '..', 'log', '*'))
|
6
|
+
`rm -rf #{log_file}`
|
7
|
+
|
8
|
+
module KrackerApp
|
9
|
+
class Application < Rails::Application
|
10
|
+
config.root = File.expand_path(File.join(__FILE__, '..', '..', 'test_app'))
|
11
|
+
config.eager_load = true
|
12
|
+
config.cache_classes = true
|
13
|
+
config.active_support.deprecation = :stderr
|
14
|
+
|
15
|
+
# Enable the asset pipeline
|
16
|
+
config.assets.enabled = true
|
17
|
+
|
18
|
+
# Configure static asset server for tests with Cache-Control for performance
|
19
|
+
config.serve_static_assets = true
|
20
|
+
config.static_cache_control = "public, max-age=3600"
|
21
|
+
|
22
|
+
# Configure cookies
|
23
|
+
config.secret_token = (('a'..'z').to_a * 2).join
|
24
|
+
config.session_store :cookie_store
|
25
|
+
|
26
|
+
I18n.enforce_available_locales = false
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
KrackerApp::Application.initialize!
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
|
4
|
+
begin
|
5
|
+
Bundler.setup(:default, :development)
|
6
|
+
rescue Bundler::BundlerError => e
|
7
|
+
$stderr.puts e.message
|
8
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
9
|
+
exit e.status_code
|
10
|
+
end
|
11
|
+
|
12
|
+
ENV['RAILS_ENV'] = 'test'
|
13
|
+
|
14
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
15
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '.'))
|
16
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..'))
|
17
|
+
|
18
|
+
require 'awesome_print'
|
19
|
+
|
20
|
+
require 'minitest/autorun'
|
21
|
+
require 'minitest/reporters'
|
22
|
+
Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new
|
23
|
+
|
24
|
+
require 'mocha/setup'
|
25
|
+
|
26
|
+
require File.expand_path('../../lib/kracker', __FILE__)
|
27
|
+
|
28
|
+
test_objects_location = File.expand_path('../test_objects/*', __FILE__)
|
29
|
+
Dir[test_objects_location].each { |f| require f }
|
30
|
+
|
31
|
+
test_helper_location = File.expand_path('../test_helpers/**/*.rb', __FILE__)
|
32
|
+
Dir[test_helper_location].each { |f| require f }
|
33
|
+
|
34
|
+
module Kracker
|
35
|
+
class KrackerTestCase < Minitest::Test
|
36
|
+
include Kracker
|
37
|
+
include Kracker::TestObjects
|
38
|
+
include Kracker::TestHelpers::Location
|
39
|
+
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Kracker
|
2
|
+
module TestHelpers
|
3
|
+
module Location
|
4
|
+
|
5
|
+
def prep_locations_for_test
|
6
|
+
@locations_root = File.expand_path('../../tmp', __FILE__)
|
7
|
+
|
8
|
+
Kracker.master_file_location = File.join(@locations_root, 'masters')
|
9
|
+
Kracker.current_file_location = File.join(@locations_root, 'current')
|
10
|
+
Kracker.diff_file_location = File.join(@locations_root, 'diff')
|
11
|
+
|
12
|
+
Kracker.create_comparison_directories
|
13
|
+
end
|
14
|
+
|
15
|
+
def delete_test_locations
|
16
|
+
FileUtils.rm_rf Kracker.master_file_location
|
17
|
+
FileUtils.rm_rf Kracker.current_file_location
|
18
|
+
FileUtils.rm_rf Kracker.diff_file_location
|
19
|
+
end
|
20
|
+
|
21
|
+
def delete_contents_from_kracker_locations
|
22
|
+
Dir[File.join(Kracker.master_file_location, "*.yaml")].each { |file| FileUtils.rm_rf file }
|
23
|
+
Dir[File.join(Kracker.current_file_location, "*.yaml")].each { |file| FileUtils.rm_rf file }
|
24
|
+
Dir[File.join(Kracker.diff_file_location, "*.html")].each { |file| FileUtils.rm_rf file }
|
25
|
+
Dir[File.join(Kracker.diff_file_location, "*.yaml")].each { |file| FileUtils.rm_rf file }
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Kracker
|
2
|
+
module TestObjects
|
3
|
+
def array_of_elements
|
4
|
+
[
|
5
|
+
{"id"=>"1", "height"=>238, "visible"=>true, "tag"=>"DIV", "width"=>720, "class"=>"grid", "left"=>43, "top"=>14},
|
6
|
+
{"id"=>"2", "height"=>132, "visible"=>true, "tag"=>"DIV", "width"=>700, "class"=>"row", "left"=>53, "top"=>14},
|
7
|
+
{"id"=>"3", "height"=>132, "visible"=>true, "tag"=>"DIV", "width"=>340, "class"=>"slot-0-1-2 mm--title_text_main", "left"=>53, "top"=>14},
|
8
|
+
{"id"=>"4", "height"=>132, "visible"=>true, "tag"=>"H1", "width"=>340, "class"=>"", "left"=>53, "top"=>14},
|
9
|
+
{"id"=>"5", "height"=>0, "visible"=>true, "tag"=>"SPAN", "width"=>0, "class"=>"mm--title_text_sub", "left"=>71, "top"=>86},
|
10
|
+
{"id"=>"6", "height"=>55, "visible"=>true, "tag"=>"DIV", "width"=>700, "class"=>"row", "left"=>53, "top"=>160},
|
11
|
+
{"id"=>"7", "height"=>55, "visible"=>true, "tag"=>"DIV", "width"=>340, "class"=>"slot-0-1-2", "left"=>53, "top"=>160},
|
12
|
+
{"id"=>"8", "height"=>55, "visible"=>true, "tag"=>"H2", "width"=>340, "class"=>"", "left"=>53, "top"=>160},
|
13
|
+
{"id"=>"9", "height"=>23, "visible"=>true, "tag"=>"DIV", "width"=>700, "class"=>"row", "left"=>53, "top"=>229},
|
14
|
+
{"id"=>"10", "height"=>21, "visible"=>true, "tag"=>"DIV", "width"=>100, "class"=>"slot-0 mm--nav", "left"=>53, "top"=>231},
|
15
|
+
{"id"=>"11", "height"=>21, "visible"=>true, "tag"=>"DIV", "width"=>100, "class"=>"slot-1 mm--nav", "left"=>173, "top"=>231}
|
16
|
+
]
|
17
|
+
end
|
18
|
+
|
19
|
+
def array_of_elements_small
|
20
|
+
[
|
21
|
+
{"id"=>"12", "height"=>238, "visible"=>true, "tag"=>"DIV", "width"=>720, "class"=>"grid", "left"=>43, "top"=>14},
|
22
|
+
{"id"=>"14", "height"=>0, "visible"=>true, "tag"=>"SPAN", "width"=>0, "class"=>"mm--title_text_sub", "left"=>71, "top"=>86}
|
23
|
+
]
|
24
|
+
end
|
25
|
+
|
26
|
+
def single_element_hash
|
27
|
+
{"id"=>"mm--single_added", "height"=>10, "visible"=>true, "tag"=>"SPAN", "width"=>50, "class"=>"mm--title_text_sub", "left"=>71, "top"=>86}
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class AnalysisTest < Kracker::KrackerTestCase
|
4
|
+
|
5
|
+
def test_same_elements
|
6
|
+
|
7
|
+
master_data = array_of_elements
|
8
|
+
current_data = array_of_elements
|
9
|
+
|
10
|
+
analysis = analyze(master_data, current_data)
|
11
|
+
|
12
|
+
assert_equal 0, analysis[:not_in_master].count, 'results of data analysis: not_in_master'
|
13
|
+
assert_equal 0, analysis[:not_in_current].count, 'results of data analysis: not_in_current'
|
14
|
+
assert analysis[:same], 'results of data analysis.same'
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_one_id_different
|
18
|
+
master_data = array_of_elements_small
|
19
|
+
current_data = array_of_elements_small
|
20
|
+
current_data.first['id'] = 'some-new-id'
|
21
|
+
|
22
|
+
analysis = analyze(master_data, current_data)
|
23
|
+
|
24
|
+
assert_equal 1, analysis[:not_in_master].count, 'results of data analysis: not_in_master'
|
25
|
+
assert_equal 1, analysis[:not_in_current].count, 'results of data analysis: not_in_current'
|
26
|
+
refute analysis[:same], 'results of data analysis.same'
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_one_new_element
|
30
|
+
master_data = array_of_elements
|
31
|
+
current_data = array_of_elements
|
32
|
+
current_data << single_element_hash
|
33
|
+
|
34
|
+
analysis = analyze(master_data, current_data)
|
35
|
+
|
36
|
+
assert_equal 1, analysis[:not_in_master].count, 'results of data analysis: not_in_master'
|
37
|
+
assert_equal 0, analysis[:not_in_current].count, 'results of data analysis: not_in_current'
|
38
|
+
refute analysis[:same], 'results of data analysis.same'
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_two_changed
|
42
|
+
master_data = array_of_elements
|
43
|
+
current_data = array_of_elements
|
44
|
+
current_data[0]['height'] = current_data[0]['height'] + 13
|
45
|
+
current_data[1]['width'] = current_data[1]['width'] + 25
|
46
|
+
|
47
|
+
analysis = analyze(master_data, current_data)
|
48
|
+
|
49
|
+
assert_equal 0, analysis[:not_in_master].count, 'results of data analysis: not_in_master'
|
50
|
+
assert_equal 0, analysis[:not_in_current].count, 'results of data analysis: not_in_current'
|
51
|
+
assert_equal 2, analysis[:changed_element_pairs].count, 'changed element pairs'
|
52
|
+
refute analysis[:same], 'results of data analysis.same'
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_one_changed_less_than_similarity_factor
|
57
|
+
master_data = array_of_elements
|
58
|
+
current_data = array_of_elements
|
59
|
+
|
60
|
+
current_data[1]['height'] = current_data[1]['height'] + 3
|
61
|
+
|
62
|
+
analysis = analyze(master_data, current_data)
|
63
|
+
|
64
|
+
assert_equal 0, analysis[:not_in_master].count, 'results of data analysis: not_in_master'
|
65
|
+
assert_equal 0, analysis[:not_in_current].count, 'results of data analysis: not_in_current'
|
66
|
+
assert_equal 0, analysis[:changed_element_pairs].count, 'changed element pairs'
|
67
|
+
assert analysis[:same], 'results of data analysis.same'
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_one_changed_one_missing_one_added
|
71
|
+
master_data = array_of_elements
|
72
|
+
current_data = array_of_elements
|
73
|
+
|
74
|
+
current_data[0]['height'] = current_data[0]['height'] + 13 ## the one changed (by more than similarity factor)
|
75
|
+
current_data[1]['height'] = current_data[1]['height'] + 3 ## the one changed (by less than similarity factor and therefor not counted)
|
76
|
+
current_data.delete_at(5) ## the one missing
|
77
|
+
current_data << single_element_hash ## the one added
|
78
|
+
|
79
|
+
analysis = analyze(master_data, current_data)
|
80
|
+
|
81
|
+
assert_equal 1, analysis[:not_in_master].count, 'results of data analysis: not_in_master'
|
82
|
+
assert_equal 1, analysis[:not_in_current].count, 'results of data analysis: not_in_current'
|
83
|
+
assert_equal 1, analysis[:changed_element_pairs].count, 'changed element pairs'
|
84
|
+
refute analysis[:same], 'results of data analysis.same'
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|