symilaa 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,72 @@
1
+ module Symilaa
2
+ module ComparisonSupport
3
+ def add_text_to_image text, image
4
+ txt = Draw.new
5
+ image.annotate(txt, 0, 0, 0, 50, text) {
6
+ txt.gravity = Magick::SouthGravity
7
+ txt.pointsize = 25
8
+ txt.stroke = '#ff0000'
9
+ txt.fill = '#ff0000'
10
+ txt.font_weight = Magick::BoldWeight
11
+ }
12
+ end
13
+
14
+ def produce_gif_showing_the_difference_between reference_shot, test_shot, output_file
15
+ gif = Magick::ImageList.new(reference_shot, test_shot)
16
+ add_text_to_image "Test Screenshot", gif[1]
17
+ gif.delay = 100
18
+ gif.write(output_file)
19
+ end
20
+
21
+ def get_unique_file_name path, extension, inc
22
+ inc = 0 unless inc
23
+ inc = inc.to_int+1
24
+
25
+ new_path = "#{path}#{inc}#{extension}"
26
+
27
+ if File.exists?("#{new_path}")
28
+ get_unique_file_name path, extension, inc
29
+ else
30
+ new_path
31
+ end
32
+ end
33
+
34
+ def check_screen_against_reference_shot sub_directory
35
+ sub_directory = "#{sub_directory}#{@gherkin_statement.parameterize.underscore}/"
36
+
37
+ FileUtils.mkdir_p("#{SCREENSHOTS_GENERATED_THIS_RUN_DIR}/#{sub_directory}")
38
+
39
+ browser_info = page.driver.browser.capabilities
40
+
41
+ version_if_required = "_#{browser_info.version.gsub('.', '-')}" unless browser_info.browser_name == 'firefox' and browser_info.version != '3.5' or browser_info.browser_name == 'chrome'
42
+
43
+ title = find('title').text
44
+ file_name = "#{browser_info.browser_name.capitalize.parameterize}#{version_if_required}_#{browser_info.platform.capitalize}_#{title.parameterize.underscore}"
45
+ test_file = get_unique_file_name "#{SCREENSHOTS_GENERATED_THIS_RUN_DIR}/#{sub_directory}#{file_name}", '.png', nil
46
+
47
+ page.driver.browser.save_screenshot test_file
48
+
49
+ screenshot_name = File.basename test_file
50
+ reference_file = "#{REFERENCE_SCREENSHOTS}/#{sub_directory}#{screenshot_name}"
51
+
52
+ reference_screenshot = Image.new reference_file
53
+ generated_screenshot = Image.new test_file
54
+
55
+ same = if dodgy_browser?
56
+ reference_screenshot.similar_to? generated_screenshot
57
+ else
58
+ reference_screenshot == generated_screenshot
59
+ end
60
+
61
+ unless same
62
+ FileUtils.mkdir_p("#{DIFFERENCES_IN_SCREENSHOTS_THIS_RUN_DIR}/#{sub_directory}")
63
+ produce_gif_showing_the_difference_between(reference_file, test_file, "#{DIFFERENCES_IN_SCREENSHOTS_THIS_RUN_DIR}/#{sub_directory}#{screenshot_name}_difference.gif")
64
+ fail "Some of the screenshots did not match"
65
+ end
66
+ end
67
+
68
+ def dodgy_browser?
69
+ %w[chrome ie7 ie8 ie9].include? ENV['REQUIRED_BROWSER']
70
+ end
71
+ end
72
+ end
@@ -2,7 +2,7 @@ require 'RMagick'
2
2
  require 'fileutils'
3
3
 
4
4
  module Symilaa
5
- class Screenshot
5
+ class Image
6
6
  SIMILARITY_THRESHOLD = 41.4
7
7
 
8
8
  attr_reader :path
@@ -1,3 +1,3 @@
1
1
  module Symilaa
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
data/lib/symilaa.rb CHANGED
@@ -1,2 +1,4 @@
1
1
  require "symilaa/version"
2
- require 'symilaa/screenshot'
2
+ require 'symilaa/comparison_support'
3
+ require 'symilaa/image'
4
+
data/symilaa.gemspec CHANGED
@@ -22,6 +22,7 @@ Gem::Specification.new do |s|
22
22
  # specify any dependencies here; for example:
