win_gui 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (164) hide show
  1. data/.document +5 -0
  2. data/.gitignore +21 -0
  3. data/LICENSE +20 -0
  4. data/README.rdoc +43 -0
  5. data/Rakefile +58 -0
  6. data/VERSION +1 -0
  7. data/book_code/early_success/bundle.rb +34 -0
  8. data/book_code/early_success/english.txt +1 -0
  9. data/book_code/early_success/jruby_basics.rb +47 -0
  10. data/book_code/early_success/windows_basics.rb +97 -0
  11. data/book_code/guessing/locknote.rb +379 -0
  12. data/book_code/guessing/monkeyshines.rb +14 -0
  13. data/book_code/guessing/note.rb +120 -0
  14. data/book_code/guessing/note_spec.rb +175 -0
  15. data/book_code/guessing/replay.rb +21 -0
  16. data/book_code/guessing/seed.rb +9 -0
  17. data/book_code/guessing/spec_helper.rb +69 -0
  18. data/book_code/guessing/windows_gui.rb +247 -0
  19. data/book_code/home_stretch/junquenote.rb +151 -0
  20. data/book_code/home_stretch/locknote.rb +180 -0
  21. data/book_code/home_stretch/note.rb +144 -0
  22. data/book_code/home_stretch/note_spec.rb +191 -0
  23. data/book_code/home_stretch/spec_helper.rb +55 -0
  24. data/book_code/home_stretch/swing_gui.rb +50 -0
  25. data/book_code/home_stretch/windows_gui.rb +232 -0
  26. data/book_code/junquenote/exports.sh +10 -0
  27. data/book_code/junquenote/jruby_mac.sh +10 -0
  28. data/book_code/junquenote/junquenote_app.rb +262 -0
  29. data/book_code/novite/Rakefile +10 -0
  30. data/book_code/novite/app/controllers/application.rb +18 -0
  31. data/book_code/novite/app/controllers/guests_controller.rb +28 -0
  32. data/book_code/novite/app/controllers/parties_controller.rb +77 -0
  33. data/book_code/novite/app/helpers/application_helper.rb +11 -0
  34. data/book_code/novite/app/helpers/guests_helper.rb +10 -0
  35. data/book_code/novite/app/helpers/parties_helper.rb +10 -0
  36. data/book_code/novite/app/models/guest.rb +11 -0
  37. data/book_code/novite/app/models/party.rb +32 -0
  38. data/book_code/novite/app/models/party_mailer.rb +19 -0
  39. data/book_code/novite/app/views/layouts/application.rhtml +44 -0
  40. data/book_code/novite/app/views/parties/new.html.erb +42 -0
  41. data/book_code/novite/app/views/parties/show.html.erb +43 -0
  42. data/book_code/novite/app/views/party_mailer/invite.erb +17 -0
  43. data/book_code/novite/config/boot.rb +117 -0
  44. data/book_code/novite/config/database.yml +19 -0
  45. data/book_code/novite/config/environment.rb +67 -0
  46. data/book_code/novite/config/environments/development.rb +29 -0
  47. data/book_code/novite/config/environments/production.rb +27 -0
  48. data/book_code/novite/config/environments/test.rb +30 -0
  49. data/book_code/novite/config/initializers/inflections.rb +18 -0
  50. data/book_code/novite/config/initializers/mime_types.rb +13 -0
  51. data/book_code/novite/config/routes.rb +47 -0
  52. data/book_code/novite/db/migrate/001_create_parties.rb +26 -0
  53. data/book_code/novite/db/migrate/002_create_guests.rb +23 -0
  54. data/book_code/novite/db/schema.rb +41 -0
  55. data/book_code/novite/log/empty.txt +0 -0
  56. data/book_code/novite/public/.htaccess +40 -0
  57. data/book_code/novite/public/404.html +38 -0
  58. data/book_code/novite/public/422.html +38 -0
  59. data/book_code/novite/public/500.html +38 -0
  60. data/book_code/novite/public/dispatch.cgi +10 -0
  61. data/book_code/novite/public/dispatch.fcgi +24 -0
  62. data/book_code/novite/public/dispatch.rb +18 -0
  63. data/book_code/novite/public/favicon.ico +0 -0
  64. data/book_code/novite/public/images/rails.png +0 -0
  65. data/book_code/novite/public/index.html +285 -0
  66. data/book_code/novite/public/javascripts/application.js +10 -0
  67. data/book_code/novite/public/javascripts/controls.js +971 -0
  68. data/book_code/novite/public/javascripts/dragdrop.js +980 -0
  69. data/book_code/novite/public/javascripts/effects.js +1128 -0
  70. data/book_code/novite/public/javascripts/prototype.js +4233 -0
  71. data/book_code/novite/public/robots.txt +5 -0
  72. data/book_code/novite/script/about +3 -0
  73. data/book_code/novite/script/console +3 -0
  74. data/book_code/novite/script/destroy +3 -0
  75. data/book_code/novite/script/generate +3 -0
  76. data/book_code/novite/script/performance/benchmarker +3 -0
  77. data/book_code/novite/script/performance/profiler +3 -0
  78. data/book_code/novite/script/performance/request +3 -0
  79. data/book_code/novite/script/plugin +3 -0
  80. data/book_code/novite/script/process/inspector +3 -0
  81. data/book_code/novite/script/process/reaper +3 -0
  82. data/book_code/novite/script/process/spawner +3 -0
  83. data/book_code/novite/script/runner +3 -0
  84. data/book_code/novite/script/server +3 -0
  85. data/book_code/novite/test/test_helper.rb +46 -0
  86. data/book_code/one_more_thing/applescript.rb +68 -0
  87. data/book_code/one_more_thing/note_spec.rb +50 -0
  88. data/book_code/one_more_thing/spec_helper.rb +17 -0
  89. data/book_code/one_more_thing/textedit-pure.rb +28 -0
  90. data/book_code/one_more_thing/textedit.applescript +26 -0
  91. data/book_code/one_more_thing/textedit.rb +32 -0
  92. data/book_code/one_more_thing/textnote.rb +87 -0
  93. data/book_code/simplify/junquenote.rb +48 -0
  94. data/book_code/simplify/locknote.rb +46 -0
  95. data/book_code/simplify/note.rb +35 -0
  96. data/book_code/simplify/note_spec.rb +28 -0
  97. data/book_code/simplify/swing_gui.rb +45 -0
  98. data/book_code/simplify/windows_gui.rb +232 -0
  99. data/book_code/simplify/windows_gui_spec.rb +35 -0
  100. data/book_code/story/invite.story +19 -0
  101. data/book_code/story/journal.txt +29 -0
  102. data/book_code/story/novite_stories.rb +156 -0
  103. data/book_code/story/party.rb +149 -0
  104. data/book_code/story/password.rb +61 -0
  105. data/book_code/story/password.story +26 -0
  106. data/book_code/story/rsvp.story +29 -0
  107. data/book_code/tables/TestTime.html +93 -0
  108. data/book_code/tables/TestTimeSample.html +63 -0
  109. data/book_code/tables/calculate_time.rb +39 -0
  110. data/book_code/tables/calculator.rb +108 -0
  111. data/book_code/tables/calculator_actions.rb +27 -0
  112. data/book_code/tables/calculator_spec.rb +47 -0
  113. data/book_code/tables/fit.rb +32 -0
  114. data/book_code/tables/matrix.rb +109 -0
  115. data/book_code/tables/pseudocode.rb +17 -0
  116. data/book_code/tubes/book_selenium.rb +67 -0
  117. data/book_code/tubes/book_watir.rb +60 -0
  118. data/book_code/tubes/dragdrop.html +81 -0
  119. data/book_code/tubes/html_capture.rb +33 -0
  120. data/book_code/tubes/joke_list.rb +67 -0
  121. data/book_code/tubes/list_spec.rb +41 -0
  122. data/book_code/tubes/search_spec.rb +32 -0
  123. data/book_code/tubes/selenium_example.rb +66 -0
  124. data/book_code/tubes/selenium_link.rb +23 -0
  125. data/book_code/tubes/web_server.rb +14 -0
  126. data/book_code/windows/wgui.rb +29 -0
  127. data/book_code/windows/wobj.rb +25 -0
  128. data/book_code/windows/wsh.rb +25 -0
  129. data/book_code/with_rspec/empty_spec.rb +13 -0
  130. data/book_code/with_rspec/junquenote.rb +60 -0
  131. data/book_code/with_rspec/locknote.rb +129 -0
  132. data/book_code/with_rspec/note_spec.rb +32 -0
  133. data/book_code/with_rspec/should_examples.rb +18 -0
  134. data/exp/exp.rb +6 -0
  135. data/exp/exp_encodings.rb +40 -0
  136. data/exp/exp_enum_windows.rb +60 -0
  137. data/exp/exp_quik.rb +38 -0
  138. data/exp/exp_wsh.rb +115 -0
  139. data/exp/old/windows_basics.rb +80 -0
  140. data/exp/old/wnote.rb +80 -0
  141. data/exp/old/wnote_spec.rb +20 -0
  142. data/features/step_definitions/win_gui_steps.rb +0 -0
  143. data/features/support/env.rb +4 -0
  144. data/features/win_gui.feature +9 -0
  145. data/lib/note/java/jemmy.jar +0 -0
  146. data/lib/note/java/jnote.rb +48 -0
  147. data/lib/note/java/jruby_basics.rb +37 -0
  148. data/lib/note/java/junquenote_app.rb +262 -0
  149. data/lib/note/java/note_spec.rb +20 -0
  150. data/lib/note/win/locknote.rb +19 -0
  151. data/lib/note.rb +15 -0
  152. data/lib/win_gui/constants.rb +66 -0
  153. data/lib/win_gui/string_extensions.rb +24 -0
  154. data/lib/win_gui/win_gui.rb +274 -0
  155. data/lib/win_gui/window.rb +70 -0
  156. data/lib/win_gui.rb +3 -0
  157. data/spec/note/win/locknote_spec.rb +7 -0
  158. data/spec/spec.opts +2 -0
  159. data/spec/spec_helper.rb +100 -0
  160. data/spec/test_apps/locknote/LockNote.exe +0 -0
  161. data/spec/win_gui/string_extensions_spec.rb +61 -0
  162. data/spec/win_gui/win_gui_spec.rb +733 -0
  163. data/spec/win_gui/window_spec.rb +124 -0
  164. metadata +251 -0
