image_spec 0.0.3 → 0.0.4

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.
data/README.md CHANGED
@@ -1,5 +1,47 @@
1
- # Usage
1
+ # Overview
2
+
3
+ This gem provides a set of RSpec matchers to allow relative comparisons of images.
4
+
5
+ e.g. User.image.should look_like(otherimage)
6
+
7
+ # Requirements
8
+
9
+ The gem has only been tested with Rails 3 and RSpec 2.
10
+
11
+ It also relies on imagemagick being installed and available from the command line as it utilisies its 'identify' command. The Gem has only been tested with Imagemagick V6.x.
12
+
13
+ # Setup
14
+
15
+ Include the gem in your Gemfile:-
16
+
17
+ ~~~~ { ruby }
18
+ gem 'image-spec'
19
+ ~~~~
20
+
21
+ include the matchers in your spec_helper.rb:-
2
22
 
3
23
  ~~~~ { ruby }
4
24
  require 'image_spec/matchers'
5
25
  ~~~~
26
+
27
+ #Usage
28
+
29
+ ###look_like
30
+
31
+ Allows you to test that an image is within a 1% of the expected image e.g.
32
+
33
+ ~~~~ { ruby }
34
+ actual.should look_like(expected)
35
+ ~~~~
36
+
37
+ or
38
+
39
+ ~~~~ { ruby }
40
+ user.picture.path(:thumb).should look_like(fixtures('member_picture/thumb/test.png'))
41
+ ~~~~
42
+
43
+ ###have_image_that_looks_like
44
+
45
+ Test if a page contains an image that is like the stated image e.g.
46
+
47
+
@@ -1,7 +1,7 @@
1
1
 
2
2
  Gem::Specification.new do |s|
3
3
  s.name = 'image_spec'
4
- s.version = '0.0.3'
4
+ s.version = '0.0.4'
5
5
  s.authors = ["Matt Wynne, Mike Howson"]
6
6
  s.description = 'A library of Rspec matchers to allow comparison of similar images'
7
7
  s.summary = "image_spec-#{s.version}"
@@ -14,7 +14,7 @@ module ImageSpec
14
14
  def score
15
15
  raise "Expected image path is blank" unless @expected
16
16
  raise "Actual image path is blank" unless @actual
17
-
17
+
18
18
  [@expected, @actual].each do |path|
19
19
  raise "No such file! (#{path})" unless File.exists?(path.to_s)
20
20
  end
@@ -81,8 +81,7 @@ RSpec::Matchers.define(:have_image_that_looks_like) do |expected_file_path|
81
81
 
82
82
  def any_images_look_similar?
83
83
  urls = page.all(:xpath, '//img/@src').map(&:text)
84
- clean_urls = urls.map { |url| url.gsub(/\?\d+$/, '') }
85
- actual_paths = clean_urls.map { |url| File.join(Rails.root, 'public', url) }
84
+ actual_paths = image_paths(urls)
86
85
 
87
86
  actual_paths.any? do |actual_path|
88
87
  looks_like?(actual_path)
@@ -98,5 +97,26 @@ RSpec::Matchers.define(:have_image_that_looks_like) do |expected_file_path|
98
97
  def comparison_with(other_file)
99
98
  ImageSpec::Comparison.new(@expected_file_path, other_file)
100
99
  end
100
+
101
+ def image_paths(urls)
102
+ urls.map {|url| find_image_file(url) }
103
+ end
104
+
105
+ def find_image_file(url)
106
+ clean_url = url.gsub(/\?\d+$/, '')
107
+ if url =~ /^\/assets\//
108
+ path = File.join(Rails.root, clean_url.gsub(/^\/assets\//, '/app/assets/images/'))
109
+ return path if File.exists?(path)
110
+ elsif url =~ /^\/images\//
111
+ asset_path = File.join(Rails.root, clean_url.gsub(/^\/images\//, '/app/assets/images/'))
112
+ return asset_path if File.exists?(asset_path)
113
+ end
114
+ rails_path = File.join(Rails.root, File.join('public', clean_url))
115
+ if File.exists?(rails_path)
116
+ rails_path
117
+ else
118
+ url
119
+ end
120
+ end
101
121
  end
102
122
 
metadata CHANGED
@@ -1,33 +1,24 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: image_spec
3
- version: !ruby/object:Gem::Version
4
- hash: 25
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.4
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 0
9
- - 3
10
- version: 0.0.3
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Matt Wynne, Mike Howson
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2011-06-09 00:00:00 Z
12
+ date: 2012-10-08 00:00:00.000000000 Z
19
13
  dependencies: []
20
-
21
14
  description: A library of Rspec matchers to allow comparison of similar images
22
15
  email: mikehowson@gmail.com
23
16
  executables: []
24
-
25
17
  extensions: []
26
-
27
- extra_rdoc_files:
18
+ extra_rdoc_files:
28
19
  - LICENSE
29
20
  - README.md
30
- files:
21
+ files:
31
22
  - .gitignore
32
23
  - LICENSE
33
24
  - README.md
@@ -35,36 +26,27 @@ files:
35
26
  - lib/image_spec/matchers.rb
36
27
  homepage: http://github.com/mikehowson/image_spec
37
28
  licenses: []
38
-
39
29
  post_install_message:
40
- rdoc_options:
30
+ rdoc_options:
41
31
  - --charset=UTF-8
42
- require_paths:
32
+ require_paths:
43
33
  - lib
44
- required_ruby_version: !ruby/object:Gem::Requirement
34
+ required_ruby_version: !ruby/object:Gem::Requirement
45
35
  none: false
46
- requirements:
47
- - - ">="
48
- - !ruby/object:Gem::Version
49
- hash: 3
50
- segments:
51
- - 0
52
- version: "0"
53
- required_rubygems_version: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ! '>='
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
41
  none: false
55
- requirements:
56
- - - ">="
57
- - !ruby/object:Gem::Version
58
- hash: 3
59
- segments:
60
- - 0
61
- version: "0"
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
62
46
  requirements: []
63
-
64
47
  rubyforge_project:
65
- rubygems_version: 1.8.5
48
+ rubygems_version: 1.8.24
66
49
  signing_key:
67
50
  specification_version: 3
68
- summary: image_spec-0.0.3
51
+ summary: image_spec-0.0.4
69
52
  test_files: []
70
-