gatling 1.0.2 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +3 -3
- data/Gemfile +7 -0
- data/README.rdoc +42 -6
- data/Rakefile +2 -1
- data/gatling.gemspec +0 -1
- data/lib/gatling.rb +41 -63
- data/lib/gatling/capture_element.rb +51 -0
- data/lib/gatling/config.rb +36 -0
- data/lib/gatling/version.rb +1 -1
- data/spec/configuration_spec.rb +37 -1
- data/spec/gatling_spec.rb +95 -12
- data/spec/rspec_matcher_spec.rb +46 -0
- data/spec/spec.opts +3 -0
- data/spec/spec_helper.rb +61 -1
- data/spec/support/assets/public/smiley-faceicon.jpg +0 -0
- data/spec/support/assets/smiley-bad.jpg +0 -0
- data/spec/support/assets/smiley_app.rb +18 -0
- data/spec/support/assets/views/smiley_site.erb +19 -0
- metadata +28 -12
data/.gitignore
CHANGED
data/Gemfile
CHANGED
data/README.rdoc
CHANGED
@@ -1,13 +1,49 @@
|
|
1
|
-
=
|
1
|
+
= Gatling
|
2
2
|
|
3
3
|
Gatling Comparison allows one to build an Rspec / Capybara custom matcher comparing a :css or :xpath element to a referenced screenshot.
|
4
4
|
|
5
|
-
|
5
|
+
-------------------------------------
|
6
|
+
|
7
|
+
Usage:
|
8
|
+
|
9
|
+
Identify an element to match, for example:
|
10
|
+
|
11
|
+
@element = page.find(:css, #button)
|
12
|
+
|
13
|
+
Use Gatling's custom matcher and specify the reference image:
|
14
|
+
|
15
|
+
@element.should look_like('button_ref.png')
|
16
|
+
|
17
|
+
Gatling will take care of cropping the element and try and make a targeted match without the noise of the whole page.
|
18
|
+
|
19
|
+
|
20
|
+
If the matcher fails, the test will fail, an exception will be raised and both a diff image and a new candidate image will be created.
|
21
|
+
|
22
|
+
|
23
|
+
If no reference image exits, the test will fail, an exception will be raised and a candidate will be created which can be used as a reference.
|
24
|
+
|
25
|
+
-------------------------------------
|
26
|
+
|
27
|
+
Usage, training mode:
|
28
|
+
|
29
|
+
Gatling can be run in training mode which will create all the initial reference images.
|
30
|
+
|
31
|
+
CAUTION: Trainer mode will pass all the test which rely on the Gatling custom matcher. Please make sure you are saving 'clean' references.
|
32
|
+
|
33
|
+
|
34
|
+
To set trainer mode, prefix rspec with $GATLING_TRAINER = true
|
35
|
+
|
36
|
+
|
37
|
+
Example:
|
38
|
+
$GATLING_TRAINER = true rspec spec/my_spec.rb
|
39
|
+
|
40
|
+
-------------------------------------
|
41
|
+
|
42
|
+
Non-gem dependencies: Imagemagick must be installed:
|
43
|
+
$sudo apt-get install imagemagick
|
44
|
+
|
45
|
+
-------------------------------------
|
6
46
|
|
7
|
-
To make this gem work with native selenium-webdriver:
|
8
|
-
in gatling.rb replace
|
9
|
-
element = @actual.native with
|
10
|
-
element = @actual
|
11
47
|
|
12
48
|
== Contributing to gatling
|
13
49
|
|
data/Rakefile
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require 'bundler/gem_tasks'
|
2
2
|
require 'rspec/core'
|
3
3
|
require 'rspec/core/rake_task'
|
4
4
|
require File.expand_path('spec/spec_helper.rb')
|
@@ -8,5 +8,6 @@ task :default => ["run"]
|
|
8
8
|
desc "default test run"
|
9
9
|
RSpec::Core::RakeTask.new(:run) do |t|
|
10
10
|
t.pattern = ['spec/*_spec.rb']
|
11
|
+
t.rspec_opts = ['--options', "spec/spec.opts"]
|
11
12
|
end
|
12
13
|
|
data/gatling.gemspec
CHANGED
@@ -18,7 +18,6 @@ Gem::Specification.new do |s|
|
|
18
18
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
19
|
s.require_paths = ["lib"]
|
20
20
|
|
21
|
-
# specify any dependencies here; for example:
|
22
21
|
s.add_dependency "rmagick"
|
23
22
|
s.add_dependency "rspec-core"
|
24
23
|
s.add_dependency "rspec"
|
data/lib/gatling.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'RMagick'
|
2
|
+
require_relative 'gatling/capture_element'
|
2
3
|
require 'capybara'
|
3
4
|
require 'capybara/dsl'
|
4
5
|
|
@@ -6,7 +7,7 @@ require 'capybara/dsl'
|
|
6
7
|
module Gatling
|
7
8
|
class Comparison
|
8
9
|
include Capybara::DSL
|
9
|
-
|
10
|
+
|
10
11
|
#TODO: Training mode
|
11
12
|
#TODO: Diff with reports
|
12
13
|
#TODO: Fuzz matches
|
@@ -16,36 +17,14 @@ module Gatling
|
|
16
17
|
@expected = expected
|
17
18
|
@actual = actual
|
18
19
|
|
20
|
+
@capture_element = Gatling::CaptureElement.new(@actual)
|
21
|
+
|
19
22
|
@reference_image_path = Gatling::Configuration.reference_image_path
|
23
|
+
@trainer_toggle = Gatling::Configuration.trainer_toggle
|
24
|
+
|
20
25
|
@expected_image = "#{@reference_image_path}/#{@expected}"
|
21
26
|
@expected_filename = "#{@expected}".sub(/\.[a-z]*/,'')
|
22
|
-
end
|
23
|
-
|
24
|
-
|
25
|
-
def capture
|
26
|
-
temp_dir = "#{@reference_image_path}/temp"
|
27
27
|
|
28
|
-
FileUtils::mkdir_p(temp_dir)
|
29
|
-
|
30
|
-
#captures the uncropped full screen
|
31
|
-
page.driver.browser.save_screenshot("#{temp_dir}/temp.png")
|
32
|
-
temp_screenshot = Magick::Image.read("#{temp_dir}/temp.png").first
|
33
|
-
end
|
34
|
-
|
35
|
-
def crop_element
|
36
|
-
element = @actual.native
|
37
|
-
location = element.location
|
38
|
-
size = element.size
|
39
|
-
capture.crop(location.x, location.y, size.width, size.height)
|
40
|
-
end
|
41
|
-
|
42
|
-
def save_crop_as_reference(cropped_element)
|
43
|
-
candidate_path = "#{@reference_image_path}/candidate"
|
44
|
-
|
45
|
-
FileUtils::mkdir_p(candidate_path)
|
46
|
-
|
47
|
-
cropped_element.write("#{candidate_path}/#{@expected_filename}.png")
|
48
|
-
candidate = "#{candidate_path}/#{@expected_filename}.png"
|
49
28
|
end
|
50
29
|
|
51
30
|
def create_diff
|
@@ -55,55 +34,54 @@ module Gatling
|
|
55
34
|
|
56
35
|
@diff_metric.first.write("#{diff_path}/#{@expected_filename}_diff.png")
|
57
36
|
|
58
|
-
candidate =
|
37
|
+
candidate = save_element_as_candidate(@cropped_element)
|
59
38
|
raise "element did not match #{@expected}. A diff image: #{@expected_filename}_diff.png was created in #{diff_path}. A new reference #{candidate} can be used to fix the test"
|
60
39
|
end
|
61
40
|
|
41
|
+
def save_element_as_candidate(element)
|
42
|
+
candidate_path = "#{@reference_image_path}/candidate"
|
43
|
+
candidate = @capture_element.save_element(element, @expected_filename, candidate_path)
|
44
|
+
end
|
62
45
|
|
63
|
-
def
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
matches = @diff_metric[1] == 0.0
|
73
|
-
|
74
|
-
create_diff unless matches
|
46
|
+
def save_element_as_reference(element)
|
47
|
+
if File.exists?(@expected_image) == false
|
48
|
+
@capture_element.save_element(element, @expected_filename, @reference_image_path)
|
49
|
+
puts "Saved #{@expected_image} as reference"
|
50
|
+
else
|
51
|
+
puts "#{@expected_image.upcase} ALREADY EXISTS. REFERENCE IMAGE WAS NOT OVERWRITTEN. PLEASE DELETE OLD FILE TO UPDATE USING TRAINER"
|
52
|
+
end
|
53
|
+
end
|
75
54
|
|
76
|
-
|
55
|
+
def matches?
|
56
|
+
@cropped_element = @capture_element.crop
|
57
|
+
if !@trainer_toggle
|
58
|
+
if File.exists?(@expected_image)
|
59
|
+
self.compare
|
60
|
+
else
|
61
|
+
candidate = self.save_element_as_candidate(@cropped_element)
|
62
|
+
raise "The design reference #{@expected} does not exist, #{candidate} is now available to be used as a reference. Copy candidate to root reference_image_path to use as reference"
|
63
|
+
end
|
77
64
|
else
|
78
|
-
|
79
|
-
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
module Configuration
|
65
|
+
self.save_element_as_reference(@cropped_element)
|
66
|
+
matches = true
|
67
|
+
end
|
68
|
+
end
|
85
69
|
|
86
|
-
|
70
|
+
def compare
|
71
|
+
expected_img = Magick::Image.read(@expected_image).first
|
87
72
|
|
88
|
-
|
73
|
+
@diff_metric = @cropped_element.compare_channel(expected_img, Magick::MeanAbsoluteErrorMetric)
|
89
74
|
|
90
|
-
|
91
|
-
#if defined?(Rails) or @reference_image_path.nil?
|
92
|
-
# @reference_image_path ||= File.join(Rails.root, 'spec/reference_images')
|
93
|
-
#end
|
94
|
-
begin
|
95
|
-
@reference_image_path ||= File.join(Rails.root, 'spec/reference_images')
|
96
|
-
rescue
|
97
|
-
raise "Not using Rails? Please set the reference_image_path"
|
98
|
-
end
|
99
|
-
end
|
75
|
+
matches = @diff_metric[1] == 0.0
|
100
76
|
|
77
|
+
create_diff unless matches
|
78
|
+
|
79
|
+
matches
|
101
80
|
end
|
102
|
-
|
103
81
|
end
|
104
|
-
|
82
|
+
|
105
83
|
end
|
106
84
|
|
107
85
|
|
108
|
-
|
86
|
+
|
109
87
|
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module Gatling
|
2
|
+
class CaptureElement
|
3
|
+
|
4
|
+
def initialize element_to_capture
|
5
|
+
@reference_image_path = Gatling::Configuration.reference_image_path
|
6
|
+
@element = element_to_capture
|
7
|
+
end
|
8
|
+
|
9
|
+
def capture
|
10
|
+
temp_dir = "#{@reference_image_path}/temp"
|
11
|
+
|
12
|
+
begin
|
13
|
+
FileUtils::mkdir_p(temp_dir)
|
14
|
+
rescue
|
15
|
+
puts "Could not create directory #{temp_dir}. Please make sure you have permission"
|
16
|
+
end
|
17
|
+
|
18
|
+
#captures the uncropped full screen
|
19
|
+
begin
|
20
|
+
page.driver.browser.save_screenshot("#{temp_dir}/temp.png")
|
21
|
+
temp_screenshot = Magick::Image.read("#{temp_dir}/temp.png").first
|
22
|
+
rescue
|
23
|
+
raise "Could not save screenshot to #{temp_dir}. Please make sure you have permission"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def crop
|
28
|
+
element = @element.native
|
29
|
+
location = element.location
|
30
|
+
size = element.size
|
31
|
+
@cropped_element = self.capture.crop(location.x, location.y, size.width, size.height)
|
32
|
+
end
|
33
|
+
|
34
|
+
def save_element(element, element_name, path)
|
35
|
+
begin
|
36
|
+
FileUtils::mkdir_p(path)
|
37
|
+
rescue
|
38
|
+
puts "Could not create directory #{path}. Please make sure you have permission"
|
39
|
+
end
|
40
|
+
|
41
|
+
begin
|
42
|
+
element.write("#{path}/#{element_name}.png")
|
43
|
+
element = "#{path}/#{element_name}.png"
|
44
|
+
rescue
|
45
|
+
raise "Could not save #{element_name} to #{path}. Please make sure you have permission"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Gatling
|
2
|
+
module Configuration
|
3
|
+
|
4
|
+
class << self
|
5
|
+
|
6
|
+
attr_accessor 'reference_image_path', 'trainer_toggle'
|
7
|
+
|
8
|
+
def reference_image_path
|
9
|
+
begin
|
10
|
+
@reference_image_path ||= File.join(Rails.root, 'spec/reference_images')
|
11
|
+
rescue
|
12
|
+
raise "Not using Rails? Please set the reference_image_path"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def trainer_toggle
|
17
|
+
@trainer_value = ENV['GATLING_TRAINER']
|
18
|
+
|
19
|
+
case @trainer_value
|
20
|
+
when nil
|
21
|
+
@trainer_value = nil
|
22
|
+
when 'true'
|
23
|
+
@trainer_value = true
|
24
|
+
when 'false'
|
25
|
+
@trainer_value = false
|
26
|
+
else
|
27
|
+
@trainer_value = false
|
28
|
+
puts 'Unknown GATLING_TRAINER argument. Please supply true, false or nil. DEFAULTING TO FALSE'
|
29
|
+
end
|
30
|
+
@trainer_toggle ||= @trainer_value ||= false
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|
data/lib/gatling/version.rb
CHANGED
data/spec/configuration_spec.rb
CHANGED
@@ -17,15 +17,51 @@ describe "Gatling::Configuration" do
|
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
|
+
|
21
|
+
|
20
22
|
it "should default to <Rails.root>/spec/reference_images" do
|
21
23
|
Gatling::Configuration.reference_image_path.should eql("fake_rails_root/spec/reference_images")
|
22
24
|
end
|
23
25
|
|
24
|
-
it "should be overrideable" do
|
26
|
+
it "should be overrideable" do
|
25
27
|
Gatling::Configuration.reference_image_path = "my custom path"
|
26
28
|
Gatling::Configuration.reference_image_path.should eql("my custom path")
|
27
29
|
end
|
30
|
+
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
describe '#trainer_toggle' do
|
35
|
+
|
36
|
+
it 'should default to false' do
|
37
|
+
Gatling::Configuration.trainer_toggle.should eql(false)
|
38
|
+
end
|
28
39
|
|
40
|
+
it 'can be toggled to true' do
|
41
|
+
Gatling::Configuration.trainer_toggle = true
|
42
|
+
Gatling::Configuration.trainer_toggle.should eql(true)
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'toggeled using GATLING_TRAINER = false' do
|
46
|
+
ENV['GATLING_TRAINER'] = 'false'
|
47
|
+
Gatling::Configuration.trainer_toggle.should eql(false)
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'toggeled using GATLING_TRAINER = true' do
|
51
|
+
ENV['GATLING_TRAINER'] = 'true'
|
52
|
+
Gatling::Configuration.trainer_toggle.should eql(true)
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'toggeled using GATLING_TRAINER = nil' do
|
56
|
+
ENV['GATLING_TRAINER'] = nil
|
57
|
+
Gatling::Configuration.trainer_toggle.should eql(false)
|
58
|
+
end
|
59
|
+
|
60
|
+
after(:each) do
|
61
|
+
Gatling::Configuration.trainer_toggle = false
|
62
|
+
ENV['GATLING_TRAINER'] = nil
|
63
|
+
end
|
64
|
+
|
29
65
|
end
|
30
66
|
|
31
67
|
end
|
data/spec/gatling_spec.rb
CHANGED
@@ -1,24 +1,107 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
+
include Capybara::DSL
|
2
3
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
4
|
+
|
5
|
+
describe 'Gatling' do
|
6
|
+
|
7
|
+
|
8
|
+
before(:all) do
|
9
|
+
|
10
|
+
include Rack::Test::Methods
|
11
|
+
|
12
|
+
def app
|
13
|
+
Sinatra::Application
|
14
|
+
end
|
15
|
+
|
16
|
+
#expected image to compare with
|
17
|
+
@example_good_image = 'smiley-faceicon.png'
|
18
|
+
|
19
|
+
@spec_support_root = spec_support_root
|
20
|
+
end
|
21
|
+
|
22
|
+
|
23
|
+
after(:each) do
|
24
|
+
remove_refs(@ref_path)
|
25
|
+
end
|
8
26
|
|
9
27
|
|
28
|
+
|
10
29
|
describe 'creating an initial reference (expected) image' do
|
11
|
-
|
30
|
+
|
31
|
+
before(:each) do
|
32
|
+
@ref_path = Gatling::Configuration.reference_image_path = File.join(@spec_support_root, 'ref_path')
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should notify that no reference exists for image and create a candidate" do
|
36
|
+
gatling = gatling_for_spec('smiley-faceicon.png')
|
37
|
+
expect {gatling.matches?}.should raise_error(RuntimeError, "The design reference #{@example_good_image} does not exist, #{@ref_path}/candidate/#{@example_good_image} is now available to be used as a reference. Copy candidate to root reference_image_path to use as reference")
|
38
|
+
File.exists?(File.join(@ref_path,'candidate','smiley-faceicon.png')).should be_true
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
|
43
|
+
|
44
|
+
describe 'image comparison' do
|
45
|
+
|
46
|
+
before(:each) do
|
47
|
+
# @ready_ref = Gatling::Configuration.reference_image_path = File.join(@spec_support_root, 'ready_candidate_ref')
|
48
|
+
@ref_path = Gatling::Configuration.reference_image_path = File.join(@spec_support_root, 'ref_path')
|
49
|
+
save_element_for_test
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'images match' do
|
53
|
+
@gatling = gatling_for_spec('smiley-faceicon.png')
|
54
|
+
@gatling.matches?.should be_true
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'images do not match and diff created' do
|
58
|
+
#convert -fill none -stroke black -strokewidth 5 smiley-faceicon.png -draw 'arc 155,25 185,45 180' sad-faceicon.png
|
59
|
+
convert_element_to_bad_element(File.join(@ref_path,"#{@example_good_image}"))
|
60
|
+
gatling = gatling_for_spec('smiley-faceicon.png')
|
61
|
+
expect {gatling.matches?}.should raise_error(RuntimeError, "element did not match #{@example_good_image}. A diff image: smiley-faceicon_diff.png was created in #{@ref_path}/diff. A new reference #{@ref_path}/candidate/#{@example_good_image} can be used to fix the test")
|
62
|
+
File.exists?(File.join(@ref_path,'diff','smiley-faceicon_diff.png')).should be_true
|
63
|
+
end
|
12
64
|
end
|
13
|
-
|
14
|
-
|
15
|
-
|
65
|
+
|
66
|
+
|
67
|
+
|
68
|
+
describe 'trainer toggle' do
|
69
|
+
|
70
|
+
before(:each) do
|
71
|
+
@ref_path = Gatling::Configuration.reference_image_path = File.join(@spec_support_root, 'ref_path')
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'should save a reference file to the nominated folder without raising an exception' do
|
75
|
+
Gatling::Configuration.trainer_toggle = true
|
76
|
+
gatling = gatling_for_spec('smiley-faceicon.png')
|
77
|
+
|
78
|
+
expect {gatling.matches?}.should_not raise_error
|
79
|
+
File.exists?(File.join(@ref_path,'smiley-faceicon.png')).should be_true
|
80
|
+
end
|
81
|
+
|
82
|
+
it 'should alert that the file should be deleted if a reference already exists and not overwrite file' do
|
83
|
+
save_element_for_test
|
84
|
+
Gatling::Configuration.trainer_toggle = true
|
85
|
+
gatling = gatling_for_spec('smiley-faceicon.png')
|
86
|
+
|
87
|
+
reference_file_ctime = File.ctime(File.join(@ref_path,'smiley-faceicon.png'))
|
88
|
+
sleep(1)
|
89
|
+
expect {gatling.matches?}.should_not raise_error
|
90
|
+
|
91
|
+
#checks if file was overwritten by comparing the time stamps
|
92
|
+
reference_file_ctime.eql?(File.ctime(File.join(@ref_path,'smiley-faceicon.png'))).should be_true
|
93
|
+
end
|
94
|
+
|
16
95
|
end
|
17
96
|
|
18
|
-
describe 'captured and referenced images do NOT match' do
|
19
|
-
pending
|
20
|
-
end
|
21
97
|
|
22
98
|
|
23
99
|
|
100
|
+
# MOCK SELENIUM ELEMENT
|
101
|
+
# correct size (340px*42px)
|
102
|
+
# image magick saves screenshot
|
103
|
+
#create diff creates the correct candidate
|
104
|
+
|
105
|
+
|
106
|
+
end
|
24
107
|
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
include Capybara::DSL
|
3
|
+
|
4
|
+
|
5
|
+
describe 'rspec matcher' do
|
6
|
+
|
7
|
+
before(:all) do
|
8
|
+
|
9
|
+
include Rack::Test::Methods
|
10
|
+
|
11
|
+
def app
|
12
|
+
Sinatra::Application
|
13
|
+
end
|
14
|
+
|
15
|
+
#expected image to compare with
|
16
|
+
@example_good_image = 'smiley-faceicon.png'
|
17
|
+
|
18
|
+
@spec_support_root = spec_support_root
|
19
|
+
|
20
|
+
@ref_path = Gatling::Configuration.reference_image_path = File.join(@spec_support_root, 'ref_path')
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
after(:each) do
|
25
|
+
remove_refs(@ref_path)
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'should initialize and run gatling' do
|
29
|
+
|
30
|
+
save_element_for_test
|
31
|
+
|
32
|
+
visit('/')
|
33
|
+
@element = page.find(:css, "#smiley")
|
34
|
+
@element.should look_like('smiley-faceicon.png')
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'should initialize and run training mode when GATLING_TRAINER is toggled' do
|
38
|
+
ENV['GATLING_TRAINER'] = 'true'
|
39
|
+
|
40
|
+
visit('/')
|
41
|
+
@element = page.find(:css, "#smiley")
|
42
|
+
@element.should look_like('smiley-faceicon.png')
|
43
|
+
File.exists?(File.join(@ref_path,'smiley-faceicon.png')).should be_true
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
data/spec/spec.opts
ADDED
data/spec/spec_helper.rb
CHANGED
@@ -1,9 +1,69 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '/support/assets/smiley_app')
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'sinatra'
|
5
|
+
Sinatra::Application.environment = :test
|
6
|
+
require 'rack/test'
|
7
|
+
# require 'spec'
|
8
|
+
# require 'spec/autorun'
|
9
|
+
# require 'spec/interop/test'
|
1
10
|
require 'capybara'
|
2
11
|
require 'capybara/dsl'
|
12
|
+
require 'capybara/rspec'
|
3
13
|
require 'gatling'
|
4
14
|
require 'gatling/matchers/look_like_matcher'
|
15
|
+
require 'fileutils'
|
16
|
+
require 'gatling/config'
|
17
|
+
|
18
|
+
RSpec.configure do |config|
|
19
|
+
config.color_enabled = true
|
20
|
+
config.formatter = 'documentation'
|
21
|
+
end
|
5
22
|
|
23
|
+
Capybara.app = Sinatra::Application
|
6
24
|
Capybara.default_driver = :selenium
|
7
|
-
|
25
|
+
|
26
|
+
def app
|
27
|
+
@app ||= Sinatra::Application
|
28
|
+
end
|
29
|
+
|
30
|
+
set :run, false
|
31
|
+
set :environment, :test
|
32
|
+
|
33
|
+
def remove_refs(dir)
|
34
|
+
FileUtils.rm_rf dir.to_s
|
35
|
+
end
|
36
|
+
|
37
|
+
def gatling_for_spec(expected)
|
38
|
+
visit('/')
|
39
|
+
@element = page.find(:css, "#smiley")
|
40
|
+
|
41
|
+
@gatling = Gatling::Comparison.new(expected, @element)
|
42
|
+
end
|
43
|
+
|
44
|
+
def spec_support_root
|
45
|
+
File.join(File.dirname(__FILE__), 'support')
|
46
|
+
end
|
47
|
+
|
48
|
+
def save_element_for_test
|
49
|
+
Gatling::Configuration.trainer_toggle = true
|
50
|
+
gatling_for_spec('smiley-faceicon.png').matches?
|
51
|
+
Gatling::Configuration.trainer_toggle = false
|
52
|
+
end
|
53
|
+
|
54
|
+
def convert_element_to_bad_element(image_file)
|
55
|
+
#convert -fill none -stroke black -strokewidth 5 smiley-faceicon.png -draw 'arc 155,25 185,45 180' sad-faceicon.png
|
56
|
+
image = Magick::Image.read(image_file).first
|
57
|
+
frown = Magick::Draw.new
|
58
|
+
frown.stroke('black')
|
59
|
+
frown.stroke_width(5)
|
60
|
+
frown.fill_opacity(0)
|
61
|
+
frown.stroke_opacity(10)
|
62
|
+
frown.arc(155,25,185,45,180,0)
|
63
|
+
frown.draw(image)
|
64
|
+
bad_element = image.write(image_file)
|
65
|
+
end
|
66
|
+
|
67
|
+
#todo: spec folders clean up method
|
8
68
|
|
9
69
|
|
Binary file
|
Binary file
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'sinatra'
|
2
|
+
|
3
|
+
set :app_file, __FILE__
|
4
|
+
|
5
|
+
set :root, File.expand_path(File.dirname(__FILE__))
|
6
|
+
set :static, true
|
7
|
+
|
8
|
+
get '/' do
|
9
|
+
erb :smiley_site
|
10
|
+
end
|
11
|
+
|
12
|
+
get '/root' do
|
13
|
+
'root is ' + settings.root
|
14
|
+
end
|
15
|
+
|
16
|
+
get '/public' do
|
17
|
+
'root is ' + settings.public_directory
|
18
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
|
2
|
+
"http://www.w3.org/TR/html4/loose.dtd">
|
3
|
+
<html>
|
4
|
+
<head>
|
5
|
+
<title>The Smiley Site</title>
|
6
|
+
<style type="text/css">
|
7
|
+
div {width:100%;}
|
8
|
+
img
|
9
|
+
{
|
10
|
+
border:1
|
11
|
+
}
|
12
|
+
</style>
|
13
|
+
</head>
|
14
|
+
<body>
|
15
|
+
<div style="width:340px;text-align:center;float:left;" id="smiley">
|
16
|
+
<img src="smiley-faceicon.jpg" alt="Smiley" height="42" width="42" />
|
17
|
+
</div>
|
18
|
+
</body>
|
19
|
+
</html>
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gatling
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.3
|
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:
|
12
|
+
date: 2012-02-19 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rmagick
|
16
|
-
requirement: &
|
16
|
+
requirement: &70310393557420 !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: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70310393557420
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rspec-core
|
27
|
-
requirement: &
|
27
|
+
requirement: &70310393556960 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70310393556960
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rspec
|
38
|
-
requirement: &
|
38
|
+
requirement: &70310393556420 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70310393556420
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: capybara
|
49
|
-
requirement: &
|
49
|
+
requirement: &70310393555900 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,7 +54,7 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :runtime
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70310393555900
|
58
58
|
description: Add visual comparison matchers for rspec
|
59
59
|
email:
|
60
60
|
- grotbart@gmail.com
|
@@ -69,15 +69,24 @@ files:
|
|
69
69
|
- LICENSE.txt
|
70
70
|
- README.rdoc
|
71
71
|
- Rakefile
|
72
|
-
- gatling-0.0.3.gem
|
73
72
|
- gatling.gemspec
|
74
73
|
- lib/gatling.rb
|
74
|
+
- lib/gatling/capture_element.rb
|
75
|
+
- lib/gatling/config.rb
|
75
76
|
- lib/gatling/matchers/look_like_matcher.rb
|
76
77
|
- lib/gatling/version.rb
|
77
78
|
- pkg/gatling-0.0.1.gem
|
79
|
+
- reports/rspec_unit_test_output.html
|
78
80
|
- spec/configuration_spec.rb
|
79
81
|
- spec/gatling_spec.rb
|
82
|
+
- spec/rspec_matcher_spec.rb
|
83
|
+
- spec/spec.opts
|
80
84
|
- spec/spec_helper.rb
|
85
|
+
- spec/support/assets/public/smiley-faceicon.jpg
|
86
|
+
- spec/support/assets/smiley-bad.jpg
|
87
|
+
- spec/support/assets/smiley_app.rb
|
88
|
+
- spec/support/assets/views/smiley_site.erb
|
89
|
+
- spec/support/ready_candidate_ref/smiley-faceicon.png
|
81
90
|
homepage: http://github.com/GabrielRotbart/gatling
|
82
91
|
licenses: []
|
83
92
|
post_install_message:
|
@@ -98,11 +107,18 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
98
107
|
version: '0'
|
99
108
|
requirements: []
|
100
109
|
rubyforge_project: gatling
|
101
|
-
rubygems_version: 1.8.
|
110
|
+
rubygems_version: 1.8.10
|
102
111
|
signing_key:
|
103
112
|
specification_version: 3
|
104
113
|
summary: Automated visual testing
|
105
114
|
test_files:
|
106
115
|
- spec/configuration_spec.rb
|
107
116
|
- spec/gatling_spec.rb
|
117
|
+
- spec/rspec_matcher_spec.rb
|
118
|
+
- spec/spec.opts
|
108
119
|
- spec/spec_helper.rb
|
120
|
+
- spec/support/assets/public/smiley-faceicon.jpg
|
121
|
+
- spec/support/assets/smiley-bad.jpg
|
122
|
+
- spec/support/assets/smiley_app.rb
|
123
|
+
- spec/support/assets/views/smiley_site.erb
|
124
|
+
- spec/support/ready_candidate_ref/smiley-faceicon.png
|