examples/quicknote/spec/quicknote/form_main_spec.rb in win32-autogui-0.4.0 vs examples/quicknote/spec/quicknote/form_main_spec.rb in win32-autogui-0.4.1

- old
+ new

@@ -5,11 +5,10 @@ describe "FormMain" do before(:all) do @debug = false @verbose = true @application = Quicknote.new - FileUtils.rm_rf(current_dir) puts "FormMain before(:all)" if @debug puts "application:\n#{@application.inspect}\n" if @debug && @verbose puts "application.combined_text:\n #{@application.combined_text}\n" if @debug && @verbose end before(:each) do @@ -18,11 +17,11 @@ @application.set_focus puts "FormMain before(:each)" if @debug end after(:all) do if @application.running? - @application.file_exit + @application.file_exit # still running? force it to close @application.close(:wait_for_close => true) @application.should_not be_running end puts "FormMain after(:all)" if @debug @@ -38,11 +37,11 @@ describe "after startup" do it "should have the title 'QuickNote - untitled.txt'" do @application.main_window.title.should == "QuickNote - untitled.txt" end it "should have no text" do - @application.edit_window.text.should == '' + @application.edit_window.text.should == '' end end describe "editing text" do after(:each) do @@ -53,13 +52,13 @@ @application.main_window.title.should == "QuickNote - untitled.txt" type_in("hello") @application.main_window.title.should == "QuickNote - +untitled.txt" end it "should change the text" do - @application.edit_window.text.should == '' + @application.edit_window.text.should == '' type_in("hello") - @application.edit_window.text.should == 'hello' + @application.edit_window.text.should == 'hello' end end describe "file open (VK_MENU, VK_F, VK_O)" do before(:each) do @@ -67,64 +66,64 @@ @file_contents = create_file(@filename, "the quick brown fox") @application.file_new(:save => false) end after(:each) do keystroke(VK_N) if @application.message_dialog_confirm - keystroke(VK_ESCAPE) if @application.file_open_dialog + keystroke(VK_ESCAPE) if @application.file_open_dialog end it "should prompt to save with modified text" do type_in("foobar") @application.main_window.title.should match(/\+/) - keystroke(VK_MENU, VK_F, VK_O) + keystroke(VK_MENU, VK_F, VK_O) @application.message_dialog_confirm.should_not be_nil end it "should not prompt to save with unmodified text" do @application.main_window.title.should_not match(/\+/) - keystroke(VK_MENU, VK_F, VK_O) + keystroke(VK_MENU, VK_F, VK_O) @application.message_dialog_confirm.should be_nil end - describe "succeeding" do + describe "succeeding" do it "should add the filename to the title" do @application.main_window.title.should == "QuickNote - untitled.txt" @application.file_open(fullpath(@filename), :save => false) @application.main_window.title.should == "QuickNote - #{fullpath(@filename)}" end it "should load the text" do @application.file_open(fullpath(@filename), :save => false) - @application.edit_window.text.should == 'the quick brown fox' + @application.edit_window.text.should == 'the quick brown fox' end end - describe "failing" do + describe "failing" do it "should show an error dialog with message 'Cannot open file'" do type_in("foobar") @application.file_open(fullpath("a_bogus_filename.txt"), :save => false) @application.error_dialog.should_not be_nil @application.error_dialog.combined_text.should match(/Cannot open file/) end it "should keep existing text" do type_in("foobar") @application.file_open(fullpath("a_bogus_filename.txt"), :save => false) @application.error_dialog.should_not be_nil - @application.edit_window.text.should == 'foobar' + @application.edit_window.text.should == 'foobar' end end end describe "file new (VK_MENU, VK_F, VK_N)" do it "should prompt to save modified text" do type_in("hello") @application.main_window.title.should match(/\+/) - keystroke(VK_MENU, VK_F, VK_N) + keystroke(VK_MENU, VK_F, VK_N) @application.message_dialog_confirm.should_not be_nil end it "should not prompt to save with unmodified text" do @application.file_new(:save => false) @application.main_window.title.should_not match(/\+/) - keystroke(VK_MENU, VK_F, VK_N) + keystroke(VK_MENU, VK_F, VK_N) @application.message_dialog_confirm.should be_nil end it "should add the filename 'untitled.txt' to the title" do filename = "input_file.txt" file_contents = create_file(filename, "the quick brown fox") @@ -139,23 +138,23 @@ @application.file_new(:save => false) @application.main_window.title.should_not match(/\+/) end it "should clear the existing text" do type_in("hello") - @application.edit_window.text.should match(/hello/) + @application.edit_window.text.should match(/hello/) @application.file_new(:save => false) - @application.edit_window.text.should == '' + @application.edit_window.text.should == '' end end - + describe "file save (VK_MENU, VK_F, VK_S)" do before(:each) do @filename = "input_file.txt" @file_contents = create_file(@filename, "original content") @application.file_open(fullpath(@filename), :save => false) @application.main_window.title.downcase.should == "QuickNote - #{fullpath(@filename)}".downcase - @application.edit_window.text.should == "original content" + @application.edit_window.text.should == "original content" @application.set_focus end it "should do nothing unless modified text" do append_to_file(@filename, "sneak in extra content that shouldn't be here") @@ -164,11 +163,11 @@ @application.file_save contents.should match(/extra content/) @application.edit_window.text.should_not match(/extra content/) end - describe "succeeding" do + describe "succeeding" do it "should remove the '+' modified flag from the title" do type_in("anything") @application.main_window.title.should == "QuickNote - +#{fullpath(@filename)}" @application.file_save @application.main_window.title.should == "QuickNote - #{fullpath(@filename)}" @@ -179,20 +178,22 @@ @application.file_save get_file_contents(@filename).should == "foobar" + "original content" end end - describe "failing" do + describe "failing" do before(:each) do # set read-only to cause save failure in_current_dir do `attrib +R #{@filename}` end end after(:each) do # cleanup read-only file - FileUtils.rm_rf(current_dir) + in_current_dir do + FileUtils.rm(@filename) + end end it "should show an error dialog with message 'Cannot create file'" do type_in("anything") @application.file_save @@ -220,23 +221,23 @@ create_file(@saveas_filename, "") @application.file_open(fullpath(@filename), :save => false) end after(:each) do keystroke(VK_N) if @application.dialog_overwrite_confirm - keystroke(VK_ESCAPE) if @application.file_save_as_dialog + keystroke(VK_ESCAPE) if @application.file_save_as_dialog end it "should prompt for filename" do - keystroke(VK_MENU, VK_F, VK_A) + keystroke(VK_MENU, VK_F, VK_A) @application.file_save_as_dialog.should_not be_nil end it "should confirm file overwrites" do type_in("anything") - keystroke(VK_MENU, VK_F, VK_A) + keystroke(VK_MENU, VK_F, VK_A) @application.clipboard.text = fullpath(@saveas_filename) keystroke(VK_CONTROL, VK_V) - keystroke(VK_RETURN) + keystroke(VK_RETURN) File.exists?(fullpath(@saveas_filename)).should be_true @application.dialog_overwrite_confirm.should_not be_nil end it "should remove the '+' modified flag from the title" do type_in("anything") @@ -256,26 +257,26 @@ end describe "file exit (VK_MENU, VK_F, VK_X)" do it "should prompt and save with modified text" do type_in("anything") - keystroke(VK_MENU, VK_F, VK_X) + keystroke(VK_MENU, VK_F, VK_X) @application.message_dialog_confirm.should_not be_nil @application.main_window.is_window?.should == true @application.should be_running end it "should not prompt to save with unmodified text" do - keystroke(VK_MENU, VK_F, VK_X) + keystroke(VK_MENU, VK_F, VK_X) @application.message_dialog_confirm.should be_nil @application.main_window.is_window?.should == false @application.should_not be_running end end describe "hotkey (VK_CONTROL, VK_X)" do it "should should exit the program" do @application.main_window.is_window?.should == true - keystroke(VK_CONTROL, VK_X) + keystroke(VK_CONTROL, VK_X) @application.main_window.is_window?.should == false @application.should_not be_running end end