gatling 1.0.7 → 1.0.8

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.
@@ -1,8 +1,7 @@
1
1
  module Gatling
2
- class ImageWrangler
2
+ module ImageWrangler
3
3
 
4
4
  def self.get_element_position element
5
-
6
5
  element = element.native
7
6
  position = Hash.new{}
8
7
  position[:x] = element.location.x
@@ -17,8 +16,7 @@ module Gatling
17
16
  @cropped_element = image.crop(position[:x], position[:y], position[:width], position[:height])
18
17
  end
19
18
 
20
- def self.exclude image, element_to_exclude
21
- end
19
+
22
20
 
23
21
 
24
22
  end
@@ -1,3 +1,3 @@
1
1
  module Gatling
2
- VERSION = "1.0.7"
2
+ VERSION = "1.0.8"
3
3
  end
@@ -0,0 +1,94 @@
1
+ require 'spec_helper'
2
+ include Capybara::DSL
3
+
4
+ describe 'Gatling' do
5
+
6
+ before(:all) do
7
+ @spec_support_root = spec_support_root
8
+ end
9
+
10
+ before(:each) do
11
+ @ref_path = Gatling::Configuration.reference_image_path = File.join(spec_support_root, 'ref_path')
12
+ end
13
+
14
+ after(:each) do
15
+ remove_refs(@ref_path)
16
+ Gatling::Configuration.trainer_toggle = false
17
+ end
18
+
19
+ describe 'Gatling, when no reference image exists' do
20
+
21
+ it "will notify that no reference image exists and create a candidate image" do
22
+ black_element = element_for_spec
23
+ expected_error = "The design reference #{"black.png"} does not exist, #{@ref_path}/candidate/#{"black.png"} " +
24
+ "is now available to be used as a reference. " +
25
+ "Copy candidate to root reference_image_path to use as reference"
26
+
27
+ expect {Gatling.matches?("black.png", black_element)}.should raise_error(RuntimeError, expected_error)
28
+
29
+ File.exists?(File.join(@ref_path, 'candidate', "black.png")).should be_true
30
+ end
31
+ end
32
+
33
+ describe 'Gatling image comparison' do
34
+
35
+ before(:each) do
36
+ create_square_image(@ref_path, 'black')
37
+ end
38
+
39
+ it 'will return true if the images are identical' do
40
+ black_element = element_for_spec('#black')
41
+
42
+ Gatling.matches?("black.png", black_element).should be_true
43
+ end
44
+
45
+ it 'will return false, creates new diff and candidate images if the images are different' do
46
+ red_element = element_for_spec('#red')
47
+ expected_error = "element did not match #{"black.png"}. " +
48
+ "A diff image: #{"black.png"} was created in #{@ref_path}/diff/#{"black.png"}. " +
49
+ "A new reference #{@ref_path}/candidate/#{"black.png"} can be used to fix the test"
50
+
51
+ expect {Gatling.matches?("black.png", red_element)}.should raise_error(RuntimeError, expected_error)
52
+
53
+ File.exists?(File.join(@ref_path,'diff', "black.png")).should be_true
54
+ File.exists?(File.join(@ref_path,'candidate', "black.png")).should be_true
55
+ end
56
+
57
+ # it 'will try to match a specified amount of time before failing' do
58
+ # red_element = element_for_spec('#red')
59
+ # Gatling.should_receive(:matches?).and_return(false)
60
+ # Gatling.should_receive(:try_until_match)
61
+ # Gatling.matches?("black.png", red_element)
62
+ # end
63
+
64
+ end
65
+
66
+ describe 'Gatling trainer toggle' do
67
+
68
+ it 'will save a reference file if no reference file already exists' do
69
+ Gatling::Configuration.trainer_toggle = true
70
+ File.exists?(File.join(@ref_path, "black.png")).should be_false
71
+ $stdout.should_receive(:puts).with "Saved #{@ref_path}/#{"black.png"} as reference"
72
+ black_element = element_for_spec
73
+
74
+ expect {Gatling.matches?("black.png", black_element)}.should_not raise_error
75
+
76
+ File.exists?(File.join(@ref_path, "black.png")).should be_true
77
+ end
78
+
79
+ it 'will warn if a reference already exists and not overwrite it' do
80
+ create_square_image(@ref_path, 'black')
81
+ Gatling::Configuration.trainer_toggle = true
82
+ expected_message = " already exists. reference image was not overwritten. " +
83
+ "please delete the old file to update using trainer"
84
+ black_element = element_for_spec
85
+ reference_file_ctime = File.ctime(File.join(@ref_path,"black.png"))
86
+
87
+ $stdout.should_receive(:puts).with expected_message
88
+ expect {Gatling.matches?("black.png", black_element)}.should_not raise_error
89
+
90
+ sleep(1)
91
+ reference_file_ctime.eql?(File.ctime(File.join(@ref_path, "black.png"))).should be_true
92
+ end
93
+ end
94
+ end
@@ -0,0 +1,39 @@
1
+ require 'spec_helper'
2
+ include Capybara::DSL
3
+
4
+ describe 'rspec matcher' do
5
+
6
+ before(:all) do
7
+ @black_box = 'black.png'
8
+ @ref_path = Gatling::Configuration.reference_image_path = File.join(spec_support_root, 'ref_path')
9
+ create_images_for_web_page
10
+ end
11
+
12
+ after(:each) do
13
+ Gatling::Configuration.trainer_toggle = false
14
+ remove_refs(@ref_path)
15
+ end
16
+
17
+ describe 'initializing and runnin gatling' do
18
+
19
+ it 'will pass if images matches reference' do
20
+ create_square_image(@ref_path, 'black')
21
+ black_element = element_for_spec("#black")
22
+ black_element.should look_like("black.png")
23
+ end
24
+
25
+ it 'will fail if images dosent matches reference' do
26
+ create_square_image(@ref_path, 'black')
27
+ red_element = element_for_spec("#red")
28
+ expect{red_element.should look_like(@black_box)}.should raise_error
29
+ end
30
+
31
+ it 'will return true if it makes a new reference image in trainer mode' do
32
+ Gatling::Configuration.trainer_toggle = true
33
+ black_element = element_for_spec("#black")
34
+ black_element.should look_like(@black_box)
35
+ File.exists?(File.join(@ref_path, @black_box)).should be_true
36
+ end
37
+
38
+ end
39
+ end
@@ -5,27 +5,28 @@ describe Gatling::Comparison do
5
5
  before do