@@ -0,0 +1,29 @@
1
+ # START:rsvp_story
2
+ Story: minimalist RSVPs
3
+ As a guest with lots to do
4
+ I want to RSVP to an invite with a minimum of mouse clicks
5
+ So that I can get on with the rest of my tasks
6
+ # END:rsvp_story
7
+
8
+ # START:email_free
9
+ Scenario: email-free RSVPs
10
+ Given a party called "a disco anniversary"
11
+ When I view the invitation
12
+ Then I should see the party details
13
+
14
+ When I answer that "Robert Bell" will not attend
15
+ Then I should see "Robert Bell" in the list of decliners
16
+ # END:email_free
17
+
18
+ # START:rsvp_email
19
+ Scenario: RSVP links from email
20
+ Given a party called "a salute to e-mail"
21
+ And a guest list of "one@example.com,two@example.com"
22
+ When I view the invitation
23
+ Then I should see that e-mail was sent to "one@example.com,two@example.com"
24
+
25
+ When I view the e-mail that was sent to "one@example.com"
26
+ Then I should see "Yes/No" links
27
+ When I follow the "Yes" link
28
+ Then I should see "one@example.com" in the list of partygoers
29
+ # END:rsvp_email
@@ -0,0 +1,93 @@
1
+ <!--
2
+ ! Excerpted from "Scripted GUI Testing With Ruby",
3
+ ! published by The Pragmatic Bookshelf.
4
+ ! Copyrights apply to this code. It may not be used to create training material,
5
+ ! courses, books, articles, and the like. Contact us if you are in doubt.
6
+ ! We make no guarantees that this code is fit for any purpose.
7
+ ! Visit http://www.pragmaticprogrammer.com/titles/idgtr for more book information.
8
+ -->
9
+ <html>
10
+
11
+ <head>
12
+ <title>Calculator Test</title>
13
+ <style type="text/css">
14
+ table {
15
+ background: silver;
16
+ margin: 2px;
17
+ padding: 0px;
18
+ border: solid grey;
19
+ border-width: 1px 0px 0px 1px;
20
+ }
21
+
22
+ td {
23
+ border: solid grey;
24
+ border-width: 0px 1px 1px 0px;
25
+ padding: 1px 3px 1px 3px;
26
+ }
27
+ </style>
28
+ </head>
29
+
30
+ <body>
31
+
32
+ <table border="1">
33
+ <tbody>
34
+ <tr><td colspan="3">fit.ActionFixture</td></tr>
35
+ <tr><td>start</td><td colspan="2">CalculatorActions</td></tr>
36
+ <tr><td>enter</td><td>number</td><td>2</td></tr>
37
+ <tr><td>press</td><td colspan="2">plus</td></tr>
38
+ <tr><td>enter</td><td>number</td><td>3</td></tr>
39
+ <tr><td>press</td><td colspan="2">equals</td></tr>
40
+ <tr><td>check</td><td>total_seconds</td><td>5</td></tr>
41
+ </tbody>
42
+ </table>
43
+
44
+ <hr>
45
+
46
+ <table border="1">
47
+ <tbody>
48
+ <tr><td colspan="8">CalculateTime</td></tr>
49
+ <tr>
50
+ <td><em>days</em></td>
51
+ <td><em>hours</em></td>
52
+ <td><em>mins</em></td>
53
+ <td><em>secs</em></td>
54
+
55
+ <td><em>days()</em></td>
56
+ <td><em>hours()</em></td>
57
+ <td><em>mins()</em></td>
58
+ <td><em>secs()</em></td>
59
+ </tr>
60
+
61
+ <tr>
62
+ <td>1</td><td>47</td><td>59</td><td>59</td>
63
+ <td>2</td><td>23</td><td>59</td><td>59</td>
64
+ </tr>
65
+ <tr>
66
+ <td>1</td><td>47</td><td>59</td><td>60</td>
67
+ <td>3</td><td>0</td><td>0</td><td>0</td>
68
+ </tr>
69
+ <tr>
70
+ <td>1</td><td>47</td><td>59</td><td>61</td>
71
+ <td>3</td><td>0</td><td>0</td><td>1</td>
72
+ </tr>
73
+ <tr>
74
+ <td>0</td><td>0</td><td>0</td><td>86399</td>
75
+ <td>0</td><td>23</td><td>59</td><td>59</td>
76
+ </tr>
77
+ <tr>
78
+ <td>0</td><td>0</td><td>0</td><td>86400</td>
79
+ <td>1</td><td>0</td><td>0</td><td>0</td>
80
+ </tr>
81
+ <tr>
82
+ <td>0</td><td>0</td><td>0</td><td>86401</td>
83
+ <td>1</td><td>0</td><td>0</td><td>1</td>
84
+ </tr>
85
+ <tr>
86
+ <td>0</td><td>0</td><td>0</td><td>9223372036854775807</td>
87
+ <td>106751991167300</td><td>15</td><td>30</td><td>7</td>
88
+ </tr>
89
+ </tbody>
90
+ </table>
91
+
92
+ </body>
93
+ </html>
@@ -0,0 +1,63 @@
1
+ <!--
2
+ ! Excerpted from "Scripted GUI Testing With Ruby",
3
+ ! published by The Pragmatic Bookshelf.
4
+ ! Copyrights apply to this code. It may not be used to create training material,
5
+ ! courses, books, articles, and the like. Contact us if you are in doubt.
6
+ ! We make no guarantees that this code is fit for any purpose.
7
+ ! Visit http://www.pragmaticprogrammer.com/titles/idgtr for more book information.
8
+ -->
9
+ <html>
10
+
11
+ <head>
12
+ <title>Calculator Test</title>
13
+ <style type="text/css">
14
+ table {
15
+ background: silver;
16
+ margin: 2px;
17
+ padding: 0px;
18
+ border: solid grey;
19
+ border-width: 1px 0px 0px 1px;
20
+ }
21
+
22
+ td {
23
+ border: solid grey;
24
+ border-width: 0px 1px 1px 0px;
25
+ padding: 1px 3px 1px 3px;
26
+ }
27
+ </style>
28
+ </head>
29
+
30
+ <body>
31
+
32
+
33
+ <table border="1">
34
+ <tbody>
35
+ <tr><td colspan="8">CalculateTime</td></tr>
36
+ <tr> <!-- (1) -->
37
+ <td><em>days</em></td>
38
+ <td><em>hours</em></td>
39
+ <td><em>mins</em></td>
40
+ <td><em>secs</em></td>
41
+
42
+ <td><em>days()</em></td>
43
+ <td><em>hours()</em></td>
44
+ <td><em>mins()</em></td>
45
+ <td><em>secs()</em></td>
46
+ </tr>
47
+
48
+ <tr>
49
+ <td>1</td> <td>47</td> <td>59</td> <td>59</td>
50
+ <td>2</td> <td>23</td> <td>59</td> <td>59</td>
51
+ </tr>
52
+ <tr>
53
+ <td>1</td> <td>47</td> <td>59</td> <td>60</td>
54
+ <td>3</td> <td>0</td> <td>0</td> <td>0</td>
55
+ </tr>
56
+
57
+ <!-- ... and so on -->
58
+ </tbody>
59
+ </table>
60
+
61
+
62
+ </body>
63
+ </html>
@@ -0,0 +1,39 @@
1
+ #---
2
+ # Excerpted from "Scripted GUI Testing With Ruby",
3
+ # published by The Pragmatic Bookshelf.
4
+ # Copyrights apply to this code. It may not be used to create training material,
5
+ # courses, books, articles, and the like. Contact us if you are in doubt.
6
+ # We make no guarantees that this code is fit for any purpose.
7
+ # Visit http://www.pragmaticprogrammer.com/titles/idgtr for more book information.
8
+ #---
9
+ require 'rubygems'
10
+
11
+
12
+ require 'fit/column_fixture'
13
+ require 'calculator'
14
+
15
+ class CalculateTime < Fit::ColumnFixture
16
+ def initialize
17
+ @calc = Calculator.single
18
+ @days = @hours = @mins = @secs = nil
19
+ end
20
+ end
21
+
22
+
23
+
24
+ class CalculateTime
25
+ attr_accessor :days, :hours, :mins
26
+ attr_reader :secs
27
+
28
+ def secs=(value)
29
+ @secs = value
30
+
31
+ @calc.enter_time @days, @hours, @mins, @secs
32
+ @calc.plus
33
+ @calc.enter_number 0
34
+ @calc.equals
35
+
36
+ @days, @hours, @mins, @secs = @calc.time
37
+ end
38
+ end
39
+
@@ -0,0 +1,108 @@
1
+ #---
2
+ # Excerpted from "Scripted GUI Testing With Ruby",
3
+ # published by The Pragmatic Bookshelf.
4
+ # Copyrights apply to this code. It may not be used to create training material,
5
+ # courses, books, articles, and the like. Contact us if you are in doubt.
6
+ # We make no guarantees that this code is fit for any purpose.
7
+ # Visit http://www.pragmaticprogrammer.com/titles/idgtr for more book information.
8
+ #---
9
+ require 'java'
10
+ require 'jemmy.jar'
11
+
12
+ $CLASSPATH << '.'
13
+ include_class 'org.crocodile.timecalc.TimeCalcApp'
14
+ include_class 'org.netbeans.jemmy.JemmyProperties'
15
+ include_class 'org.netbeans.jemmy.TestOut'
16
+
17
+ %w(Frame Label Button).each do |o|
18
+ include_class "org.netbeans.jemmy.operators.#{o}Operator"
19
+ end
20
+
21
+ JemmyProperties.set_current_timeout 'DialogWaiter.WaitFrameTimeout', 3000
22
+ JemmyProperties.set_current_output TestOut.get_null_output
23
+
24
+ class Calculator
25
+ def initialize
26
+ TimeCalcApp.main nil
27
+
28
+ @main_window = FrameOperator.new 'Time Calc'
29
+ @result = LabelOperator.new @main_window
30
+
31
+ keys = (0..9).to_a + [:days, :hours,
32
+ :minutes, :seconds,
33
+ :help, :off,
34
+ '+', '-', '*', '/',
35
+ '=', 'C']
36
+
37
+ @buttons = {}
38
+ keys.each do |k|
39
+ @buttons[k] = ButtonOperator.new @main_window, k.to_s.capitalize
40
+ end
41
+ end
42
+
43
+ def clear
44
+ @buttons['C'].push
45
+ end
46
+
47
+ def plus
48
+ @buttons['+'].push
49
+ end
50
+
51
+ def equals
52
+ @buttons['='].push
53
+ sleep 0.5
54
+ end
55
+
56
+ def off
57
+ @buttons[:off].push
58
+ end
59
+
60
+ def enter_number(number)
61
+ number.to_i.to_s.split(//).each do |n|
62
+ @buttons[n.to_i].push
63
+ end
64
+ end
65
+
66
+ def enter_time(days, hours, minutes, seconds)
67
+ numbers = [days, hours, minutes, seconds]
68
+ units = [:days, :hours, :minutes, :seconds]
69
+ skip = true
70
+
71
+ numbers.each_with_index do |number, index|
72
+ skip &&= (0 == number)
73
+
74
+ unless skip
75
+ enter_number(number)
76
+ @buttons[units[index]].push
77
+ end
78
+ end
79
+ end
80
+
81
+ def time
82
+ result = {}
83
+
84
+ text = @result.text
85
+ text.scan(/[0-9]+[dhms]/).collect do |part|
86
+ number = part.to_i
87
+ units = part[-1..-1]
88
+ result[units] = number
89
+ end
90
+
91
+ ['d', 'h', 'm', 's'].map {|u| result[u] || 0}
92
+ end
93
+
94
+ def total_seconds
95
+ multipliers = [86400, 3600, 60, 1]
96
+ time.zip(multipliers).inject(0) do |total, part|
97
+ total + part[0] * part[1]
98
+ end
99
+ end
100
+
101
+ def self.single
102
+ @@single ||= Calculator.new
103
+ end
104
+ end
105
+
106
+ if __FILE__ == $0
107
+ Calculator.new
108
+ end
@@ -0,0 +1,27 @@
1
+ #---
2
+ # Excerpted from "Scripted GUI Testing With Ruby",
3
+ # published by The Pragmatic Bookshelf.
4
+ # Copyrights apply to this code. It may not be used to create training material,
5
+ # courses, books, articles, and the like. Contact us if you are in doubt.
6
+ # We make no guarantees that this code is fit for any purpose.
7
+ # Visit http://www.pragmaticprogrammer.com/titles/idgtr for more book information.
8
+ #---
9
+
10
+ require 'fit/fixture'
11
+ require 'calculator'
12
+
13
+ class CalculatorActions < Fit::Fixture
14
+ def initialize
15
+ @calc = Calculator.single
16
+ end
17
+
18
+ def number(value)
19
+ @calc.enter_number value
20
+ end
21
+
22
+ [:plus, :equals, :total_seconds].each do |name|
23
+ define_method(name) do
24
+ @calc.send name
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,47 @@
1
+ #---
2
+ # Excerpted from "Scripted GUI Testing With Ruby",
3
+ # published by The Pragmatic Bookshelf.
4
+ # Copyrights apply to this code. It may not be used to create training material,
5
+ # courses, books, articles, and the like. Contact us if you are in doubt.
6
+ # We make no guarantees that this code is fit for any purpose.
7
+ # Visit http://www.pragmaticprogrammer.com/titles/idgtr for more book information.
8
+ #---
9
+ require 'calculator'
10
+
11
+ describe 'a new calculator', :shared => true do
12
+ before do
13
+ @calc = Calculator.single
14
+ @calc.clear
15
+ end
16
+ end
17
+
18
+ module AdditionHelper
19
+ def add_and_check(number, result)
20
+ @calc.enter_number number
21
+ @calc.equals
22
+ @calc.total_seconds.should == result
23
+ end
24
+ end
25
+
26
+
27
+ describe 'Starting with 1' do
28
+ include AdditionHelper
29
+
30
+ it_should_behave_like 'a new calculator'
31
+
32
+ before do
33
+ @calc.enter_number 1
34
+ @calc.plus
35
+ end
36
+
37
+ it 'should add 0 correctly' do
38
+ add_and_check(0, 1)
39
+ end
40
+
41
+ it 'should add 1 correctly' do
42
+ add_and_check(1, 2)
43
+ end
44
+
45
+ # two more nearly-identical examples
46
+ end
47
+
@@ -0,0 +1,32 @@
1
+ #---
2
+ # Excerpted from "Scripted GUI Testing With Ruby",
3
+ # published by The Pragmatic Bookshelf.
4
+ # Copyrights apply to this code. It may not be used to create training material,
5
+ # courses, books, articles, and the like. Contact us if you are in doubt.
6
+ # We make no guarantees that this code is fit for any purpose.
7
+ # Visit http://www.pragmaticprogrammer.com/titles/idgtr for more book information.
8
+ #---
9
+ require 'calculator'
10
+
11
+ $:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
12
+
13
+ require 'rubygems'
14
+ require 'fit/parse'
15
+ require 'fit/file_runner'
16
+
17
+ report = ARGV[1]
18
+ unless report.nil?
19
+ Fit::Parse.footnote_path = File.dirname(report) + File::SEPARATOR
20
+ end
21
+
22
+
23
+ class CalcRunner < Fit::FileRunner
24
+ def run(args)
25
+ process_args args
26
+ process
27
+ $stderr.puts @fixture.totals
28
+ Calculator.single.off # will exit
29
+ end
30
+ end
31
+
32
+ CalcRunner.new.run(ARGV)
@@ -0,0 +1,109 @@
1
+ #---
2
+ # Excerpted from "Scripted GUI Testing With Ruby",
3
+ # published by The Pragmatic Bookshelf.
4
+ # Copyrights apply to this code. It may not be used to create training material,
5
+ # courses, books, articles, and the like. Contact us if you are in doubt.
6
+ # We make no guarantees that this code is fit for any purpose.
7
+ # Visit http://www.pragmaticprogrammer.com/titles/idgtr for more book information.
8
+ #---
9
+ require 'rubygems'
10
+
11
+
12
+ require 'test/unit'
13
+ require 'test/unit/ui/console/testrunner'
14
+ require 'functional_test_matrix'
15
+ require 'spec'
16
+
17
+ Test::Unit::TestCase.extend FunctionalTestMatrix
18
+
19
+
20
+
21
+
22
+ require 'calculator'
23
+
24
+ class CalculatorTest < Test::Unit::TestCase
25
+ def setup
26
+ @calc ||= Calculator.single #(1)
27
+ @calc.clear
28
+ end
29
+ end
30
+
31
+
32
+
33
+
34
+ class CalculatorTest
35
+ Constants = {:huge => 2**63 - 2, :huge_1 => 2**63 - 1, :over => 0}
36
+
37
+ def number_for(value) #(2)
38
+ Constants[value.to_s.intern] || value.to_s.to_i
39
+ end
40
+
41
+ def matrix_init_addition(_, value)
42
+ @seconds = number_for value
43
+ @calc.enter_number @seconds
44
+ end
45
+
46
+ def matrix_setup_add(value)
47
+ @adding = number_for value
48
+
49
+ @calc.plus
50
+ @calc.enter_number @adding
51
+ @calc.equals
52
+ end
53
+
54
+ def matrix_test(expected)
55
+ @calc.total_seconds.should == number_for(expected)
56
+ end
57
+ end
58
+
59
+
60
+
61
+
62
+ class CalculatorTest
63
+ alias_method :old_method_missing, :method_missing
64
+
65
+ def method_missing(name, *args)
66
+ case name.to_s
67
+ when /matrix_setup_add_(.+)/
68
+ matrix_setup_add $1
69
+ when /matrix_test_(.+)/
70
+ matrix_test $1
71
+ else
72
+ old_method_missing name, *args
73
+ end
74
+ end
75
+ end
76
+
77
+
78
+
79
+
80
+ class CalculatorTest
81
+ matrix :addition, :to_0, :to_1, :to_2, :to_huge
82
+ action :add_0, 0, 1, 2, :huge
83
+ action :add_1, 1, 2, 3, :huge_1
84
+ action :add_2, 2, 3, 4, :over
85
+ action :add_huge, :huge, :huge_1, :over, :over
86
+ end
87
+
88
+
89
+
90
+
91
+ class CalculatorTest
92
+ _ = :na
93
+
94
+ matrix :addition, :to_0, :to_1, :to_2, :to_huge
95
+ action :add_0, 0, _, _, _
96
+ action :add_1, 1, 2, _, _
97
+ action :add_2, 2, 3, 4, _
98
+ action :add_huge, :huge, :huge_1, :over, :over
99
+ end
100
+
101
+
102
+
103
+
104
+ class CalculatorOff < Test::Unit::TestCase
105
+ def test_off
106
+ Thread.new {sleep 3; Calculator.single.off}
107
+ end
108
+ end
109
+
@@ -0,0 +1,17 @@
1
+ #---
2
+ # Excerpted from "Scripted GUI Testing With Ruby",
3
+ # published by The Pragmatic Bookshelf.
4
+ # Copyrights apply to this code. It may not be used to create training material,
5
+ # courses, books, articles, and the like. Contact us if you are in doubt.
6
+ # We make no guarantees that this code is fit for any purpose.
7
+ # Visit http://www.pragmaticprogrammer.com/titles/idgtr for more book information.
8
+ #---
9
+ fixture.days = 1
10
+ fixture.hours = 47
11
+ fixture.mins = 59
12
+ fixture.secs = 59 #(1)
13
+
14
+ passed = (fixture.days == 2)
15
+ passed &&= (fixture.hours == 23)
16
+ passed &&= (fixture.mins == 59)
17
+ passed &&= (fixture.secs == 59)
@@ -0,0 +1,67 @@
1
+ #---
2
+ # Excerpted from "Scripted GUI Testing With Ruby",
3
+ # published by The Pragmatic Bookshelf.
4
+ # Copyrights apply to this code. It may not be used to create training material,
5
+ # courses, books, articles, and the like. Contact us if you are in doubt.
6
+ # We make no guarantees that this code is fit for any purpose.
7
+ # Visit http://www.pragmaticprogrammer.com/titles/idgtr for more book information.
8
+ #---
9
+
10
+ require 'rubygems'
11
+ require 'selenium'
12
+
13
+ class BookSearch
14
+ def initialize
15
+ @browser = Selenium::SeleniumDriver.new \
16
+ 'localhost', 4444, '*firefox', 'http://www.pragprog.com', 10000
17
+ @browser.start
18
+ end
19
+
20
+ def close
21
+ @browser.stop
22
+ end
23
+ end
24
+
25
+
26
+
27
+
28
+ class BookSearch
29
+ ResultCounter = '//table[@id="bookshelf"]//tr' #(1)
30
+ ResultReader = 'xpath=/descendant::td[@class="description"]'
31
+
32
+ def find(term)
33
+ @browser.open '/'
34
+ @browser.type '//input[@id="q"]', term
35
+ @browser.click '//button[@class="go"]'
36
+ @browser.wait_for_page_to_load 5000
37
+
38
+ num_results = @browser.get_xpath_count(ResultCounter).to_i
39
+
40
+ (1..num_results).inject({}) do |results, i|
41
+ full_title = @browser.get_text("#{ResultReader}[#{i}]/h4/a") #(2)
42
+ byline = @browser.get_text("#{ResultReader}[#{i}]/p[@class='by-line']")
43
+ url = @browser.get_attribute("#{ResultReader}[#{i}]/h4/a@href")
44
+
45
+ title, subtitle = full_title.split ': '
46
+ authors = authors_from byline #(3)
47
+
48
+ results.merge title =>
49
+ {
50
+ :title => title,
51
+ :subtitle => subtitle,
52
+ :url => url,
53
+ :authors => authors
54
+ }
55
+ end
56
+ end
57
+ end
58
+
59
+
60
+
61
+
62
+ class BookSearch
63
+ def authors_from(byline)
64
+ byline[3..-1].gsub(/(,? and )|(,? with )/, ',').split(',')
65
+ end
66
+ end
67
+
@@ -0,0 +1,60 @@
1
+ #---
2
+ # Excerpted from "Scripted GUI Testing With Ruby",
3
+ # published by The Pragmatic Bookshelf.
4
+ # Copyrights apply to this code. It may not be used to create training material,
5
+ # courses, books, articles, and the like. Contact us if you are in doubt.
6
+ # We make no guarantees that this code is fit for any purpose.
7
+ # Visit http://www.pragmaticprogrammer.com/titles/idgtr for more book information.
8
+ #---
9
+
10
+ require 'rubygems'
11
+ require 'watir'
12
+
13
+ class BookSearch
14
+ def initialize
15
+ @browser = Watir::IE.new
16
+ end
17
+
18
+ def close
19
+ @browser.close
20
+ end
21
+ end
22
+
23
+
24
+
25
+
26
+ class BookSearch
27
+ def find(term)
28
+ @browser.goto 'http://www.pragprog.com'
29
+ @browser.text_field(:id, 'q').set('Ruby') #(1)
30
+ @browser.button(:class, 'go').click #(2)
31
+
32
+ bookshelf = @browser.table(:id, 'bookshelf')
33
+ num_results = bookshelf.row_count
34
+
35
+ (1..num_results).inject({}) do |results, i|
36
+ book = bookshelf[i][2] #(3)
37
+
38
+ full_title = book.h4(:index, 1).text
39
+ byline = book.p(:class, 'by-line').text
40
+ url = book.link(:index, 1).href
41
+
42
+ title, subtitle = full_title.split ': '
43
+ authors = authors_from byline
44
+
45
+ results.merge title => {
46
+ :title => title,
47
+ :subtitle => subtitle,
48
+ :url => url,
49
+ :authors => authors }
50
+ end
51
+ end
52
+ end
53
+
54
+
55
+
56
+ class BookSearch
57
+ def authors_from(byline)
58
+ byline[3..-1].gsub(/(,? and )|(,? with )/, ',').split(',')
59
+ end
60
+ end