Skip to content

Commit db91c23

Browse files
authored
Merge pull request #3 from kaspergrubbe/screenshot-specs
Screenshot specs
2 parents e362748 + 51e3548 commit db91c23

3 files changed

Lines changed: 53 additions & 0 deletions

File tree

ruby-vnc.gemspec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,5 @@ Gem::Specification.new do |s|
3636
s.add_development_dependency 'rake', '~> 12.3'
3737
s.add_development_dependency 'rspec', '~> 3.7'
3838
s.add_development_dependency 'simplecov', '~> 0.16'
39+
s.add_development_dependency 'image_size', '~> 2.0'
3940
end

spec/real_net_vnc_spec.rb

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,53 @@
4343
expect { Net::VNC.open(WITH_AUTH_SERVER_DISPLAY) }.to raise_error(RuntimeError, 'Need to authenticate but no password given')
4444
end
4545
end
46+
47+
context 'screenshotting' do
48+
def verify_screenshot(input)
49+
image_size = ImageSize.path(input)
50+
expect(image_size.format).to eq :png
51+
expect(image_size.width).to eq 1366
52+
expect(image_size.height).to eq 768
53+
end
54+
55+
it 'should allow you to take a screenshot with a path' do
56+
Tempfile.open('ruby-vnc-spec') do |screenshotfile|
57+
Net::VNC.open(NO_AUTH_SERVER_DISPLAY) do |vnc|
58+
vnc.pointer_move(10, 15)
59+
vnc.take_screenshot(screenshotfile.path)
60+
end
61+
verify_screenshot(screenshotfile.path)
62+
end
63+
end
64+
65+
it 'should allow you to take a screenshot with a blob' do
66+
Tempfile.open('ruby-vnc-spec-blob') do |screenshotfile|
67+
vnc = Net::VNC.open(NO_AUTH_SERVER_DISPLAY)
68+
begin
69+
vnc.pointer_move(10, 15)
70+
blob = vnc.take_screenshot(nil)
71+
screenshotfile.write(blob)
72+
ensure
73+
vnc.close
74+
end
75+
76+
verify_screenshot(screenshotfile.path)
77+
end
78+
end
79+
80+
it 'should allow you to take a screenshot with a IO-object' do
81+
screenshotfile = File.new("out.png", "w")
82+
83+
begin
84+
Net::VNC.open(NO_AUTH_SERVER_DISPLAY) do |vnc|
85+
vnc.pointer_move(10, 15)
86+
vnc.take_screenshot(screenshotfile)
87+
end
88+
verify_screenshot(screenshotfile)
89+
ensure
90+
screenshotfile.close
91+
File.delete(screenshotfile)
92+
end
93+
end
94+
end
4695
end

spec/spec_helper.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
require 'simplecov'
1818
SimpleCov.start
1919

20+
require 'tempfile'
21+
require 'image_size'
22+
2023
RSpec.configure do |config|
2124
# rspec-expectations config goes here. You can use an alternate
2225
# assertion/expectation library such as wrong or the stdlib/minitest

0 commit comments

Comments
 (0)