6
6
  apple = Magick::Image.new(100,100) { self.background_color = "green" }
7
7
  orange = Magick::Image.new(100,100) { self.background_color = "orange" }
8
- @apple = Gatling::Image.new(:from_diff, 'apple.png', apple)
9
- @orange = Gatling::Image.new(:from_diff, 'orange.png', orange)
8
+ @apple = Gatling::Image.new(apple, "apple.png")
9
+ @orange = Gatling::Image.new(orange, "orange.png")
10
+ end
11
+
12
+ describe 'will make images from ' do
13
+
10
14
  end
11
15
 
12
16
  describe 'will compare two images' do
13
17
 
14
18
  it 'will return true if the images are identical' do
15
- subject = Gatling::Comparison.new(@apple, @apple)
16
- subject.match.should == true
19
+ Gatling::Comparison.new(@apple, @apple).matches?.should == true
17
20
  end
18
21
 
19
22
  it 'will return false if the images are different' do
20
- subject = Gatling::Comparison.new(@apple, @orange)
21
- subject.match.should == false
23
+ Gatling::Comparison.new(@orange, @apple).matches?.should == false
22
24
  end
23
25
  end
24
26
 
25
27
  describe 'Diff images' do
26
28
  it 'will give us a diff' do
27
- subject = Gatling::Comparison.new(@apple, @orange)
28
- subject.diff_image.class.should == Gatling::Image
29
+ Gatling::Comparison.new(@apple, @orange).diff_image.class.should == Gatling::Image
29
30
  end
