ojo 0.0.2 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -12,9 +12,9 @@ module Ojo
12
12
 
13
13
  def self.screenshot(group_name, base_name)
14
14
  raise 'No screenshot method defined for Ojo.screenshoter!' unless @screenshotter
15
- raise 'No screenshot location defined for Ojo.location!' unless @location
15
+ raise 'No screenshot location defined for Ojo.location!' unless ::Ojo.configuration.location
16
16
 
17
- filename = File.join(location, group_name, "#{base_name}.png")
17
+ filename = File.join(::Ojo.configuration.location, group_name, "#{base_name}.png")
18
18
 
19
19
  @screenshotter.call filename
20
20
  end
@@ -1,3 +1,3 @@
1
1
  module Ojo
2
- VERSION = '0.0.2'.freeze
2
+ VERSION = '1.0.0'.freeze
3
3
  end
@@ -6,53 +6,28 @@ namespace :ojo do
6
6
  branch_1 = args.fetch(:branch_1, nil)
7
7
  branch_2 = args.fetch(:branch_2, nil)
8
8
 
9
- unless branch_1 && branch_2
10
- branches = Ojo.get_data_sets_available
11
- unless branch_1
12
- branches.each do |branch|
13
- if branch != branch_2
14
- branch_1 = branch
15
- break
16
- end
17
- end
18
- end
19
-
20
- unless branch_2
21
- branches.each do |branch|
22
- if branch != branch_1
23
- branch_2 = branch
24
- break
25
- end
26
- end
27
- end
28
- end
29
-
30
- results = Ojo.compare(branch_1, branch_2)
31
- Ojo.display_to_console results[1]
9
+ Ojo::Manager.new.compare(branch_1, branch_2)
32
10
  end
33
11
 
34
12
  desc 'show ojo location setting'
35
13
  task :location => :environment do |t|
36
- puts Ojo.location
14
+ Ojo::Manager.new.location
37
15
  end
38
16
 
39
17
  desc 'list ojo data sets'
40
18
  task :list => :environment do |t|
41
- data_sets = Ojo.get_data_sets_available
42
- Ojo.display_data_sets(data_sets)
19
+ Ojo::Manager.new.data_sets
43
20
  end
44
21
 
45
22
  namespace :clear do
46
23
  desc 'clear ojo results only'
47
24
  task :diff => :environment do |t|
48
- FileUtils.rm_rf File.join(Ojo.location, 'diff')
25
+ Ojo::Manager.new.clear_diff
49
26
  end
50
27
 
51
28
  desc 'clear all ojo files INCLUDING all data sets'
52
29
  task :all => :environment do |t|
53
- data_sets = Ojo.get_data_sets_available
54
- FileUtils.rm_rf File.join(Ojo.location, 'diff')
55
- data_sets.each { |d| FileUtils.rm_rf(File.join(Ojo.location, d)) }
30
+ Ojo::Manager.new.clear_all
56
31
  end
57
32
 
58
33
  end
@@ -2,8 +2,7 @@ require 'phantom_test_helper'
2
2
 
3
3
  class TestAppTest < OjoApp::PhantomTestCase
4
4
  def test_index_page
5
- index_page = PageObjects::TestApp::IndexPage.visit
6
-
5
+ PageObjects::TestApp::IndexPage.visit
7
6
  Ojo.screenshot(branch_name, __method__)
8
7
  end
9
8
  end
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ../..
3
3
  specs:
4
- ojo (0.0.1)
4
+ ojo (0.0.2)
5
5
  collimator
6
6
  open4
7
7
 
@@ -1 +1,3 @@
1
- Ojo.location = File.join(Rails.root, 'tmp', 'ojo_data')
1
+ ::Ojo.configure do |c|
2
+ c.location = File.join(Rails.root, 'tmp', 'ojo_data')
3
+ end
@@ -1,3 +1,8 @@
1
+ if ENV['CODECLIMATE_REPO_TOKEN']
2
+ require 'codeclimate-test-reporter'
3
+ CodeClimate::TestReporter.start
4
+ end
5
+
1
6
  require 'rubygems'
2
7
  require 'bundler'
3
8
 
@@ -27,6 +32,8 @@ require 'open4'
27
32
 
28
33
  require File.expand_path('../../lib/ojo', __FILE__)
29
34
 
35
+ Ojo.configure
36
+
30
37
  module Ojo
31
38
  class OjoTestCase < Minitest::Test
32
39
 
