ojo 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +16 -0
  3. data/.ruby-version +1 -0
  4. data/.travis.yml +3 -0
  5. data/Gemfile +14 -0
  6. data/LICENSE.txt +22 -0
  7. data/README.md +106 -0
  8. data/Rakefile +19 -0
  9. data/lib/ojo/comparison.rb +88 -0
  10. data/lib/ojo/locations.rb +26 -0
  11. data/lib/ojo/output.rb +90 -0
  12. data/lib/ojo/rails/engine.rb +6 -0
  13. data/lib/ojo/screenshot.rb +21 -0
  14. data/lib/ojo/version.rb +3 -0
  15. data/lib/ojo.rb +13 -0
  16. data/lib/tasks/ojo.rake +59 -0
  17. data/ojo.gemspec +28 -0
  18. data/test/page_objects/test_app/index_page.rb +8 -0
  19. data/test/page_objects/test_app/test_app_page.rb +6 -0
  20. data/test/page_objects.rb +13 -0
  21. data/test/phantom/browser_test.rb +9 -0
  22. data/test/phantom_test_helper.rb +67 -0
  23. data/test/test_app/Gemfile +9 -0
  24. data/test/test_app/Gemfile.lock +100 -0
  25. data/test/test_app/app/controllers/application_controller.rb +2 -0
  26. data/test/test_app/app/controllers/local_controller.rb +7 -0
  27. data/test/test_app/app/views/layouts/local.html.erb +14 -0
  28. data/test/test_app/app/views/local/index.html.erb +1 -0
  29. data/test/test_app/config/database.yml +10 -0
  30. data/test/test_app/config/initializers/ojo_initializer.rb +1 -0
  31. data/test/test_app/config/routes.rb +4 -0
  32. data/test/test_app/config.ru +31 -0
  33. data/test/test_app/log/development.log +260 -0
  34. data/test/test_app/log/test.log +2762 -0
  35. data/test/test_app/ojo_development +0 -0
  36. data/test/test_app/test_app.rb +30 -0
  37. data/test/test_helper.rb +59 -0
  38. data/test/unit/comparison_test.rb +185 -0
  39. data/test/unit/config_test.rb +9 -0
  40. data/test/unit/files_test.rb +31 -0
  41. data/test/unit/output_test.rb +38 -0
  42. metadata +164 -0