30
31
  end
31
32
  end
@@ -2,15 +2,18 @@ require 'spec_helper'
2
2
 
3
3
  describe Gatling::Configuration do
4
4
 
5
- describe "#reference_image_path" do
6
- before :each do
5
+ after :each do
7
6
  Gatling::Configuration.reference_image_path = nil
8
- end
7
+ Gatling.reference_image_path = nil
8
+ end
9
+
10
+ describe "#reference_image_path" do
11
+
9
12
 
10
13
  describe "Without Rails" do
11
14
  it "should default to './spec/reference_images' when not in a rails environment" do
12
15
  Gatling::Configuration.reference_image_path.should eql("spec/reference_images")
13
- end
16
+ end
14
17
  end
15
18
 
16
19
  describe "with rails" do
@@ -38,32 +41,32 @@ describe Gatling::Configuration do
38
41
  end
39
42
 
40
43
  end
41
- end
44
+ end
42
45
 
43
46
  describe '#trainer_toggle' do
44
47
 
45
48
  it 'should default to false' do
46
- Gatling::Configuration.trainer_toggle.should eql(false)
49
+ subject.trainer_toggle.should eql(false)
47
50
  end
48
51
 
49
52
  it 'can be toggled to true' do
50
53
  Gatling::Configuration.trainer_toggle = true
51
- Gatling::Configuration.trainer_toggle.should eql(true)
54
+ subject.trainer_toggle.should eql(true)
52
55
  end
53
56
 
54
57
  it 'toggeled using GATLING_TRAINER = false' do
55
58
  ENV['GATLING_TRAINER'] = 'false'
56
- Gatling::Configuration.trainer_toggle.should eql(false)
59
+ subject.trainer_toggle.should eql(false)
57
60
  end
58
61
 
59
62
  it 'toggeled using GATLING_TRAINER = true' do
60
63
  ENV['GATLING_TRAINER'] = 'true'
61
- Gatling::Configuration.trainer_toggle.should eql(true)
64
+ subject.trainer_toggle.should eql(true)
62
65
  end
63
66
 
64
67
  it 'toggeled using GATLING_TRAINER = nil' do
65
68
  ENV['GATLING_TRAINER'] = nil
66
- Gatling::Configuration.trainer_toggle.should eql(false)
69
+ subject.trainer_toggle.should eql(false)
67
70
  end
68
71
 
69
72
  after(:each) do
@@ -75,12 +78,51 @@ describe Gatling::Configuration do
75
78
  describe 'paths' do
76
79
  it 'should return the directory for a type of image' do
77
80
  Gatling::Configuration.reference_image_path = "a_path"
78
- Gatling::Configuration.path_from_type(:temp).should == 'a_path/temp'
81
+ subject.path(:temp).should == 'a_path/temp'
79
82
  end
80
83
 
81
84
  it 'should thrown an error when you ask for the path of an unknown image type' do
82
- expect { Gatling::Configuration.path_from_type(:unknown)}.should raise_error "Unkown image type 'unknown'"
85
+ expect { Gatling::Configuration.path(:unknown)}.should raise_error "Unkown image type 'unknown'"
86
+ end
87
+ end
88
+
89
+ describe "#max_no_tries" do
90
+
91
+ it "should default to 5" do
92
+ subject.max_no_tries.should == 5
93
+ end
94
+
95
+ it "should be settable" do
96
+ Gatling::Configuration.max_no_tries = 1
97
+ subject.max_no_tries.should == 1
98
+ end
99
+ end
100
+
101
+ describe "#sleep_between_tries" do
102
+
103
+ it "should default to 0.5" do
104
+ subject.sleep_between_tries.should == 0.5
83
105
  end
