gnawrnip 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,7 @@
1
1
  require 'tempfile'
2
2
  require 'time'
3
3
  require 'capybara'
4
+ require 'oily_png'
4
5
 
5
6
  module Gnawrnip
6
7
  class Screenshot
@@ -51,8 +52,6 @@ module Gnawrnip
51
52
  end
52
53
 
53
54
  def resize(path)
54
- require 'oily_png'
55
-
56
55
  image = OilyPNG::Canvas.from_file(path)
57
56
  new_width, new_height = calculate_new_size(image.width, image.height)
58
57
 
@@ -67,12 +66,12 @@ module Gnawrnip
67
66
  # @return [Array] New width and height size. [width, height]
68
67
  #
69
68
  def calculate_new_size(width, height)
70
- ratio = width / height
69
+ ratio = width.to_f / height.to_f
71
70
  target = Gnawrnip.max_frame_size
72
71
 
73
72
  return [width, height] if target > [width, height].max
74
73
 
75
- if ratio < 0
74
+ if ratio < 1
76
75
  new_width = target * ratio
77
76
  new_height = target
78
77
  else
@@ -1,3 +1,3 @@
1
1
  module Gnawrnip
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
@@ -3,29 +3,8 @@ require 'gnawrnip/screenshot'
3
3
 
4
4
  module Gnawrnip
5
5
  describe Screenshot do
6
- describe '.take' do
7
- subject { Screenshot.take.read }
8
-
9
- context 'No given max frame size' do
10
- before do
11
- Screenshot.stub(:need_resize?) { false }
12
- Screenshot.should_not_receive(:resize)
13
- end
14
-
15
- # see GnawrnipTestSession::save_screenshot
16
- it { should == "screenshot" }
17
- end
18
-
19
- context 'No given max frame size' do
20
- before do
21
- Screenshot.stub(:need_resize?) { true }
22
- Screenshot.should_receive(:resize)
23
- end
24
-
25
- it { should == "screenshot" }
26
- end
27
-
28
- context 'not support save_screenshot' do
6
+ context 'Not support save_screenshot' do
7
+ describe '.tale' do
29
8
  before do
30
9
  GnawrnipTest::Session.any_instance.stub(:save_screenshot) do
31
10
  raise Capybara::NotSupportedByDriverError
@@ -35,8 +14,10 @@ module Gnawrnip
35
14
  subject { lambda { Screenshot.take } }
36
15
  it { should raise_error Capybara::NotSupportedByDriverError }
37
16
  end
17
+ end
38
18
 
39
- context 'raise unknown error' do
19
+ context 'raise unknown error' do
20
+ describe '.take' do
40
21
  before do
41
22
  GnawrnipTest::Session.any_instance.stub(:save_screenshot) do
42
23
  raise Timeout::Error
@@ -61,5 +42,70 @@ module Gnawrnip
61
42
  end
62
43
  end
63
44
  end
45
+
46
+ context 'No given Gnawrnip.max_frame_size' do
47
+ describe '.take' do
48
+ subject { Screenshot.take.read }
49
+
50
+ context 'No given max frame size' do
51
+ before do
52
+ Gnawrnip.max_frame_size = nil
53
+ Screenshot.should_not_receive(:resize)
54
+ end
55
+
56
+ it { should == "screenshot" }
57
+ end
58
+ end
59
+ end
60
+
61
+ context 'Given Gnawrnip.max_frame_size' do
62
+ before do
63
+ OilyPNG::Canvas.stub(:from_file) { oily_png }
64
+ end
65
+
66
+ subject { Screenshot.take.read }
67
+
68
+ context 'width larger than height.' do
69
+ let(:oily_png) do
70
+ oily_png = double('oily_png', width: 640, height: 480, save: nil)
71
+ oily_png.should_receive(:resample_bilinear!).with(300, 225)
72
+ oily_png
73
+ end
74
+
75
+ before do
76
+ Gnawrnip.max_frame_size = 300
77
+ end
78
+
79
+ it { should == "screenshot" }
80
+ end
81
+
82
+ context 'height larger than width.' do
83
+ let(:oily_png) do
84
+ oily_png = double('oily_png', width: 480, height: 640, save: nil)
85
+ oily_png.should_receive(:resample_bilinear!).with(300, 400)
86
+ oily_png
87
+ end
88
+
89
+ before do
90
+ Gnawrnip.max_frame_size = 400
91
+ end
92
+
93
+ it { should == "screenshot" }
94
+ end
95
+
96
+ context 'Given max_frame_size larger than original.' do
97
+ let(:oily_png) do
98
+ oily_png = double('oily_png', width: 640, height: 480, save: nil)
99
+ oily_png.should_receive(:resample_bilinear!).with(640, 480)
100
+ oily_png
101
+ end
102
+
103
+ before do
104
+ Gnawrnip.max_frame_size = 1024
105
+ end
106
+
107
+ it { should == "screenshot" }
108
+ end
109
+ end
64
110
  end
65
111
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gnawrnip
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-11-15 00:00:00.000000000 Z
12
+ date: 2013-11-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: capybara
@@ -173,7 +173,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
173
173
  version: '0'
174
174
  segments:
175
175
  - 0
176
- hash: 270195121
176
+ hash: 3462601225133787516
177
177
  required_rubygems_version: !ruby/object:Gem::Requirement
178
178
  none: false
179
179
  requirements:
@@ -182,7 +182,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
182
182
  version: '0'
183
183
  segments:
184
184
  - 0
185
- hash: 270195121
185
+ hash: 3462601225133787516
186
186
  requirements: []
187
187
  rubyforge_project:
188
188
  rubygems_version: 1.8.23