File without changes
@@ -0,0 +1,30 @@
1
+ db_name = "ojo_#{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 OjoApp
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
+ OjoApp::Application.initialize!
@@ -0,0 +1,59 @@
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
+ require 'mocha/mini_test'
23
+
24
+ Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new
25
+
26
+ require 'open4'
27
+
28
+ require File.expand_path('../../lib/ojo', __FILE__)
29
+
30
+ module Ojo
31
+ class OjoTestCase < Minitest::Test
32
+
33
+ private
34
+
35
+ def generate_image_with_shapes(image_destination, size_of_image, shapes = [])
36
+ shapes_string = ''
37
+ shapes.each do |shape|
38
+ if shape.include? 'fill'
39
+ shapes_string += " #{shape}"
40
+ else
41
+ shapes_string += " -draw '#{shape}'"
42
+ end
43
+ end
44
+
45
+ im = "convert -size #{size_of_image} xc:white -fill white -stroke red #{shapes_string} #{image_destination}"
46
+
47
+ #puts "\nim: #{im}"
48
+
49
+ err = nil
50
+ status = Open4::popen4(im) do |pid, stdin, stdout, stderr|
51
+ err = stderr.read
52
+ end
53
+
54
+ raise "generate image: #{err}" unless status.success?
55
+ end
56
+
57
+
58
+ end
59
+ end
@@ -0,0 +1,185 @@
1
+ require_relative '../test_helper'
2
+
3
+ class ComparisonTest < Ojo::OjoTestCase
4
+ require 'fileutils'
5
+
6
+ def setup
7
+ create_location_directories
8
+ Collimator::ProgressBar.stubs(:put_current_progress)
9
+ Collimator::ProgressBar.stubs(:complete)
10
+ end
11
+
12
+ def teardown
13
+ remove_location_directories
14
+ end
15
+
16
+ def test_comparison__single_file__same
17
+ # for reference, draw parameters look like this for rectangle
18
+ # rectangle x0,y0 x1,y1
19
+
20
+ shapes = []
21
+ shapes << "rectangle 20,0 190,190"
22
+ shapes << "rectangle 30,10 100,60"
23
+
24
+ file_1 = File.join(@branch_1, 'test_one.png')
25
+ generate_image_with_shapes(file_1, '200x200', shapes)
26
+ assert File.exist?(file_1)
27
+
28
+ file_2 = File.join(@branch_2, 'test_one.png')
29
+ generate_image_with_shapes(file_2, '200x200', shapes)
30
+ assert File.exist?(file_2)
31
+
32
+ r = Ojo.compare('branch_1', 'branch_2')
33
+
34
+ assert r[0], 'the all_pass status'
35
+ assert_equal @location, r[1][:location]
36
+ assert_equal 'branch_1', r[1][:branch_1]
37
+ assert_equal 'branch_2', r[1][:branch_2]
38
+ assert_equal 1, r[1][:results].keys.count
39
+ assert_equal File.basename(file_1), r[1][:results].keys.first
40
+ assert_equal true, r[1][:results]['test_one.png'][:same]
41
+ assert_equal file_1, r[1][:results]['test_one.png'][:file_1]
42
+ assert_equal file_2, r[1][:results]['test_one.png'][:file_2]
43
+
44
+ end
45
+
46
+ def test_comparison__single_file__different
47
+ # for reference, draw parameters look like this for rectangle
48
+ # rectangle x0,y0 x1,y1
49
+
50
+ shapes = []
51
+ shapes << "rectangle 20,0 190,190"
52
+ shapes << "rectangle 30,10 100,60"
53
+
54
+ file_1 = File.join(@branch_1, 'test_one.png')
55
+ generate_image_with_shapes(file_1, '200x200', shapes)
56
+ assert File.exist?(file_1)
57
+
58
+ shapes.pop
59
+ shapes << "rectangle 120,100 150,160"
60
+
61
+ file_2 = File.join(@branch_2, 'test_one.png')
62
+ generate_image_with_shapes(file_2, '200x200', shapes)
63
+ assert File.exist?(file_2)
64
+
65
+ r = Ojo.compare('branch_1', 'branch_2')
66
+
67
+ refute r[0], 'the all_pass status'
68
+ assert_equal @location, r[1][:location]
69
+ assert_equal 'branch_1', r[1][:branch_1]
70
+ assert_equal 'branch_2', r[1][:branch_2]
71
+ assert_equal 1, r[1][:results].keys.count
72
+ assert_equal File.basename(file_1), r[1][:results].keys.first
73
+ assert_equal false, r[1][:results]['test_one.png'][:same]
74
+ assert_equal file_1, r[1][:results]['test_one.png'][:file_1]
75
+ assert_equal file_2, r[1][:results]['test_one.png'][:file_2]
76
+ end
77
+
78
+ def test_comparison__single_file__different_size
79
+ # for reference, draw parameters look like this for rectangle
80
+ # rectangle x0,y0 x1,y1
81
+
82
+ shapes = []
83
+ shapes << "rectangle 20,0 190,190"
84
+ shapes << "rectangle 30,10 100,60"
85
+
86
+ file_1 = File.join(@branch_1, 'test_one.png')
87
+ generate_image_with_shapes(file_1, '200x200', shapes)
88
+ assert File.exist?(file_1)
89
+
90
+ file_2 = File.join(@branch_2, 'test_one.png')
91
+ generate_image_with_shapes(file_2, '200x210', shapes)
92
+ assert File.exist?(file_2)
93
+
94
+ r = Ojo.compare('branch_1', 'branch_2')
95
+
96
+ refute r[0], 'the all_pass status'
97
+ assert_equal @location, r[1][:location]
98
+ assert_equal 'branch_1', r[1][:branch_1]
99
+ assert_equal 'branch_2', r[1][:branch_2]
100
+ assert_equal 1, r[1][:results].keys.count
101
+ assert_equal File.basename(file_1), r[1][:results].keys.first
102
+ assert_equal false, r[1][:results]['test_one.png'][:same]
103
+ assert_equal file_1, r[1][:results]['test_one.png'][:file_1]
104
+ assert_equal file_2, r[1][:results]['test_one.png'][:file_2]
105
+ end
106
+
107
+ def test_comparison__multiple_files
108
+ shapes = []
109
+ shapes << "rectangle 20,0 190,190"
110
+ shapes << "rectangle 30,10 100,60"
111
+
112
+ file_1_1 = File.join(@branch_1, 'file_one.png')
113
+ file_2_1 = File.join(@branch_2, 'file_one.png')
114
+ generate_image_with_shapes(file_1_1, '200x200', shapes)
115
+ generate_image_with_shapes(file_2_1, '200x200', shapes)
116
+
117
+ shapes.pop
118
+ shapes << "rectangle 120,100 150,160"
119
+ file_1_2 = File.join(@branch_1, 'file_two.png')
120
+ generate_image_with_shapes(file_1_2, '220x220', shapes)
121
+
122
+ shapes << "rectangle 120,100 150,160"
123
+ file_2_3 = File.join(@branch_2, 'file_three.png')
124
+ generate_image_with_shapes(file_2_3, '200x220', shapes)
125
+
126
+ r = Ojo.compare('branch_1', 'branch_2')
127
+
128
+ assert r[0], 'the all_pass status'
129
+ assert_equal @location, r[1][:location]
130
+ assert_equal 'branch_1', r[1][:branch_1]
131
+ assert_equal 'branch_2', r[1][:branch_2]
132
+ assert_equal 3, r[1][:results].keys.count
133
+
134
+ file_1_4 = File.join(@branch_1, 'file_four.png')
135
+ file_2_4 = File.join(@branch_2, 'file_four.png')
136
+ generate_image_with_shapes(file_1_4, '50x50', ["rectangle 22,12 24,14"])
137
+ generate_image_with_shapes(file_2_4, '50x50', ["rectangle 20,10 22,12"])
138
+
139
+ r = Ojo.compare('branch_1', 'branch_2')
140
+
141
+ refute r[0], 'the all_pass status'
142
+ assert_equal @location, r[1][:location]
143
+ assert_equal 'branch_1', r[1][:branch_1]
144
+ assert_equal 'branch_2', r[1][:branch_2]
145
+ assert_equal 4, r[1][:results].keys.count
146
+
147
+ assert r[1][:results].keys.include?(File.basename(file_1_1))
148
+ assert r[1][:results].keys.include?(File.basename(file_1_2))
149
+ assert r[1][:results].keys.include?(File.basename(file_2_1))
150
+ assert r[1][:results].keys.include?(File.basename(file_2_3))
151
+ assert r[1][:results].keys.include?(File.basename(file_1_4))
152
+ assert r[1][:results].keys.include?(File.basename(file_2_4))
153
+
154
+ assert_equal true, r[1][:results][File.basename(file_1_1)][:same]
155
+ assert_equal nil, r[1][:results][File.basename(file_1_2)][:same]
156
+ assert_equal nil, r[1][:results][File.basename(file_2_3)][:same]
157
+ assert_equal false, r[1][:results][File.basename(file_1_4)][:same]
158
+
159
+ diff_location = File.join(Ojo.location, 'diff')
160
+ assert_equal 1, Dir[File.join(diff_location, '*.png')].count
161
+ refute File.exist?(File.join(diff_location, File.basename(file_1_1)))
162
+ refute File.exist?(File.join(diff_location, File.basename(file_1_2)))
163
+ refute File.exist?(File.join(diff_location, File.basename(file_2_3)))
164
+ assert File.exist?(File.join(diff_location, File.basename(file_1_4)))
165
+ end
166
+
167
+ private
168
+
169
+ def create_location_directories
170
+ @location = File.expand_path('../../tmp')
171
+ @branch_1 = File.join(@location, 'branch_1')
172
+ @branch_2 = File.join(@location, 'branch_2')
173
+
174
+ FileUtils.mkdir_p(@branch_1)
175
+ FileUtils.mkdir_p(@branch_2)
176
+
177
+ Ojo.location = @location
178
+ end
179
+
180
+ def remove_location_directories
181
+ FileUtils.rm_rf(@branch_1)
182
+ FileUtils.rm_rf(@branch_2)
183
+ FileUtils.rm_rf(File.join(@location, 'diff'))
184
+ end
185
+ end
@@ -0,0 +1,9 @@
1
+ require_relative '../test_helper'
2
+
3
+ class ConfigTest < Ojo::OjoTestCase
4
+
5
+ def test_locations
6
+ Ojo.location = File.expand_path('../../tmp')
7
+ assert_equal File.expand_path('../../tmp'), Ojo.location
8
+ end
9
+ end
@@ -0,0 +1,31 @@
1
+ require_relative '../test_helper'
2
+
3
+ class FilesTest < Ojo::OjoTestCase
4
+ def test_files__all_same
5
+ files_src_1 = %w(one two three four five)
6
+ files_src_2 = files_src_1.dup
7
+
8
+ all_files = Ojo.send(:compile_file_lists, files_src_1, files_src_2)
9
+
10
+ assert_equal files_src_1, all_files
11
+ assert_equal files_src_2, all_files
12
+ end
13
+
14
+ def test_files__totally_different
15
+ files_src_1 = %w(one two three four five)
16
+ files_src_2 = %w(six seven eight)
17
+
18
+ all_files = Ojo.send(:compile_file_lists, files_src_1, files_src_2)
19
+
20
+ assert_equal %w(one two three four five six seven eight), all_files
21
+ end
22
+
23
+ def test_files__slightly_different
24
+ files_src_1 = %w(one two three four five)
25
+ files_src_2 = %w(four five six seven)
26
+
27
+ all_files = Ojo.send(:compile_file_lists, files_src_1, files_src_2)
28
+
29
+ assert_equal %w(one two three four five six seven), all_files
30
+ end
31
+ end
@@ -0,0 +1,38 @@
1
+ require_relative '../test_helper'
2
+
3
+ class OutputTest < Ojo::OjoTestCase
4
+
5
+ def test_not_too_long
6
+ s = Ojo.send(:make_printable_name, 'Geordie', 10)
7
+ assert_equal 7, s.length
8
+ assert_equal 'Geordie', s
9
+ end
10
+
11
+ def test_too_long_filename__even_max_odd_string
12
+ max_length = 10
13
+ starting_string = 'SomeOddNumberOfCharactersInThisString'
14
+ s = Ojo.send(:make_printable_name, starting_string, max_length)
15
+ assert_equal 'Som....ing', s
16
+ end
17
+
18
+ def test_too_long_filename__even_max_even_string
19
+ max_length = 10
20
+ starting_string = 'SomeEvenNumberOfCharactersInThisString'
21
+ s = Ojo.send(:make_printable_name, starting_string, max_length)
22
+ assert_equal 'Som....ng', s
23
+ end
24
+
25
+ def test_too_long_filename__odd_max_odd_string
26
+ max_length = 11
27
+ starting_string = 'SomeOddNumberOfCharactersInThisString'
28
+ s = Ojo.send(:make_printable_name, starting_string, max_length)
29
+ assert_equal 'Som....ing', s
30
+ end
31
+
32
+ def test_too_long_filename__odd_max_even_string
33
+ max_length = 11
34
+ starting_string = 'SomeEvenNumberOfCharactersInThisString'
35
+ s = Ojo.send(:make_printable_name, starting_string, max_length)
36
+ assert_equal 'Some....ing', s
37
+ end
38
+ end
metadata ADDED
@@ -0,0 +1,164 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ojo
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - geordie
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-11-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: collimator
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: open4
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: ojo will compare a few sets of screen shots and report results.
70
+ email:
71
+ - george.speake@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".ruby-version"
78
+ - ".travis.yml"
79
+ - Gemfile
80
+ - LICENSE.txt
81
+ - README.md
82
+ - Rakefile
83
+ - lib/ojo.rb
84
+ - lib/ojo/comparison.rb
85
+ - lib/ojo/locations.rb
86
+ - lib/ojo/output.rb
87
+ - lib/ojo/rails/engine.rb
88
+ - lib/ojo/screenshot.rb
89
+ - lib/ojo/version.rb
90
+ - lib/tasks/ojo.rake
91
+ - ojo.gemspec
92
+ - test/page_objects.rb
93
+ - test/page_objects/test_app/index_page.rb
94
+ - test/page_objects/test_app/test_app_page.rb
95
+ - test/phantom/browser_test.rb
96
+ - test/phantom_test_helper.rb
97
+ - test/test_app/Gemfile
98
+ - test/test_app/Gemfile.lock
99
+ - test/test_app/app/controllers/application_controller.rb
100
+ - test/test_app/app/controllers/local_controller.rb
101
+ - test/test_app/app/views/layouts/local.html.erb
102
+ - test/test_app/app/views/local/index.html.erb
103
+ - test/test_app/config.ru
104
+ - test/test_app/config/database.yml
105
+ - test/test_app/config/initializers/ojo_initializer.rb
106
+ - test/test_app/config/routes.rb
107
+ - test/test_app/log/development.log
108
+ - test/test_app/log/test.log
109
+ - test/test_app/ojo_development
110
+ - test/test_app/test_app.rb
111
+ - test/test_helper.rb
112
+ - test/unit/comparison_test.rb
113
+ - test/unit/config_test.rb
114
+ - test/unit/files_test.rb
115
+ - test/unit/output_test.rb
116
+ homepage: ''
117
+ licenses:
118
+ - MIT
119
+ metadata: {}
120
+ post_install_message:
121
+ rdoc_options: []
122
+ require_paths:
123
+ - lib
124
+ required_ruby_version: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - ">="
127
+ - !ruby/object:Gem::Version
128
+ version: '0'
129
+ required_rubygems_version: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - ">="
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ requirements: []
135
+ rubyforge_project:
136
+ rubygems_version: 2.2.2
137
+ signing_key:
138
+ specification_version: 4
139
+ summary: ojo is the eyes of the appearance test
140
+ test_files:
141
+ - test/page_objects.rb
142
+ - test/page_objects/test_app/index_page.rb
143
+ - test/page_objects/test_app/test_app_page.rb
144
+ - test/phantom/browser_test.rb
145
+ - test/phantom_test_helper.rb
146
+ - test/test_app/Gemfile
147
+ - test/test_app/Gemfile.lock
148
+ - test/test_app/app/controllers/application_controller.rb
149
+ - test/test_app/app/controllers/local_controller.rb
150
+ - test/test_app/app/views/layouts/local.html.erb
151
+ - test/test_app/app/views/local/index.html.erb
152
+ - test/test_app/config.ru
153
+ - test/test_app/config/database.yml
154
+ - test/test_app/config/initializers/ojo_initializer.rb
155
+ - test/test_app/config/routes.rb
156
+ - test/test_app/log/development.log
157
+ - test/test_app/log/test.log
158
+ - test/test_app/ojo_development
159
+ - test/test_app/test_app.rb
160
+ - test/test_helper.rb
161
+ - test/unit/comparison_test.rb
162
+ - test/unit/config_test.rb
163
+ - test/unit/files_test.rb
164
+ - test/unit/output_test.rb