23
23
  s.add_development_dependency "minitest"
24
24
  s.add_development_dependency "guard-minitest"
25
+ s.add_development_dependency "rake"
25
26
 
26
27
  s.add_development_dependency 'rb-inotify' if RUBY_PLATFORM =~ /linux/
27
28
 
@@ -1,87 +1,87 @@
1
1
  gem 'minitest'
2
2
  require 'minitest/autorun'
3
- require_relative '../../lib/symilaa/screenshot'
3
+ require_relative '../../lib/symilaa/image'
4
4
 
5
5
  module Symilaa
6
- class TestScreenshot < Minitest::Unit::TestCase
6
+ class TestImage < Minitest::Unit::TestCase
7
7
  def test_equality_when_images_altered
8
- one = Screenshot.new grylls
9
- two = Screenshot.new grylls_different
8
+ one = Image.new grylls
9
+ two = Image.new grylls_different
10
10
 
11
11
  refute one == two
12
12
  end
13
13
 
14
14
  def test_equality_when_images_similar
15
- one = Screenshot.new grylls
16
- two = Screenshot.new grylls_slightly_different
15
+ one = Image.new grylls
16
+ two = Image.new grylls_slightly_different
17
17
 
18
18
  refute one == two
19
19
  end
20
20
 
21
21
  def test_equality_when_identical
22
- one = Screenshot.new grylls
23
- two = Screenshot.new grylls
22
+ one = Image.new grylls
23
+ two = Image.new grylls
24
24
 
25
25
  assert one == two
26
26
  end
27
27
 
28
28
  def test_similar_when_identical
29
- one = Screenshot.new grylls
30
- two = Screenshot.new grylls
29
+ one = Image.new grylls
30
+ two = Image.new grylls
31
31
 
32
32
  assert one.similar_to? two
33
33
  end
34
34
 
35
35
  def test_similar_when_similar
36
- one = Screenshot.new grylls
37
- two = Screenshot.new grylls_slightly_different
36
+ one = Image.new grylls
37
+ two = Image.new grylls_slightly_different
38
38
 
39
39
  assert one.similar_to? two
40
40
  end
41
41
 
42
42
  def test_different_sized_images_are_different
43
- one = Screenshot.new grylls
44
- two = Screenshot.new the_queen
43
+ one = Image.new grylls
44
+ two = Image.new the_queen
45
45
 
46
46
  refute one.similar_to? two
47
47
  refute one == two
48
48
  end
49
49
 
50
50
  def test_css_font_size_change
51
- ref = Screenshot.new fixture 'diagnostics/reference/font_size.png'
52
- diff = Screenshot.new fixture 'diagnostics/generated/font_size.png'
51
+ ref = Image.new fixture 'diagnostics/reference/font_size.png'
52
+ diff = Image.new fixture 'diagnostics/generated/font_size.png'
53
53
 
54
54
  refute ref == diff
55
55
  refute ref.similar_to? diff
56
56
  end
57
57
 
58
58
  def test_css_change_of_gradient
59
- ref = Screenshot.new fixture 'diagnostics/reference/gradient.png'
60
- diff = Screenshot.new fixture 'diagnostics/generated/gradient.png'
59
+ ref = Image.new fixture 'diagnostics/reference/gradient.png'
60
+ diff = Image.new fixture 'diagnostics/generated/gradient.png'
61
61
 
62
62
  refute ref == diff, "Images with different gradients should not be the same"
63
63
  refute ref.similar_to?(diff), "Images with different gradients should not be similar"
64
64
  end
65
65
 
66
66
  def test_lightbox_difference
67
- ref = Screenshot.new fixture 'diagnostics/reference/lightbox.png'
68
- diff = Screenshot.new fixture 'diagnostics/generated/lightbox.png'
67
+ ref = Image.new fixture 'diagnostics/reference/lightbox.png'
68
+ diff = Image.new fixture 'diagnostics/generated/lightbox.png'
69
69
 
70
70
  refute ref == diff, "Internet Explorer's rendering of a lightbox is different every time"
