gatling 0.0.3 → 0.9.9

Sign up to get free protection for your applications and to get access to all the features.
data/.DS_Store ADDED
Binary file
data/.gitignore CHANGED
@@ -1,4 +1,11 @@
1
+ <<<<<<< HEAD
2
+ *.png
3
+ =======
1
4
  *.gem
2
5
  .bundle
3
6
  Gemfile.lock
4
7
  pkg/*
8
+ *.orig
9
+ test*
10
+ .idea*
11
+ >>>>>>> 942d4a993ee6a3407063786d0431cdfd553629ed
data/README.rdoc CHANGED
@@ -1,14 +1,6 @@
1
1
  = gatling
2
2
 
3
- Gatling Comparison allows one to build an Rspec / Capybara custom matcher comparing a :css or :xpath element to a referenced screenshot:
4
- Example:
5
- -----------
6
- RSpec::Matchers.define :look_like do |expected|
7
- match do |actual|
8
- Gatling::Comparison.new(expected, actual).matches?
9
- end
10
- end
11
- -----------
3
+ Gatling Comparison allows one to build an Rspec / Capybara custom matcher comparing a :css or :xpath element to a referenced screenshot.
12
4
 
13
5
  Imagemagick must be installed: $sudo apt-get install imagemagick
14
6
 
data/Rakefile CHANGED
@@ -1 +1,12 @@
1
1
  require "bundler/gem_tasks"
2
+ require 'rspec/core'
3
+ require 'rspec/core/rake_task'
4
+ require File.expand_path('spec/spec_helper.rb')
5
+
6
+ task :default => ["run"]
7
+
8
+ desc "default test run"
9
+ RSpec::Core::RakeTask.new(:run) do |t|
10
+ t.pattern = ['spec/*_spec.rb']
11
+ end
12
+
data/gatling.gemspec CHANGED
@@ -20,4 +20,7 @@ Gem::Specification.new do |s|
20
20
 
21
21
  # specify any dependencies here; for example:
22
22
  s.add_dependency "rmagick"
23
+ s.add_dependency "rspec-core"
24
+ s.add_dependency "rspec"
25
+ s.add_dependency "capybara"
23
26
  end
data/lib/gatling.rb CHANGED
@@ -1,5 +1,4 @@
1
1
  require 'RMagick'
2
- include Magick
3
2
 
4
3
  module Gatling
5
4
  class Comparison
@@ -7,7 +6,6 @@ module Gatling
7
6
  #TODO: Training mode
8
7
  #TODO: Diff with reports
9
8
  #TODO: Canidate in spec
10
- #TODO: Point ref files to desired folder
11
9
  #TODO: Fuzz matches
12
10
  #TODO: Helpers for cucumber
13
11
 
@@ -16,9 +14,15 @@ module Gatling
16
14
  @actual = actual
17
15
  end
18
16
 
17
+
19
18
  def capture
20
- page.driver.browser.save_screenshot('temp.png')
21
- temp_screenshot = Magick::Image.read('temp.png').first
19
+ temp_dir = "#{@reference_image_path}/temp"
20
+
21
+ FileUtils::mkdir_p(temp_dir) unless File.exists?(temp_dir)
22
+
23
+ #captures the uncropped full screen
24
+ page.driver.browser.save_screenshot("#{temp_dir}/temp.png")
25
+ temp_screenshot = Magick::Image.read("#{temp_dir}/temp.png").first
22
26
  end
23
27
 
24
28
  def crop_element
@@ -28,27 +32,53 @@ module Gatling
28
32
  capture.crop(location.x, location.y, size.width, size.height)
29
33
  end
30
34
 
31
- def save_crop_as_reference(cropped_element)
35
+ def save_crop_as_reference(cropped_element)
36
+ candidate_path = "#{@reference_image_path}/candidate"
37
+
38
+ FileUtils::mkdir_p(candidate_path) unless File.exists?(candidate_path)
39
+
32
40
  filename = "#{@expected}".sub(/\.[a-z]*/,'')
