spec/spec_helper.rb in win_gui-0.2.16 vs spec/spec_helper.rb in win_gui-0.2.17

- old
+ new

@@ -1,7 +1,6 @@ -require 'spec' -require 'spec/autorun' +require 'rspec' require 'win_gui' # Customize RSpec with my own extensions module SpecMacros @@ -12,88 +11,87 @@ end # reads description line from source file and drops external brackets (like its{}, use{} def description_from(file, line) File.open(file) do |f| - f.lines.to_a[line-1].gsub( /(spec.*?{)|(use.*?{)|}/, '' ).strip + f.lines.to_a[line-1].gsub(/(spec.*?{)|(use.*?{)|}/, '').strip end end end -Spec::Runner.configure { |config| config.extend(SpecMacros) } +RSpec.configure { |config| + config.include Win::Gui # This is a namespace from win gem. + config.include WinGui # This is our own main namespace. TODO: looks confusing... better names? + config.extend SpecMacros } -module WinGuiTest - include Win::Gui # This is a namespace from win gem. - include WinGui # This is our own main namespace. TODO: looks confusing... better names? - # Test related Constants: - TIMEOUT = 0.001 - KEY_DELAY = 0.001 - SLEEP_DELAY = 0.01 - APP_PATH = File.join(File.dirname(__FILE__), "../misc/locknote/LockNote.exe" ) - DIALOG_TITLE = "Save As" - WIN_TITLE = 'LockNote - Steganos LockNote' - WIN_CLASS = 'ATL:00434098' - TEXTAREA_CLASS = 'ATL:00434310' - STATUSBAR_CLASS = 'msctls_statusbar32' - IMPOSSIBLE = 'Impossible' - ERROR_CONVERSION = /Can.t convert/ +# Test related Constants: +TIMEOUT = 0.001 +KEY_DELAY = 0.001 +SLEEP_DELAY = 0.01 +APP_PATH = File.join(File.dirname(__FILE__), "../misc/locknote/LockNote.exe") +DIALOG_TITLE = "Save As" +WIN_TITLE = 'LockNote - Steganos LockNote' +WIN_CLASS = 'ATL:00434098' +TEXTAREA_CLASS = 'ATL:00434310' +STATUSBAR_CLASS = 'msctls_statusbar32' +IMPOSSIBLE = 'Impossible' +ERROR_CONVERSION = /Can.t convert/ - # Helper methods: - def use - lambda {yield}.should_not raise_error - end +# Helper methods: +def use + lambda { yield }.should_not raise_error +end - def any_handle - find_window(nil, nil) - end +def any_handle + find_window(nil, nil) +end - def not_a_handle - 123 - end +def not_a_handle + 123 +end - def any_block - lambda {|*args| args} - end +def any_block + lambda { |*args| args } +end - def launch_test_app - #system APP_START - @test_app = App.launch( path: APP_PATH, title: WIN_TITLE, timeout: 1) - end +def launch_test_app + #system APP_START + @test_app = App.launch(path: APP_PATH, title: WIN_TITLE, timeout: 1) +end - def close_test_app - while @test_app && @test_app.main_window.window? - @test_app.close - # Dealing with closing confirmation modal dialog - if dialog = dialog( title: "Steganos Locknote", timeout: SLEEP_DELAY) - dialog.set_foreground_window - keystroke("N") - end +def close_test_app + while @test_app && @test_app.main_window.window? + @test_app.close + # Dealing with closing confirmation modal dialog + if dialog = dialog(title: "Steganos Locknote", timeout: SLEEP_DELAY) + dialog.set_foreground_window + keystroke("N") end - @test_app = nil end + @test_app = nil +end - # Creates test app object and yields it back to the block - def test_app - yield launch_test_app - close_test_app - end +# Creates test app object and yields it back to the block +def test_app + yield launch_test_app + close_test_app +end - def with_dialog(type=:close) - case type - when :close - keystroke('A') - @app.close - title, key = "Steganos Locknote", "N" - when :save - keystroke(VK_ALT, 'F', 'A') - title, key = "Save As", VK_ESCAPE - end - sleep 0.01 until dialog = Window.top_level(title: title) - yield dialog - while dialog.window? - dialog.set_foreground_window - keystroke(key) - sleep 0.01 - end +def with_dialog(type=:close) + case type + when :close + keystroke('A') + @app.close + title, key = "Steganos Locknote", "N" + when :save + keystroke(VK_ALT, 'F', 'A') + title, key = "Save As", VK_ESCAPE + end + sleep 0.01 until dialog = Window.top_level(title: title) + yield dialog + while dialog.window? + dialog.set_foreground_window + keystroke(key) + sleep 0.01 end end