71
71
  assert ref.similar_to?(diff), "Internet Explorer's rendering of a lightbox is similar enough each time"
72
72
  end
73
73
 
74
74
  def test_rounded_corners_in_ie9
75
- ref = Screenshot.new fixture 'diagnostics/reference/rounded_corner_ie9.png'
76
- diff = Screenshot.new fixture 'diagnostics/generated/rounded_corner_ie9.png'
75
+ ref = Image.new fixture 'diagnostics/reference/rounded_corner_ie9.png'
76
+ diff = Image.new fixture 'diagnostics/generated/rounded_corner_ie9.png'
77
77
 
78
78
  refute ref == diff
79
79
  assert ref.similar_to?(diff)
80
80
  end
81
81
 
82
82
  def test_active_input_state_in_ie9
83
- ref = Screenshot.new fixture 'diagnostics/reference/active_input_ie9.png'
84
- diff = Screenshot.new fixture 'diagnostics/generated/active_input_ie9.png'
83
+ ref = Image.new fixture 'diagnostics/reference/active_input_ie9.png'
84
+ diff = Image.new fixture 'diagnostics/generated/active_input_ie9.png'
85
85
 
86
86
  refute ref == diff
87
87
  assert ref.similar_to?(diff)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: symilaa
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-09 00:00:00.000000000Z
12
+ date: 2012-11-15 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: minitest
16
- requirement: &22820560 !ruby/object:Gem::Requirement
16
+ requirement: &11679260 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *22820560
24
+ version_requirements: *11679260
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: guard-minitest
27
- requirement: &22819920 !ruby/object:Gem::Requirement
27
+ requirement: &11678820 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,21 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *22819920
35
+ version_requirements: *11678820
36
+ - !ruby/object:Gem::Dependency
37
+ name: rake
38
+ requirement: &11678220 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *11678220
36
47
  - !ruby/object:Gem::Dependency
37
48
  name: rb-inotify
38
- requirement: &22819220 !ruby/object:Gem::Requirement
49
+ requirement: &11677500 !ruby/object:Gem::Requirement
39
50
  none: false
40
51
  requirements:
41
52
  - - ! '>='
@@ -43,10 +54,10 @@ dependencies:
43
54
  version: '0'
44
55
  type: :development
45
56
  prerelease: false
46
- version_requirements: *22819220
57
+ version_requirements: *11677500
47
58
  - !ruby/object:Gem::Dependency
48
59
  name: rmagick
49
- requirement: &22818440 !ruby/object:Gem::Requirement
60
+ requirement: &11239900 !ruby/object:Gem::Requirement
50
61
  none: false
51
62
  requirements:
52
63
  - - ! '>='
@@ -54,7 +65,7 @@ dependencies:
54
65
  version: '0'
55
66
  type: :runtime
56
67
  prerelease: false
57
- version_requirements: *22818440
68
+ version_requirements: *11239900
58
69
  description: ! "Using the wonders of RMagick, this wonderful gem will produce a boolean
59
70
  result based on the computed similarity\n of the two images passed."
60
71
  email:
@@ -69,7 +80,8 @@ files:
69
80
  - README.md
70
81
  - Rakefile
71
82
  - lib/symilaa.rb
72
- - lib/symilaa/screenshot.rb
83
+ - lib/symilaa/comparison_support.rb
84
+ - lib/symilaa/image.rb
73
85
  - lib/symilaa/version.rb
74
86
  - symilaa.gemspec
75
87
  - test/fixtures/bear_grylls.png
@@ -99,12 +111,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
99
111
  - - ! '>='
100
112
  - !ruby/object:Gem::Version
101
113
  version: '0'
114
+ segments:
115
+ - 0
116
+ hash: -3943333428684723224
102
117
  required_rubygems_version: !ruby/object:Gem::Requirement
103
118
  none: false
104
119
  requirements:
105
120
  - - ! '>='
106
121
  - !ruby/object:Gem::Version
107
122
  version: '0'
123
+ segments:
124
+ - 0
125
+ hash: -3943333428684723224
108
126
  requirements: []
109
127
  rubyforge_project: symilaa
110
128
  rubygems_version: 1.8.10