33
- cropped_element.write("#{filename}_candidate.png")
34
- return filename
41
+ cropped_element.write("#{candidate_path}/#{filename}_candidate.png")
42
+ candidate = "#{candidate_path}/#{filename}_candidate.png"
35
43
  end
36
44
 
37
45
 
38
46
  def matches?
47
+ @reference_image_path = Gatling::Configuration.reference_image_path
39
48
  cropped_element = crop_element
40
49
  if File.exists?(@expected)
41
50
  expected_img = Magick::Image.read(@expected).first
42
- diff_metric = cropped_element.compare_channel(expected_img, MeanAbsoluteErrorMetric)
51
+ diff_metric = cropped_element.compare_channel(expected_img, Magick::MeanAbsoluteErrorMetric)
43
52
  matches = diff_metric[1] == 0.0
44
53
  diff_metric.first.write('diff.png') unless matches
45
54
  matches
46
55
  else
47
- filename = save_crop_as_reference(cropped_element)
48
- raise "The design reference #{@expected} does not exist, #{filename}_candidate.png is now available to be used as a reference"
56
+ candidate = save_crop_as_reference(cropped_element)
57
+ raise "The design reference #{@expected} does not exist, #{candidate} is now available to be used as a reference"
49
58
  end
50
59
  end
51
60
  end
52
- end
61
+
62
+ module Configuration
63
+
64
+ class << self
65
+
66
+ attr_accessor 'reference_image_path'
67
+
68
+ def reference_image_path
69
+ begin
70
+ @reference_image_path ||= File.join(Rails.root, 'spec/reference_images')
71
+ rescue NameError
72
+ puts "Not using Rails? Please set the reference_image_path"
73
+ end
74
+ end
75
+
76
+ end
77
+
78
+ end
79
+
80
+ end
81
+
82
+
53
83
 
54
84
 
@@ -1,3 +1,3 @@
1
1
  module Gatling
2
- VERSION = "0.0.3"
2
+ VERSION = "0.9.9"
3
3
  end
@@ -0,0 +1,9 @@
1
+ require 'spec_helper'
2
+ require 'gatling'
3
+
4
+ RSpec::Matchers.define :look_like do |expected|
5
+ match do |actual|
6
+ compare = Gatling::Comparison.new(expected, actual)
7
+ compare.matches?
8
+ end
9
+ end
@@ -0,0 +1,31 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Gatling::Configuration" do
4
+
5
+ describe "#reference_image_path" do
6
+
7
+ before do
8
+ begin
9
+ # Check that rails exists, otherwise fake it for the test
10
+ Module.const_get("Rails")
11
+ rescue NameError
12
+ module Rails
13
+ def self.root
14
+ "fake_rails_root"
15
+ end
16
+ end
17
+ end
18
+ end
19
+
20
+ it "should default to <Rails.root>/spec/reference_images" do
21
+ Gatling::Configuration.reference_image_path.should eql("fake_rails_root/spec/reference_images")
22
+ end
23
+
24
+ it "should be overrideable" do
25
+ Gatling::Configuration.reference_image_path = "my custom path"
26
+ Gatling::Configuration.reference_image_path.should eql("my custom path")
27
+ end
28
+
29
+ end
30
+
31
+ end
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+
3
+ # before(:all) do
4
+ # @expected_image =
5
+ # @page_to_capture =
6
+ #
7
+ # end
8
+
9
+
10
+ describe 'creating an initial reference (expected) image' do
11
+ pending
12
+ end
13
+
14
+ describe 'captured and referenced images match' do
15
+ pending
16
+ end
17
+
18
+ describe 'captured and referenced images do NOT match' do
19
+ pending
20
+ end
21
+
22
+
23
+
24
+
@@ -0,0 +1,9 @@
1
+ require 'capybara'
2
+ require 'capybara/dsl'
3
+ require 'gatling'
4
+ require 'matchers/look_like_matcher.rb'
5
+
6
+ Capybara.default_driver = :selenium
7
+ Capybara.app_host = 'http://www.google.com'
8
+
9
+
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: 0.0.3
4
+ version: 0.9.9
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: 2011-12-02 00:00:00.000000000Z
12
+ date: 2011-12-06 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rmagick
16
- requirement: &70159714602700 !ruby/object:Gem::Requirement
16
+ requirement: &70344792244780 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,7 +21,40 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70159714602700
24
+ version_requirements: *70344792244780
25
+ - !ruby/object:Gem::Dependency
26
+ name: rspec-core
27
+ requirement: &70344792244340 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70344792244340
36
+ - !ruby/object:Gem::Dependency
37
+ name: rspec
38
+ requirement: &70344792243880 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :runtime
45
+ prerelease: false
46
+ version_requirements: *70344792243880
47
+ - !ruby/object:Gem::Dependency
48
+ name: capybara
49
+ requirement: &70344792243340 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :runtime
56
+ prerelease: false
57
+ version_requirements: *70344792243340
25
58
  description: Add visual comparison matchers for rspec