@@ -54,6 +61,29 @@ module Ojo
54
61
  raise "generate image: #{err}" unless status.success?
55
62
  end
56
63
 
64
+ def create_location_directories
65
+ @location = File.absolute_path('../../tmp', __FILE__)
66
+ @branch_1 = File.join(@location, 'branch_1')
67
+ @branch_2 = File.join(@location, 'branch_2')
68
+
69
+ FileUtils.mkdir_p(@branch_1)
70
+ FileUtils.mkdir_p(@branch_2)
71
+
72
+ ::Ojo.configuration.location = @location
73
+ end
74
+
75
+ def remove_location_directories
76
+ FileUtils.rm_rf Dir[File.join(@location, '*')]
77
+ end
78
+
79
+ def capture_output
80
+ out = StringIO.new
81
+ $stdout = out
82
+ yield
83
+ return out
84
+ ensure
85
+ $stdout = STDOUT
86
+ end
57
87
 
58
88
  end
59
89
  end
@@ -7,6 +7,7 @@ class ComparisonTest < Ojo::OjoTestCase
7
7
  create_location_directories
8
8
  Collimator::ProgressBar.stubs(:put_current_progress)
9
9
  Collimator::ProgressBar.stubs(:complete)
10
+ @ojo = Ojo::Ojo.new
10
11
  end
11
12
 
12
13
  def teardown
@@ -29,7 +30,7 @@ class ComparisonTest < Ojo::OjoTestCase
29
30
  generate_image_with_shapes(file_2, '200x200', shapes)
30
31
  assert File.exist?(file_2)
31
32
 
32
- r = Ojo.compare('branch_1', 'branch_2')
33
+ r = @ojo.compare('branch_1', 'branch_2')
33
34
 
34
35
  assert r[0], 'the all_pass status'
35
36
  assert_equal @location, r[1][:location]
@@ -62,7 +63,7 @@ class ComparisonTest < Ojo::OjoTestCase
62
63
  generate_image_with_shapes(file_2, '200x200', shapes)
63
64
  assert File.exist?(file_2)
64
65
 
65
- r = Ojo.compare('branch_1', 'branch_2')
66
+ r = @ojo.compare('branch_1', 'branch_2')
66
67
 
67
68
  refute r[0], 'the all_pass status'
68
69
  assert_equal @location, r[1][:location]
@@ -84,14 +85,14 @@ class ComparisonTest < Ojo::OjoTestCase
84
85
  shapes << "rectangle 30,10 100,60"
85
86
 
86
87
  file_1 = File.join(@branch_1, 'test_one.png')
87
- generate_image_with_shapes(file_1, '200x200', shapes)
88
+ generate_image_with_shapes(file_1, '205x200', shapes)
88
89
  assert File.exist?(file_1)
89
90
 
90
91
  file_2 = File.join(@branch_2, 'test_one.png')
91
92
  generate_image_with_shapes(file_2, '200x210', shapes)
92
93
  assert File.exist?(file_2)
93
94
 
94
- r = Ojo.compare('branch_1', 'branch_2')
95
+ r = @ojo.compare('branch_1', 'branch_2')
95
96
 
96
97
  refute r[0], 'the all_pass status'
97
98
  assert_equal @location, r[1][:location]
@@ -123,7 +124,7 @@ class ComparisonTest < Ojo::OjoTestCase
123
124
  file_2_3 = File.join(@branch_2, 'file_three.png')
124
125
  generate_image_with_shapes(file_2_3, '200x220', shapes)
125
126
 
126
- r = Ojo.compare('branch_1', 'branch_2')
127
+ r = @ojo.compare('branch_1', 'branch_2')
127
128
 
128
129
  assert r[0], 'the all_pass status'
129
130
  assert_equal @location, r[1][:location]
@@ -136,7 +137,7 @@ class ComparisonTest < Ojo::OjoTestCase
136
137
  generate_image_with_shapes(file_1_4, '50x50', ["rectangle 22,12 24,14"])
137
138
  generate_image_with_shapes(file_2_4, '50x50', ["rectangle 20,10 22,12"])
138
139
 
139
- r = Ojo.compare('branch_1', 'branch_2')
140
+ r = @ojo.compare('branch_1', 'branch_2')
140
141
 
141
142
  refute r[0], 'the all_pass status'
142
143
  assert_equal @location, r[1][:location]
@@ -156,7 +157,7 @@ class ComparisonTest < Ojo::OjoTestCase
156
157
  assert_equal nil, r[1][:results][File.basename(file_2_3)][:same]
