splendid 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 +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +27 -0
- data/lib/image_compare.rb +45 -0
- data/lib/proxy.rb +42 -0
- data/lib/splendid.rb +45 -0
- data/lib/splendid/version.rb +3 -0
- data/splendid.gemspec +26 -0
- metadata +111 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 675c362ac5a32edef9e26b1ea436c6523562752e
|
4
|
+
data.tar.gz: 19427d5af4b2f45ae80a645b8902e03b9e40d3fd
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ff58f35ecd192fe251171f8c23be02a2d0961cd3ce3492667947a05a887957e8103887e0dc62cdc79b37e3a271a0d7e746eab3cb149f2fd4d9658b0e7a0b41e4
|
7
|
+
data.tar.gz: 50767dbfdb6b501e40a768de156e6372c1853f5b2b311d049d9e2ce67bb2b004d149a2d73ef5821c57b575f73f459b607a43acfc1ed6766fa7cc79712170c047
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Shervin Aflatooni
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Splendid
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'splendid'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install splendid
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it ( http://github.com/<my-github-username>/splendid/fork )
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
|
3
|
+
# Console
|
4
|
+
task :console do
|
5
|
+
require 'irb'
|
6
|
+
require 'irb/completion'
|
7
|
+
require 'splendid'
|
8
|
+
require 'proxy'
|
9
|
+
require 'image_compare'
|
10
|
+
|
11
|
+
def test
|
12
|
+
Splendid.create_good_copy('http://localhost:3000/')
|
13
|
+
end
|
14
|
+
|
15
|
+
def test2
|
16
|
+
Splendid.looks_good?('http://localhost:3000/')
|
17
|
+
end
|
18
|
+
|
19
|
+
def test3
|
20
|
+
p = Proxy.new('www.microlancer.com')
|
21
|
+
p.start
|
22
|
+
end
|
23
|
+
|
24
|
+
ARGV.clear
|
25
|
+
|
26
|
+
IRB.start
|
27
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'chunky_png'
|
2
|
+
|
3
|
+
class ImageCompare
|
4
|
+
def self.compare(test_img_blob, good_img_blob)
|
5
|
+
new(test_img_blob, good_img_blob).compare
|
6
|
+
end
|
7
|
+
|
8
|
+
def initialize(test_img_blob, good_img_blob)
|
9
|
+
@test_img_blob = test_img_blob
|
10
|
+
@good_img_blob = good_img_blob
|
11
|
+
end
|
12
|
+
|
13
|
+
def compare
|
14
|
+
diff = []
|
15
|
+
|
16
|
+
good_img.height.times do |y|
|
17
|
+
good_img.row(y).each_with_index do |pixel, x|
|
18
|
+
diff << [x,y] unless pixel == test_img[x,y]
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
changed_percent = diff.length.to_f / good_img.pixels.length
|
23
|
+
|
24
|
+
puts "pixels (total): #{good_img.pixels.length}"
|
25
|
+
puts "pixels changed: #{diff.length}"
|
26
|
+
puts "pixels changed (%): #{changed_percent * 100}%"
|
27
|
+
|
28
|
+
if diff.length > 0
|
29
|
+
x, y = diff.map{ |xy| xy[0] }, diff.map{ |xy| xy[1] }
|
30
|
+
|
31
|
+
test_img.rect(x.min, y.min, x.max, y.max, ChunkyPNG::Color.rgb(0,255,0))
|
32
|
+
test_img.save('diff.png')
|
33
|
+
end
|
34
|
+
|
35
|
+
changed_percent
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_img
|
39
|
+
@test_img ||= ChunkyPNG::Image.from_blob(@test_img_blob)
|
40
|
+
end
|
41
|
+
|
42
|
+
def good_img
|
43
|
+
@good_img ||= ChunkyPNG::Image.from_blob(@good_img_blob)
|
44
|
+
end
|
45
|
+
end
|
data/lib/proxy.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'socket'
|
2
|
+
|
3
|
+
class Proxy
|
4
|
+
def initialize(hostname)
|
5
|
+
@hostname = 'http://www.tutorialspoint.com/'
|
6
|
+
end
|
7
|
+
|
8
|
+
def start
|
9
|
+
server = TCPServer.open(12345)
|
10
|
+
|
11
|
+
loop do
|
12
|
+
Thread.start(server.accept) do |client|
|
13
|
+
socket = TCPSocket.open(@hostname, 80)
|
14
|
+
while line = client.gets
|
15
|
+
socket.print line
|
16
|
+
client.send socket.read
|
17
|
+
end
|
18
|
+
# input = fix_input(client.recv(1024))
|
19
|
+
# puts "Input: #{input}"
|
20
|
+
# output = injected_output(input)
|
21
|
+
# puts "Sending: #{output}"
|
22
|
+
# client.puts output
|
23
|
+
client.close
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def injected_output(request)
|
29
|
+
socket = TCPSocket.open(@hostname, 80)
|
30
|
+
puts "Sending request"
|
31
|
+
request_to_send = "#{request}\r\n\r\n"
|
32
|
+
socket.print(request_to_send)
|
33
|
+
puts "Getting Response"
|
34
|
+
response = socket.read
|
35
|
+
socket.close
|
36
|
+
response
|
37
|
+
end
|
38
|
+
|
39
|
+
def fix_input(input)
|
40
|
+
input.gsub(/localhost:12345/, "#{@hostname}:80")
|
41
|
+
end
|
42
|
+
end
|
data/lib/splendid.rb
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'imgkit'
|
3
|
+
require 'nokogiri'
|
4
|
+
require 'tmpdir'
|
5
|
+
require 'pathname'
|
6
|
+
require "splendid/version"
|
7
|
+
require 'digest/md5'
|
8
|
+
|
9
|
+
class Splendid
|
10
|
+
def self.looks_good?(uri)
|
11
|
+
new(uri).looks_good?
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.create_good_copy(uri)
|
15
|
+
new(uri).create_good_copy
|
16
|
+
end
|
17
|
+
|
18
|
+
def initialize(uri)
|
19
|
+
@uri = uri
|
20
|
+
end
|
21
|
+
|
22
|
+
def looks_good?
|
23
|
+
test_img = to_image(@uri).to_img(:png)
|
24
|
+
ImageCompare.compare(test_img, good_copy_img) < 0.1
|
25
|
+
end
|
26
|
+
|
27
|
+
def create_good_copy
|
28
|
+
img = to_image(@uri)
|
29
|
+
img.to_file("tmp/#{file_name}")
|
30
|
+
end
|
31
|
+
|
32
|
+
def good_copy_img
|
33
|
+
File.read("tmp/#{file_name}")
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def to_image(url)
|
39
|
+
IMGKit.new(url, :"disable-javascript" => true, :quality => 5, :zoom => 0.4, :width => 500, :height => 1000)
|
40
|
+
end
|
41
|
+
|
42
|
+
def file_name
|
43
|
+
"splendid_#{Digest::MD5.hexdigest(@uri)}.png"
|
44
|
+
end
|
45
|
+
end
|
data/splendid.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'splendid/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "splendid"
|
8
|
+
spec.version = Splendid::VERSION
|
9
|
+
spec.authors = ["Shervin Aflatooni"]
|
10
|
+
spec.email = ["shervinaflatooni@gmail.com"]
|
11
|
+
spec.summary = "Check if your site looks as expected"
|
12
|
+
spec.description = "Want to test if a webpage looks as expected? Use splendid in your tests to make sure styles are not broken on your site!"
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
|
24
|
+
spec.add_dependency "imgkit"
|
25
|
+
spec.add_dependency "chunky_png"
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: splendid
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Shervin Aflatooni
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-03-17 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.5'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.5'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: imgkit
|
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: chunky_png
|
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: Want to test if a webpage looks as expected? Use splendid in your tests
|
70
|
+
to make sure styles are not broken on your site!
|
71
|
+
email:
|
72
|
+
- shervinaflatooni@gmail.com
|
73
|
+
executables: []
|
74
|
+
extensions: []
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- ".gitignore"
|
78
|
+
- Gemfile
|
79
|
+
- LICENSE.txt
|
80
|
+
- README.md
|
81
|
+
- Rakefile
|
82
|
+
- lib/image_compare.rb
|
83
|
+
- lib/proxy.rb
|
84
|
+
- lib/splendid.rb
|
85
|
+
- lib/splendid/version.rb
|
86
|
+
- splendid.gemspec
|
87
|
+
homepage: ''
|
88
|
+
licenses:
|
89
|
+
- MIT
|
90
|
+
metadata: {}
|
91
|
+
post_install_message:
|
92
|
+
rdoc_options: []
|
93
|
+
require_paths:
|
94
|
+
- lib
|
95
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
96
|
+
requirements:
|
97
|
+
- - ">="
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '0'
|
100
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
requirements: []
|
106
|
+
rubyforge_project:
|
107
|
+
rubygems_version: 2.2.2
|
108
|
+
signing_key:
|
109
|
+
specification_version: 4
|
110
|
+
summary: Check if your site looks as expected
|
111
|
+
test_files: []
|