26
59
  email:
27
60
  - grotbart@gmail.com
@@ -29,15 +62,22 @@ executables: []
29
62
  extensions: []
30
63
  extra_rdoc_files: []
31
64
  files:
65
+ - .DS_Store
32
66
  - .gitignore
33
67
  - Gemfile
68
+ - Gemfile.lock
34
69
  - LICENSE.txt
35
70
  - README.rdoc
36
71
  - Rakefile
72
+ - gatling-0.0.3.gem
37
73
  - gatling.gemspec
38
- - gatling.gemspec.orig
39
74
  - lib/gatling.rb
40
75
  - lib/gatling/version.rb
76
+ - lib/matchers/look_like_matcher.rb
77
+ - pkg/gatling-0.0.1.gem
78
+ - spec/configuration_spec.rb
79
+ - spec/gatling_spec.rb
80
+ - spec/spec_helper.rb
41
81
  homepage: ''
42
82
  licenses: []
43
83
  post_install_message:
@@ -58,8 +98,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
58
98
  version: '0'
59
99
  requirements: []
60
100
  rubyforge_project: gatling
61
- rubygems_version: 1.8.10
101
+ rubygems_version: 1.8.12
62
102
  signing_key:
63
103
  specification_version: 3
64
104
  summary: Automated visual testing
65
- test_files: []
105
+ test_files:
106
+ - spec/configuration_spec.rb
107
+ - spec/gatling_spec.rb
108
+ - spec/spec_helper.rb
data/gatling.gemspec.orig DELETED
@@ -1,30 +0,0 @@
1
- # -*- encoding: utf-8 -*-
2
- $:.push File.expand_path("../lib", __FILE__)
3
- require "gatling/version"
4
-
5
- Gem::Specification.new do |s|
6
- s.name = "gatling"
7
- s.version = Gatling::VERSION
8
- s.authors = ["Gabriel Rotbart, Amanda Koh"]
9
- s.email = ["grotbart@gmail.com"]
10
- s.homepage = ""
11
- s.summary = %q{Automated visual testing}
12
- s.description = %q{Add visual comparison matchers for rspec}
13
-
14
- s.rubyforge_project = "gatling"
15
-
16
- s.files = `git ls-files`.split("\n")
17
- s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
- s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
- s.require_paths = ["lib"]
20
-
21
- # specify any dependencies here; for example:
22
- <<<<<<< HEAD
23
- s.add_dependency "rspec"
24
- s.add_dependency "rmagick"
25
- s.add_dependency "selenium-client"
26
- s.add_dependency "capybara"
27
- =======
28
- s.add_dependency "rmagick"
29
- >>>>>>> 01f1c5b58a3aa249141ef026447e2fbe9f5a8b0f
30
- end