Skip to content

Commit

Permalink
Merge pull request #3 from kaspergrubbe/screenshot-specs
Browse files Browse the repository at this point in the history
Screenshot specs
  • Loading branch information
lobin-z0x50 authored Nov 22, 2018
2 parents e362748 + 51e3548 commit db91c23
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 0 deletions.
1 change: 1 addition & 0 deletions ruby-vnc.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,5 @@ Gem::Specification.new do |s|
s.add_development_dependency 'rake', '~> 12.3'
s.add_development_dependency 'rspec', '~> 3.7'
s.add_development_dependency 'simplecov', '~> 0.16'
s.add_development_dependency 'image_size', '~> 2.0'
end
49 changes: 49 additions & 0 deletions spec/real_net_vnc_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,53 @@
expect { Net::VNC.open(WITH_AUTH_SERVER_DISPLAY) }.to raise_error(RuntimeError, 'Need to authenticate but no password given')
end
end

context 'screenshotting' do
def verify_screenshot(input)
image_size = ImageSize.path(input)
expect(image_size.format).to eq :png
expect(image_size.width).to eq 1366
expect(image_size.height).to eq 768
end

it 'should allow you to take a screenshot with a path' do
Tempfile.open('ruby-vnc-spec') do |screenshotfile|
Net::VNC.open(NO_AUTH_SERVER_DISPLAY) do |vnc|
vnc.pointer_move(10, 15)
vnc.take_screenshot(screenshotfile.path)
end
verify_screenshot(screenshotfile.path)
end
end

it 'should allow you to take a screenshot with a blob' do
Tempfile.open('ruby-vnc-spec-blob') do |screenshotfile|
vnc = Net::VNC.open(NO_AUTH_SERVER_DISPLAY)
begin
vnc.pointer_move(10, 15)
blob = vnc.take_screenshot(nil)
screenshotfile.write(blob)
ensure
vnc.close
end

verify_screenshot(screenshotfile.path)
end
end

it 'should allow you to take a screenshot with a IO-object' do
screenshotfile = File.new("out.png", "w")

begin
Net::VNC.open(NO_AUTH_SERVER_DISPLAY) do |vnc|
vnc.pointer_move(10, 15)
vnc.take_screenshot(screenshotfile)
end
verify_screenshot(screenshotfile)
ensure
screenshotfile.close
File.delete(screenshotfile)
end
end
end
end
3 changes: 3 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
require 'simplecov'
SimpleCov.start

require 'tempfile'
require 'image_size'

RSpec.configure do |config|
# rspec-expectations config goes here. You can use an alternate
# assertion/expectation library such as wrong or the stdlib/minitest
Expand Down

0 comments on commit db91c23

Please sign in to comment.