157
158
  assert_equal false, r[1][:results][File.basename(file_1_4)][:same]
158
159
 
159
- diff_location = File.join(Ojo.location, 'diff')
160
+ diff_location = File.join(Ojo.configuration.location, 'diff')
160
161
  assert_equal 1, Dir[File.join(diff_location, '*.png')].count
161
162
  refute File.exist?(File.join(diff_location, File.basename(file_1_1)))
162
163
  refute File.exist?(File.join(diff_location, File.basename(file_1_2)))
@@ -164,22 +165,4 @@ class ComparisonTest < Ojo::OjoTestCase
164
165
  assert File.exist?(File.join(diff_location, File.basename(file_1_4)))
165
166
  end
166
167
 
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
168
  end
@@ -3,7 +3,7 @@ require_relative '../test_helper'
3
3
  class ConfigTest < Ojo::OjoTestCase
4
4
 
5
5
  def test_locations
6
- Ojo.location = File.expand_path('../../tmp')
7
- assert_equal File.expand_path('../../tmp'), Ojo.location
6
+ Ojo.configuration.location = File.expand_path('../../tmp')
7
+ assert_equal File.expand_path('../../tmp'), Ojo.configuration.location
8
8
  end
9
9
  end
@@ -0,0 +1,38 @@
1
+ require_relative '../test_helper'
2
+
3
+ class DataSetsTest < Ojo::OjoTestCase
4
+ def setup
5
+ create_location_directories
6
+ @data_sets = ::Ojo::DataSets.new
7
+ end
8
+
9
+ def teardown
10
+ remove_location_directories
11
+ end
12
+
13
+ def test_data_sets
14
+ sets_available = @data_sets.sets_available
15
+
16
+ assert_equal 2, sets_available.length
17
+ assert_includes sets_available, 'branch_1'
18
+ assert_includes sets_available, 'branch_2'
19
+ end
20
+
21
+ def test_data_sets__lots
22
+ branch_3 = File.join(@location, 'branch_3')
23
+ branch_4 = File.join(@location, 'branch_4')
24
+ diff = File.join(@location, 'diff')
25
+
26
+ FileUtils.mkdir_p(branch_3)
27
+ FileUtils.mkdir_p(branch_4)
28
+ FileUtils.mkdir_p(diff)
29
+
30
+ sets_available = @data_sets.sets_available
31
+ assert_equal 4, sets_available.length
32
+ assert_includes sets_available, 'branch_1'
33
+ assert_includes sets_available, 'branch_2'
34
+ assert_includes sets_available, 'branch_3'
35
+ assert_includes sets_available, 'branch_4'
36
+ refute_includes sets_available, 'diff'
37
+ end
38
+ end
@@ -5,7 +5,7 @@ class FilesTest < Ojo::OjoTestCase
5
5
  files_src_1 = %w(one two three four five)
6
6
  files_src_2 = files_src_1.dup
7
7
 
8
- all_files = Ojo.send(:compile_file_lists, files_src_1, files_src_2)
8
+ all_files = Ojo::Ojo.new.send(:compile_file_lists, files_src_1, files_src_2)
9
9
 
10
10
  assert_equal files_src_1, all_files
11
11
  assert_equal files_src_2, all_files
@@ -15,7 +15,7 @@ class FilesTest < Ojo::OjoTestCase
15
15
  files_src_1 = %w(one two three four five)
16
16
  files_src_2 = %w(six seven eight)
17
17
 
18
- all_files = Ojo.send(:compile_file_lists, files_src_1, files_src_2)
18
+ all_files = Ojo::Ojo.new.send(:compile_file_lists, files_src_1, files_src_2)
19
19
 
20
20
  assert_equal %w(one two three four five six seven eight), all_files
21
21
  end
@@ -24,7 +24,7 @@ class FilesTest < Ojo::OjoTestCase
24
24
  files_src_1 = %w(one two three four five)
25
25
  files_src_2 = %w(four five six seven)
26
26
 
27
- all_files = Ojo.send(:compile_file_lists, files_src_1, files_src_2)
27
+ all_files = Ojo::Ojo.new.send(:compile_file_lists, files_src_1, files_src_2)
28
28
 
29
29
  assert_equal %w(one two three four five six seven), all_files
30
30
  end