84
- end
106
+
107
+ it "should be settable" do
108
+ Gatling::Configuration.sleep_between_tries = 55
109
+ subject.sleep_between_tries.should eql 55
110
+ end
111
+ end
112
+
113
+ describe "settings" do
114
+
115
+ it "should accept a block of settings and parse them correctly" do
116
+ Gatling.config do |setting|
117
+ Gatling.reference_image_path = 'custom_path'
118
+ Gatling.max_no_tries = 3
119
+ Gatling.sleep_between_tries = 0.7
120
+ end
121
+ subject.reference_image_path.should eql 'custom_path'
122
+ subject.max_no_tries.should eql 3
123
+ subject.sleep_between_tries.should eql 0.7
124
+ end
125
+
126
+ end
85
127
 
86
128
  end
@@ -1,89 +1,94 @@
1
1
  require 'spec_helper'
2
2
  include Capybara::DSL
3
3
 
4
- describe 'Gatling' do
4
+ describe Gatling do
5
5
 
6
- before(:all) do
6
+ before :all do
7
7
  @spec_support_root = spec_support_root
8
+ @box = 'box'
8
9
  @black_box = 'black.png'
9
10
  @red_box = 'red.png'
10
- create_images_for_web_page
11
+ @ref_path = Gatling::Configuration.reference_image_path = './ref_path'
11
12
  end
12
13
 
13
- before(:each) do
14
- @ref_path = Gatling::Configuration.reference_image_path = File.join(spec_support_root, 'ref_path')
15
- end
16
-
17
- after(:each) do
18
- remove_refs(@ref_path)
14
+ after :each do
19
15
  Gatling::Configuration.trainer_toggle = false
20
16
  end
21
17
 
22
- describe 'Gatling, when no reference image exists' do
23
-
24
- it "will notify that no reference image exists and create a candidate image" do
25
- black_element = element_for_spec
26
- expected_error = "The design reference #{@black_box} does not exist, #{@ref_path}/candidate/#{@black_box} " +
27
- "is now available to be used as a reference. " +
28
- "Copy candidate to root reference_image_path to use as reference"
29
-
30
- expect {Gatling.matches?(@black_box, black_element)}.should raise_error(RuntimeError, expected_error)
18
+ describe '#Gatling' do
31
19
 
32
- File.exists?(File.join(@ref_path, 'candidate', @black_box)).should be_true
33
- end
34
- end
35
-
36
- describe 'Gatling image comparison' do
37
-
38
- before(:each) do
39
- create_square_image(@ref_path, 'black')
20
+ before :each do
21
+ @image_class_mock = mock(Gatling::Image)
40
22
  end
41
23
 
42
24
  it 'will return true if the images are identical' do
43
- black_element = element_for_spec('#black')
44
-
45
- Gatling.matches?(@black_box, black_element).should be_true
25
+ @apple = mock("Gatling::Image")
26
+ @orange = mock("Gatling::Image")
27
+ @element = mock("Gatling::CaptureElement")
28
+ @comparison = mock("Gatling::Comparison")
29
+ Gatling::ImageFromFile.stub!(:new).and_return(@orange)
30
+ Gatling::ImageFromElement.stub!(:new).and_return(@orange)
31
+ Gatling::Comparison.stub!(:new).and_return(@comparison)
32
+ @comparison.stub!(:matches?).and_return(true)
33
+ File.stub!(:exists?).and_return(true)
34
+ subject.matches?("orange.png", @element).should be_true
46
35
  end
47
36
 
48
- it 'will return false, creates new diff and candidate images if the images are different' do
49
- red_element = element_for_spec('#red')
50
- expected_error = "element did not match #{@black_box}. " +
51
- "A diff image: #{@black_box} was created in #{@ref_path}/diff/#{@black_box}. " +
52
- "A new reference #{@ref_path}/candidate/#{@black_box} can be used to fix the test"
53
-
54
- expect {Gatling.matches?(@black_box, red_element)}.should raise_error(RuntimeError, expected_error)
37
+ it "#save_image_as_diff" do
38
+ @image_class_mock.should_receive(:save).with(:as => :diff).and_return(@ref_path)
39
+ @image_class_mock.should_receive(:file_name).at_least(:once).and_return("some_name")
40
+ expect {subject.save_image_as_diff(@image_class_mock)}.should raise_error
41
+ end
55
42
 
