Sha256: 84bf4e207bf6422368348be14bbb3404ed2f27b301d447b46d625dab5b04abf5

Contents?: true

Size: 1.34 KB

Versions: 3

Compression:

Stored size: 1.34 KB

Contents

$LOAD_PATH.unshift(File.dirname(__FILE__))
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
require 'win32/screenshot'
require 'rspec'
require 'fileutils'

module SpecHelper
  HWND_TOPMOST = -1
  HWND_NOTOPMOST = -2
  SWP_NOSIZE = 1
  SWP_NOMOVE = 2
  SWP_SHOWWINDOW = 40

  extend FFI::Library
  ffi_lib 'user32'
  ffi_convention :stdcall

  # user32.dll
  attach_function :set_window_pos, :SetWindowPos,
                  [:long, :long, :int, :int, :int, :int, :int], :bool
  
  def save_and_verify_image(img, file=nil)
    FileUtils.mkdir @temp_dir unless File.exists?(@temp_dir)
    file_name = File.join @temp_dir, "#{file}.bmp"
    img.write file_name
    img.bitmap[0..1].should == 'BM'
  end

  def resize title
    hwnd = RAutomation::Window.new(:title => title).hwnd
    set_window_pos(hwnd,
                   HWND_TOPMOST,
                   0, 0, 150, 238,
                   SWP_NOMOVE)
    set_window_pos(hwnd,
                   HWND_NOTOPMOST,
                   0, 0, 0, 0,
                   SWP_SHOWWINDOW | SWP_NOMOVE | SWP_NOSIZE)
    sleep 1
  end
end

RSpec.configure do |config|
  config.include(SpecHelper)
  config.before(:suite) {FileUtils.rm Dir.glob(File.join(File.dirname(__FILE__), "tmp/*"))}
  config.before(:all) {@temp_dir = File.join(File.dirname(__FILE__), 'tmp')}
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
win32screenshot-3.0.0 spec/spec_helper.rb
win32screenshot-2.1.0 spec/spec_helper.rb
win32screenshot-2.0.0 spec/spec_helper.rb