@@ -0,0 +1,34 @@
1
+ require_relative '../test_helper'
2
+
3
+ class ImageMagicianTest < Ojo::OjoTestCase
4
+
5
+ def setup
6
+ @image_magician = ::Ojo::ImageMagician.new
7
+ end
8
+
9
+ def test_get_color_values
10
+ raw = raw_string('1', '22', '303', '4044')
11
+ color_values = @image_magician.send(:get_color_values, raw)
12
+
13
+ assert_equal '1', color_values[:red]
14
+ assert_equal '22', color_values[:green]
15
+ assert_equal '303', color_values[:blue]
16
+ assert_equal '4044', color_values[:all]
17
+ end
18
+
19
+ def test_unpack_comparison_result
20
+ assert @image_magician.unpack_comparison_result(raw_string('0', '0', '0', '0')), 'all colors equal 0'
21
+
22
+ refute @image_magician.unpack_comparison_result(raw_string('123', '234', '345', '456')), 'all colors greater than 0'
23
+ refute @image_magician.unpack_comparison_result(raw_string('123', '0', '0', '0')), 'red greater than 0'
24
+ refute @image_magician.unpack_comparison_result(raw_string('0', '234', '0', '0')), 'green greater than 0'
25
+ refute @image_magician.unpack_comparison_result(raw_string('0', '0', '345', '0')), 'blue greater than 0'
26
+ refute @image_magician.unpack_comparison_result(raw_string('0', '0', '0', '456')), "'all' greater than 0"
27
+ end
28
+
29
+ private
30
+
31
+ def raw_string(red, green, blue, all)
32
+ "/Users/someone/branch_1/test_one.png PNG 200x200 200x200+0+0 16-bit sRGB 1.04KB 0.000u 0:00.000\n/Users/someone/branch_2/test_one.png PNG 200x200 200x200+0+0 16-bit sRGB 1.05KB 0.000u 0:00.000\nImage: /Users/someone/branch_1/test_one.png\n Channel distortion: AE\n red: #{red}\n green: #{green}\n blue: #{blue}\n all: #{all}\n/Users/someone/branch_1/test_one.png=>/Users/someone/diff/test_one.png PNG 200x200 200x200+0+0 16-bit sRGB 6c 1.18KB 0.010u 0:00.000\n"
33
+ end
34
+ end
@@ -0,0 +1,163 @@
1
+ require_relative '../test_helper'
2
+
3
+ class ManagerTest < Ojo::OjoTestCase
4
+
5
+ def setup
6
+ create_location_directories
7
+ @manager = ::Ojo::Manager.new
8
+ end
9
+
10
+ def teardown
11
+ remove_location_directories
12
+ $stdout = STDOUT
13
+ end
14
+
15
+ def test_locations
16
+ out = capture_output do
17
+ @manager.location
18
+ end
19
+
20
+ assert_match Ojo.configuration.location, out.string.strip
21
+ end
22
+
23
+ def test_data_sets
24
+ out = capture_output do
25
+ @manager.data_sets
26
+ end
27
+
28
+ sa = out.string.split("\n")
29
+
30
+ assert_equal '~~~~~~~~~~~~~~~~~~~~ Ojo ~~~~~~~~~~~~~~~~~~~~', sa[0]
31
+ assert_equal 'Data sets that can be compared:', sa[1]
32
+ assert_equal ' branch_1', sa[2]
33
+ assert_equal ' branch_2', sa[3]
34
+ assert_equal '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~', sa[4]
35
+ end
36
+
37
+ def test_clear__diff
38
+ make_some_temp_files
39
+
40
+ assert File.exist?(@temp_diff_filename)
41
+ assert File.exist?(@filename_1)
42
+ assert File.exist?(@filename_2)
43
+
44
+ @manager.clear_diff
45
+
46
+ refute File.exist?(@temp_diff_filename)
47
+ assert File.exist?(@filename_1)
48
+ assert File.exist?(@filename_2)
49
+ end
50
+
51
+ def test_clear__all
52
+ make_some_temp_files
53
+
54
+ assert File.exist?(@temp_diff_filename)
55
+ assert File.exist?(@filename_1)
56
+ assert File.exist?(@filename_2)
57
+
58
+ @manager.clear_all
59
+
60
+ refute File.exist?(@temp_diff_filename)
61
+ refute File.exist?(@filename_1)
62
+ refute File.exist?(@filename_2)
63
+ end
64
+
65
+ def test_compare
66
+ make_some_real_files
67
+ Collimator::ProgressBar.stubs(:put_current_progress)
68
+ Collimator::ProgressBar.stubs(:complete)
69
+
70
+ branch_1_name = @branch_1.split('/').last
71
+ branch_2_name = @branch_2.split('/').last
72
+
73
+ out = capture_output do
74
+ Date.stub :today, Date.parse('1/10/2014') do
75
+ @manager.compare branch_1_name, branch_2_name
76
+ end
77
+ end
78
+
79
+ assert_compare_output out.string, %w(branch_1 branch_2)
80
+ end
81
+
82
+ def test_compare__missing_branch_names
83
+ make_some_real_files
84
+ Collimator::ProgressBar.stubs(:put_current_progress)
85
+ Collimator::ProgressBar.stubs(:complete)
86
+
87
+ branch_1_name = @branch_1.split('/').last
88
+ branch_2_name = @branch_2.split('/').last
89
+
90
+ out = capture_output do
91
+ Date.stub :today, Date.parse('1/10/2014') do
92
+ @manager.compare nil, branch_2_name
93
+ end
94
+ end
95
+ assert_compare_output out.string, %w(branch_1 branch_2)
96
+
97
+ out = capture_output do
98
+ Date.stub :today, Date.parse('1/10/2014') do
99
+ @manager.compare branch_1_name, nil
100
+ end
101
+ end
102
+ assert_compare_output out.string, %w(branch_1 branch_2)
103
+
104
+ branch_1a = File.join(@location, 'branch_1a')
105
+ FileUtils.mkdir_p(branch_1a)
106
+ file_1a = File.join(branch_1a, 'test_one.png')
107
+ generate_one_real_file file_1a
108
+
109
+ out = capture_output do
110
+ Date.stub :today, Date.parse('1/10/2014') do
111
+ @manager.compare nil, nil
112
+ end
113
+ end
114
+ assert_compare_output out.string, %w(branch_1 branch_1a)
115
+ end
116
+
117
+ private
118
+
119
+ def assert_compare_output(output_string, branch_names)
120
+ sa = output_string.split("\n")
121
+
122
+ assert_equal '+-----------------------------------------------------------------------------------------------------------------------------------------+', sa[0]
123
+ assert_match 'Ojo v.', sa[1]
124
+ assert_match 'file location:', sa[2]
125
+ assert_equal '| 10/01/2014 |', sa[3]
126
+ assert_equal '+-----------------------------------------------------------------------------------------------------------------------------------------+', sa[4]
127
+ assert_match branch_names.first, sa[5]
128
+ assert_match branch_names.last, sa[5]
129
+ assert_equal '|--------------------------------------------------------------+--------------------------------------------------------------+-----------|', sa[6]
130
+ assert_equal "| \e[1;32mtest_one.png\e[0m | \e[1;32mtest_one.png\e[0m | \e[1;32mPASS\e[0m |", sa[7]
131
+ assert_equal '+-----------------------------------------------------------------------------------------------------------------------------------------+', sa[8]
132
+ assert_equal '| Results: All Same |', sa[9]
133
+ assert_match 'Difference Files at', sa[10]
134
+ assert_equal '+-----------------------------------------------------------------------------------------------------------------------------------------+', sa[11]
135
+ end
136
+
137
+ def make_some_real_files
138
+ file_1 = File.join(@branch_1, 'test_one.png')
139
+ file_2 = File.join(@branch_2, 'test_one.png')
140
+ generate_one_real_file file_1
141
+ generate_one_real_file file_2
142
+ end
143
+
144
+ def generate_one_real_file(name)
145
+ shapes = []
146
+ shapes << "rectangle 20,0 190,190"
147
+ shapes << "rectangle 30,10 100,60"
148
+
149
+ generate_image_with_shapes(name, '200x200', shapes)
150
+ end
151
+
152
+ def make_some_temp_files
153
+ @temp_diff_location = File.join(Ojo.configuration.location, 'diff')
154
+ @temp_diff_filename = File.join(@temp_diff_location, 'some_test_diff.txt')
155
+ FileUtils.mkdir_p @temp_diff_location
156
+ File.open(@temp_diff_filename, 'w') { |f| f.write '' }
157
+
158
+ @filename_1 = File.join(@branch_1, 'some_test.txt')
159
+ @filename_2 = File.join(@branch_2, 'some_test.txt')
160
+ File.open(@filename_1, 'w') { |f| f.write '' }
161
+ File.open(@filename_2, 'w') { |f| f.write '' }
162
+ end
163
+ end