56
- File.exists?(File.join(@ref_path,'diff', @black_box)).should be_true
57
- File.exists?(File.join(@ref_path,'candidate', @black_box)).should be_true
43
+ it "#save_image_as_candidate" do
44
+ @image_class_mock.should_receive(:save).with(:as => :candidate).and_return(@ref_path)
45
+ @image_class_mock.should_receive(:file_name).at_least(:once).and_return("some_name")
46
+ @image_class_mock.should_receive(:path).and_return(@path)
47
+ expect {subject.save_image_as_candidate(@image_class_mock)}.should raise_error
58
48
  end
59
- end
60
49
 
61
- describe 'Gatling trainer toggle' do
50
+ describe "#save_image_as_reference" do
62
51
 
63
- it 'will save a reference file if no reference file already exists' do
64
- Gatling::Configuration.trainer_toggle = true
65
- File.exists?(File.join(@ref_path, @black_box)).should be_false
66
- $stdout.should_receive(:puts).with "Saved #{@ref_path}/#{@black_box} as reference"
67
- black_element = element_for_spec
52
+ it "when image.exists? == true" do
53
+ @image_class_mock.should_receive(:exists?).and_return(true)
54
+ @image_class_mock.should_receive(:path).and_return(@path)
55
+ @image_class_mock.should_not_receive(:save)
56
+ subject.save_image_as_reference(@image_class_mock)
57
+ end
68
58
 
69
- expect {Gatling.matches?(@black_box, black_element)}.should_not raise_error
59
+ it "when image_exists? == false" do
60
+ @image_class_mock.should_receive(:exists?).and_return(false)
61
+ @image_class_mock.should_receive(:save).with(:as => :reference).and_return(@ref_path)
62
+ @image_class_mock.should_receive(:path).and_return(@path)
63
+ subject.save_image_as_reference(@image_class_mock)
64
+ end
70
65
 
71
- File.exists?(File.join(@ref_path, @black_box)).should be_true
72
66
  end
73
67
 
74
- it 'will warn if a reference already exists and not overwrite it' do
75
- create_square_image(@ref_path, 'black')
76
- Gatling::Configuration.trainer_toggle = true
77
- expected_message = " already exists. reference image was not overwritten. " +
78
- "please delete the old file to update using trainer"
79
- black_element = element_for_spec
80
- reference_file_ctime = File.ctime(File.join(@ref_path,@black_box))
81
68
 
82
- $stdout.should_receive(:puts).with expected_message
83
- expect {Gatling.matches?(@black_box, black_element)}.should_not raise_error
84
69
 
85
- sleep(1)
86
- reference_file_ctime.eql?(File.ctime(File.join(@ref_path, @black_box))).should be_true
87
70
  end
71
+
72
+ describe "#compare_until_match" do
73
+
74
+ before do
75
+ @apple = mock("Gatling::Image")
76
+ @orange = mock("Gatling::Image")
77
+ @element = mock(Gatling::CaptureElement)
78
+ @comparison = mock("Gatling::Comparison")
79
+ Gatling::ImageFromFile.stub!(:new).and_return(@orange)
80
+ Gatling::ImageFromElement.stub!(:new).and_return(@orange)
81
+ Gatling::Comparison.stub!(:new).and_return(@comparison)
82
+ end
83
+
84
+ it "should try match for a specified amount of times" do
85
+ @comparison.should_receive(:matches?).exactly(3).times
86
+ Gatling.compare_until_match(@element, "orange.png", 3)
87
+ end
88
+
89
+ it "should pass after a few tries if match is found" do
90
+ @comparison.should_receive(:matches?).exactly(1).times.and_return(true)
91
+ Gatling.compare_until_match(@element, "orange.png", 3)
92
+ end
88
93
  end
89
- end
94
+ end