rubyuw 0.99.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. data/.gitignore +4 -0
  2. data/README.md +81 -0
  3. data/Rakefile +45 -0
  4. data/VERSION +1 -0
  5. data/lib/rubyuw.rb +9 -0
  6. data/lib/rubyuw/base.rb +122 -0
  7. data/lib/rubyuw/connection.rb +145 -0
  8. data/lib/rubyuw/curriculum_enrollment.rb +75 -0
  9. data/lib/rubyuw/errors.rb +16 -0
  10. data/lib/rubyuw/schedule.rb +52 -0
  11. data/lib/rubyuw/sln.rb +108 -0
  12. data/rubyuw.gemspec +97 -0
  13. data/test/live/curriculum_enrollment_test.rb +47 -0
  14. data/test/live/sln_test.rb +54 -0
  15. data/test/live/test_helper.rb +24 -0
  16. data/test/mocked/base_test.rb +171 -0
  17. data/test/mocked/connection_test.rb +178 -0
  18. data/test/mocked/curriculum_enrollment_test.rb +158 -0
  19. data/test/mocked/fixture_pages/bad_request.html +80 -0
  20. data/test/mocked/fixture_pages/curric_courses.html +2659 -0
  21. data/test/mocked/fixture_pages/curric_no_courses.html +88 -0
  22. data/test/mocked/fixture_pages/curric_no_curric_found.html +86 -0
  23. data/test/mocked/fixture_pages/logged_in_relay.html +660 -0
  24. data/test/mocked/fixture_pages/login.html +121 -0
  25. data/test/mocked/fixture_pages/no_form_login.html +122 -0
  26. data/test/mocked/fixture_pages/no_login_button.html +100 -0
  27. data/test/mocked/fixture_pages/not_logged_in_relay.html +15 -0
  28. data/test/mocked/fixture_pages/registration.html +699 -0
  29. data/test/mocked/fixture_pages/registration_error.html +699 -0
  30. data/test/mocked/fixture_pages/registration_error_no_rows.html +627 -0
  31. data/test/mocked/fixture_pages/registration_no_form.html +700 -0
  32. data/test/mocked/fixture_pages/registration_success.html +718 -0
  33. data/test/mocked/fixture_pages/registration_unknown.html +721 -0
  34. data/test/mocked/fixture_pages/schedule.html +166 -0
  35. data/test/mocked/fixture_pages/schedule_diff_credit_row.html +167 -0
  36. data/test/mocked/fixture_pages/schedule_empty.html +130 -0
  37. data/test/mocked/fixture_pages/schedule_no_credit_row.html +169 -0
  38. data/test/mocked/fixture_pages/sln_does_not_exist.html +85 -0
  39. data/test/mocked/fixture_pages/sln_no_course_info.html +94 -0
  40. data/test/mocked/fixture_pages/sln_no_course_notes.html +94 -0
  41. data/test/mocked/fixture_pages/sln_no_enrollment_info.html +94 -0
  42. data/test/mocked/fixture_pages/sln_status.html +92 -0
  43. data/test/mocked/fixture_pages/welcome.html +93 -0
  44. data/test/mocked/schedule_test.rb +89 -0
  45. data/test/mocked/sln_test.rb +146 -0
  46. data/test/mocked/test_helper.rb +67 -0
  47. data/test/password.rb.sample +8 -0
  48. metadata +118 -0
@@ -0,0 +1,92 @@
1
+ <HTML>
2
+ <HEAD>
3
+ <META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
4
+ <TITLE>Current Section Status</TITLE>
5
+ <LINK REL="stylesheet" TYPE="text/css" HREF="https://www.washington.edu/home/home.css">
6
+ </HEAD>
7
+ <BODY>
8
+
9
+ <table border='0' cellpadding='0' cellspacing='0' width='100%' align='center'>
10
+ <tr>
11
+ <td width='100%' class='rpad'>
12
+ <a href='http://www.washington.edu/' target='_top'><img src='/sdb_library/images/uwlogo150p.gif' border='0' width='150' height='28' alt='University of Washington'></a>
13
+ </td>
14
+ <td rowspan='2' valign='bottom'>
15
+
16
+ <table border='0' cellpadding='0' cellspacing='0'>
17
+ <tr><td colspan='2' bgcolor='#666666'><img src='/sdb_library/images/1px_transparent.gif' height='1'></td></tr>
18
+ <tr>
19
+ <td bgcolor='#666666'><img src='/sdb_library/images/1px_transparent.gif' width='7' height='1'></td>
20
+ <td nowrap><span class='l1text'>
21
+ &nbsp;<a href='http://www.washington.edu/home/search.html' target='_top'>Search</A> |
22
+ <a href='http://www.washington.edu/home/directories.html' target='_top'>Directories</A> |
23
+ <a href='http://www.washington.edu/tools/' target='_top'>Reference Tools</A>
24
+ </span></td>
25
+ </tr>
26
+ </table>
27
+
28
+ </td>
29
+ </tr>
30
+ <tr>
31
+ <td bgcolor='#666666'><img src='/sdb_library/images/1px_transparent.gif' height='1'></td>
32
+ </tr>
33
+ </table>
34
+ <table border='0' cellpadding='0' cellspacing='0' width='100%'>
35
+ <tr>
36
+ <td bgcolor='#e6e6e6'><img src='/sdb_library/images/1px_transparent.gif' width='1' height='5'></TD>
37
+ </tr>
38
+ </table>
39
+ <table border='0' cellpadding='0' cellspacing='0' width='100%'>
40
+ <tr>
41
+ <td rowspan='2' nowrap><span class='l1text'>
42
+ <a href='http://www.washington.edu/' target='_top'>UW Home</A>&nbsp;&gt; <a href='http://www.washington.edu/students/' target='_top'>Student Guide</A>&nbsp;&gt; <a href='http://www.washington.edu/students/timeschd/' target='_top'>Time Schedule</A>&nbsp;&gt; <a href='http://www.washington.edu/students/timeschd/AUT2009' target='_top'>Autumn 2009</A>&nbsp;&gt; <a href='http://www.washington.edu/students/timeschd/AUT2009/phil ' target='_top'>PHILOSOPHY </A>&nbsp;
43
+ </span></td>
44
+ <td width='5' rowspan='3' bgcolor='#cccccc'><img src='/sdb_library/images/1px_transparent.gif' border='0' width='7' height='1'></td>
45
+ <td bgcolor='#cccccc' height='1'><img src='/sdb_library/images/1px_transparent.gif' border='0' width='1' height='1'></td>
46
+ </tr>
47
+ <tr>
48
+ <td width='100%'>&nbsp;</td>
49
+ </tr>
50
+ <tr>
51
+ <td bgcolor='#cccccc'><img src='/sdb_library/images/1px_transparent.gif' border='0' width='1' height='1'></td>
52
+ </tr>
53
+ </table>
54
+ <H1>Current Section Status - Autumn Quarter 2009</H1>
55
+ <P><TABLE BORDER=1 CELLPADDING=3><TR BGCOLOR="#d0d0d0"><TH>SLN</TH><TH>Course</TH><TH>Section</TH><TH>Type</TH><TH>Credits</TH><TH>Title</TH><TH>General Education<BR>and Basic Skills<BR>Requirements</TH></TR><TR ROWSPAN=1><TD><TT>17237</TT></TD><TD><TT>PHIL &nbsp;120</TT></TD><TD ALIGN="center"><TT>AE </TT></TD><TD ALIGN="center"><TT>QZ</TT></TD><TD ALIGN="center"><TT>&nbsp;</TT></TD><TD><TT><A HREF="http://www.washington.edu/students/crscat/phil.html#phil120" TARGET="_phil120">INTRO TO LOGIC </A></TT></TD><TD><TT>&nbsp;</TT></TD></TR><TR><TD COLSPAN=7><TT><A HREF="http://sdb.admin.washington.edu/textbooks/query.asp?qtr=Autumn&sln1=17237" TARGET="_tb">Display Textbooks</A></TT></TD></TR></TABLE><P><TABLE BORDER=1 CELLPADDING=3><TR BGCOLOR="#d0d0d0"><TH>Current<BR>Enrollment</TH><TH>Limit</TH><TH>Room<BR>Capacity</TH><TH>Space<BR>Available</TH><TH>Status</TH></B></TR><TR><TD ALIGN="center"><TT> 25</TT></TD><TD ALIGN="center"><TT> 25</TT></TD><TD ALIGN="center"><TT> 40</TT></TD><TD ALIGN="center"><TT>&nbsp;</TT></TD><TD ALIGN="center"><TT><B>** Closed **</B></TT></TD></TR></TABLE>
56
+ <P><TABLE BORDER=1 CELLPADDING=3><TR BGCOLOR="#d0d0d0"><TH COLSPAN=4>Meetings</TH></TR>
57
+ <TR BGCOLOR="#d0d0d0"><TH>Days</TH><TH>Time</TH><TH>Location</TH><TH>Instructor</TH></TR>
58
+ <TR><TD NOWRAP VALIGN="top"><TT>TTh</TT></TD>
59
+ <TD NOWRAP VALIGN="top"><TT>10:30-11:20</TT></TD>
60
+ <TD NOWRAP VALIGN="top"><TT><A HREF="http://www.washington.edu/students/maps/map.cgi?DEN" TARGET="_DEN">DEN</A>&nbsp;212</TT></TD>
61
+ <TD NOWRAP><TT>&nbsp;</TT></TD>
62
+ </TR></TABLE>
63
+ <P><TABLE BORDER=1 CELLPADDING=3><TR BGCOLOR="#d0d0d0"><TH>Notes</TH></TR><TR><TD><TT>Quiz Section </TT></TD></TR></TABLE>
64
+ <P></P>
65
+ <table border='0' cellpadding='0' cellspacing='0' align='center' width='100%'>
66
+ <tr>
67
+ <td rowspan='2'>
68
+ <a href='http://www.washington.edu/'><img src='/sdb_library/images/footersealW.gif' border='0' height='48' width='48' hspace='5' vspace='7' alt='UW Seal'></a>
69
+ </td>
70
+ <td rowspan='3' bgcolor='#666666' width='5'><img src='/sdb_library/images/1px_transparent.gif' width='7' height='1'></td>
71
+ <td colspan='2' bgcolor='#666666' height='1'><img src='/sdb_library/images/1px_transparent.gif' width='1' height='1'></td>
72
+ </tr><tr>
73
+ <td width='100%'>
74
+ <table border='0' width='100%'>
75
+ <tr>
76
+ <td valign='top'><address>
77
+ Office of the Registrar<br>
78
+ registrar@u.washington.edu<br>
79
+ June 27, 2009
80
+ </address>
81
+ </td>
82
+ </tr>
83
+ </table>
84
+ </td>
85
+ </tr><tr height='1'>
86
+ <td bgcolor='#666666'><img src='/sdb_library/images/1px_transparent.gif' width='1' height='1'></td>
87
+ </tr>
88
+ </table>
89
+
90
+
91
+ </BODY>
92
+ </HTML>
@@ -0,0 +1,93 @@
1
+ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
2
+ "http://www.w3.org/TR/html4/loose.dtd">
3
+ <html>
4
+ <head>
5
+ <title>Welcome to MyUW</title>
6
+ <meta http-equiv="Content-type" content="text/html; charset=utf-8">
7
+ <meta http-equiv="pragma" content="no-cache">
8
+ <meta http-equiv="cache-control" content="no-cache">
9
+ <meta http-equiv="expires" content="Fri, 01 Dec 2000 00:00:00 GMT">
10
+ <meta name="author" lang="en"
11
+ content="Copyright (c) 1998- University of Washington">
12
+
13
+ <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon">
14
+ <link rel="stylesheet" href="/css/myuw.css" type="text/css">
15
+ <script type="text/javascript" src="/js/base.js"></script>
16
+ </head>
17
+
18
+ <body bgcolor="#ffffff" onLoad="sf()">
19
+
20
+ <table cellpadding="0" cellspacing="20" border="0" width="700" align="center">
21
+
22
+ <tr>
23
+ <td width="50%" valign="baseline">
24
+ <img src="/graphics/myuwbig.gif" border="0" alt="MyUW Logo">
25
+ </td>
26
+
27
+ <td width="2" bgcolor="#9999FF" rowspan="4"><img src="/graphics/1pixffcc33.gif"
28
+ width="1" height="1" align="BOTTOM" alt=""></td>
29
+
30
+ <td valign="middle" align="left">
31
+ Your personal gateway to the UW Web resources you use most.
32
+ </td>
33
+ </tr>
34
+
35
+
36
+
37
+ <tr>
38
+
39
+ <td align="left" style="padding-left: 10px;" valign="top">
40
+ <form method="get" name="f" action='https://myuw.washington.edu/servlet/user'><input type="submit" name="defbut" value="Log in with your UW NetID"></form></td>
41
+
42
+ <td align="left" rowspan="3" valign="top">
43
+ <a href="http://www.washington.edu/computing/uwnetid/">What is the UW NetID</a>?<br>
44
+ <a href="/info.html">Help, FAQs</a><br>
45
+ <a href="/about.html">About MyUW</a><br>
46
+ <a href="/policy.html">Privacy statement</a><br>
47
+ <a href="http://www.washington.edu/computing/rules">Appropriate use</a>
48
+ </td>
49
+ </tr>
50
+
51
+ <tr>
52
+ <td align="left" style="padding-left: 10px;" valign="top">
53
+ <form method="get" action='http://myuw.washington.edu/servlet/guest'>
54
+ <input type="submit" value="Enter as a guest"></form></td>
55
+ </tr>
56
+
57
+ <tr>
58
+ <td align="left" style="padding: 10px;">
59
+ <!--
60
+ <div style="background-color: #E6CDE6; padding: 5px;">
61
+ <a href="http://careerweek.washington.edu/">Career Discovery Week, Jan. 26-30, 2009</a><br>All three UW campuses
62
+ </div>
63
+ -->
64
+ </td>
65
+ </tr>
66
+
67
+ <tr>
68
+ <td colspan="3">
69
+ <table border="0" cellpadding="5" >
70
+ <tr><td><img src="/graphics/caution.gif" alt= "caution icon" align="right"></td>
71
+ <td>To prevent unauthorized use of your UW NetID and protect your privacy, <a href="info.html#logout"><b>Log Out</b> and completely exit your Web browser</a> when you finish.</td></table>
72
+ </td>
73
+ </tr>
74
+
75
+ <tr>
76
+ <td colspan="3">
77
+ <hr size="2" noshade >
78
+ <table border="0" cellspacing="0" cellpadding="0" width="100%">
79
+ <tr><td align="center" valign="top" width="73"><a href="http://www.washington.edu/"><img src="/graphics/UW.gif" width="53" height="37" alt="UW logo" border="0"></a></td>
80
+ <td align="left" valign="top" style="white-space:nowrap"><div class="chancontrols"><img src="/graphics/uwtech.gif" width="167" height="44" alt="UW Technology logo" align="top" border="0"></div>
81
+ <div><address><a href="/cgi-bin/contactmyuw.cgi">Contact MyUW</a><br>Copyright&copy; 1998-2009, University of Washington<br>MyUW&reg; is a registered trademark of the University of Washington.</address></div></td>
82
+ </tr></table>
83
+
84
+ </td>
85
+ </tr>
86
+ </table>
87
+
88
+ <script type="text/javascript">
89
+ displayAlert();
90
+ </script>
91
+
92
+ </body>
93
+ </html>
@@ -0,0 +1,89 @@
1
+ require File.join(File.dirname(__FILE__), 'test_helper')
2
+
3
+ class ScheduleTest < Test::Unit::TestCase
4
+ setup do
5
+ RubyUW::Schedule.publicize_singleton_methods
6
+ end
7
+
8
+ teardown do
9
+ RubyUW::Schedule.protect_singleton_methods
10
+ end
11
+
12
+ context "getting the schedule" do
13
+ context "with authentication" do
14
+ should "raise an error if not authenticated" do
15
+ RubyUW::Base.expects(:authenticated?).returns(false)
16
+ assert_raises(RubyUW::Errors::NotLoggedInError) { RubyUW::Schedule.get }
17
+ end
18
+
19
+ should "not raise an error if authenticated" do
20
+ RubyUW::Base.expects(:authenticated?).returns(true)
21
+ assert_nothing_raised { RubyUW::Schedule.get }
22
+ end
23
+ end
24
+
25
+ context "with the mocked pages" do
26
+ setup do
27
+ RubyUW::Base.stubs(:authenticated?).returns(true)
28
+
29
+ @courses = {
30
+ "14368" => {
31
+ :course => "HIST 111 A",
32
+ :type => "LC",
33
+ :credits => "5.0",
34
+ :title => "THE ANCIENT WORLD",
35
+ :days => "MTWTh",
36
+ :time => "130-220",
37
+ :location => "SMI 120",
38
+ :instructor => "WALKER,JOEL T"
39
+ },
40
+ "14372" => {},
41
+ "12271" => {}
42
+ }
43
+ end
44
+
45
+ should "pull the right data" do
46
+ expect_get("schedule")
47
+ schedule = RubyUW::Schedule.get
48
+
49
+ assert !schedule.nil?
50
+ assert_equal @courses.length, schedule.length
51
+ schedule.each do |course|
52
+ current_course = @courses[course.sln]
53
+ assert !current_course.nil?
54
+
55
+ current_course.each do |k,v|
56
+ assert_equal v, course.data(k)
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
62
+
63
+ context "extracting courses" do
64
+ setup do
65
+ @page = mock('page')
66
+ end
67
+
68
+ should "call extract_course on every result from the xpath" do
69
+ @results = [1,2,3]
70
+ @page.expects(:search).returns(@results)
71
+ RubyUW::Schedule.expects(:extract_course).times(@results.length).returns({:sln => "foo"})
72
+ RubyUW::Schedule.extract_courses(@page)
73
+ end
74
+
75
+ should "turn the results of extract_course into a RubyUW::SLN object" do
76
+ @results = [1]
77
+ @page.expects(:search).returns(@results)
78
+ RubyUW::Schedule.expects(:extract_course).once.returns({ :sln => "foo" })
79
+ RubyUW::SLN.expects(:new).once.with("foo", anything, anything)
80
+ RubyUW::Schedule.extract_courses(@page)
81
+ end
82
+
83
+ should "return an array of results" do
84
+ @page.expects(:search).returns([])
85
+ results = RubyUW::Schedule.extract_courses(@page)
86
+ assert results.empty?
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,146 @@
1
+ require File.join(File.dirname(__FILE__), 'test_helper')
2
+
3
+ class SLNTest < Test::Unit::TestCase
4
+ setup do
5
+ RubyUW::SLN.publicize_singleton_methods
6
+ end
7
+
8
+ teardown do
9
+ RubyUW::SLN.protect_singleton_methods
10
+ end
11
+
12
+ context "SLN instance" do
13
+ setup do
14
+ @sln = "foo"
15
+ @term = "bar"
16
+ @data = {
17
+ :one => "1",
18
+ :two => "2"
19
+ }
20
+
21
+ @sln_obj = RubyUW::SLN.new(@sln, @term, @data)
22
+ end
23
+
24
+ should "return data values from the field method" do
25
+ @data.each do |k,v|
26
+ assert_equal v, @sln_obj.data(k)
27
+ end
28
+ end
29
+
30
+ should "convert to symbols so accessing by string works too" do
31
+ @data.each do |k,v|
32
+ assert_equal v, @sln_obj.data(k.to_s)
33
+ end
34
+ end
35
+ end
36
+
37
+ context "finding an SLN" do
38
+ context "with authentication" do
39
+ setup do
40
+ expect_get("bad_request", nil, :stubs)
41
+ RubyUW::SLN.stubs(:extract_data_from_page).returns({})
42
+ end
43
+
44
+ should "raise an error if not authenticated" do
45
+ RubyUW::Base.expects(:authenticated?).returns(false)
46
+ assert_raises(RubyUW::Errors::NotLoggedInError) { RubyUW::SLN.find("foo", "bar") }
47
+ end
48
+
49
+ should "not raise an error if authenticated" do
50
+ RubyUW::Base.expects(:authenticated?).returns(true)
51
+ assert_nothing_raised { RubyUW::SLN.find("foo", "bar") }
52
+ end
53
+ end
54
+
55
+ context "with checking if an SLN was requested too soon" do
56
+ should "return true if the URI matches the badrequest page" do
57
+ page = mock('page')
58
+ page.stubs(:uri).returns("http://www.washington.edu/students/timeschd/badrequest.html")
59
+
60
+ assert RubyUW::SLN.requested_too_soon?(page)
61
+ end
62
+
63
+ should "convert URI to string before checking" do
64
+ uri = mock('uri')
65
+ uri.expects(:to_s).returns("http://www.washington.edu/students/timeschd/badrequest.html")
66
+
67
+ page = mock('page')
68
+ page.stubs(:uri).returns(uri)
69
+
70
+ assert RubyUW::SLN.requested_too_soon?(page)
71
+ end
72
+
73
+ should "return false if the URI is anything else" do
74
+ page = mock('page')
75
+ page.stubs(:uri).returns("foo")
76
+
77
+ assert !RubyUW::SLN.requested_too_soon?(page)
78
+ end
79
+ end
80
+
81
+ context "with checking if an SLN exists or not" do
82
+ should "return false if the SLN does not exist string is found" do
83
+ mocked_page = RubyUW::Base.connection.get(path_to_html("sln_does_not_exist"))
84
+
85
+ assert !RubyUW::SLN.sln_exists?(mocked_page)
86
+ end
87
+
88
+ should "return true if the string is not found" do
89
+ mocked_page = RubyUW::Base.connection.get(path_to_html("sln_status"))
90
+
91
+ assert RubyUW::SLN.sln_exists?(mocked_page)
92
+ end
93
+ end
94
+
95
+ context "with checking whether time schedule is closed" do
96
+ should "return true if the URI matches the closed page" do
97
+ page = mock('page')
98
+ page.stubs(:uri).returns("http://www.washington.edu/students/timeschd/nots.html")
99
+
100
+ assert RubyUW::SLN.time_schedule_closed?(page)
101
+ end
102
+
103
+ should "return false if the URI is anything else" do
104
+ page = mock('page')
105
+ page.stubs(:uri).returns("foo")
106
+
107
+ assert !RubyUW::SLN.time_schedule_closed?(page)
108
+ end
109
+ end
110
+
111
+ context "raising exceptions on failures" do
112
+ setup do
113
+ RubyUW::Base.stubs(:authenticated?).returns(true)
114
+ RubyUW::SLN.stubs(:requested_too_soon?).returns(false)
115
+ RubyUW::SLN.stubs(:sln_exists?).returns(true)
116
+ RubyUW::SLN.stubs(:time_schedule_closed?).returns(false)
117
+ RubyUW::SLN.stubs(:extract_data_from_page).returns({})
118
+
119
+ page = mock('page')
120
+ RubyUW::Base.connection.stubs(:get).returns(page)
121
+
122
+ @sln = "foo"
123
+ @term = "bar"
124
+ end
125
+
126
+ should "raise SLNRequestedTooSoonError is requested too soon" do
127
+ RubyUW::SLN.expects(:requested_too_soon?).returns(true)
128
+ assert_raises(RubyUW::Errors::SLNRequestedTooSoonError) { RubyUW::SLN.find(@sln, @term) }
129
+ end
130
+
131
+ should "raise SLNDoesNotExistError if sln does not exist" do
132
+ RubyUW::SLN.expects(:sln_exists?).returns(false)
133
+ assert_raises(RubyUW::Errors::SLNDoesNotExistError) { RubyUW::SLN.find(@sln, @term) }
134
+ end
135
+
136
+ should "raise SLNServiceClosedError if the service is closed" do
137
+ RubyUW::SLN.expects(:time_schedule_closed?).returns(true)
138
+ assert_raises(RubyUW::Errors::SLNServiceClosedError) { RubyUW::SLN.find(@sln, @term) }
139
+ end
140
+
141
+ should "not raise any exception if all fail checks are valid" do
142
+ assert_nothing_raised { RubyUW::SLN.find(@sln, @term) }
143
+ end
144
+ end
145
+ end
146
+ end
@@ -0,0 +1,67 @@
1
+ require 'rubygems'
2
+ $:.unshift(File.join(File.dirname(__FILE__), '..', '..', 'lib'))
3
+ require 'rubyuw'
4
+ require 'test/unit'
5
+ require "contest"
6
+ require "stories"
7
+ require "mocha"
8
+
9
+ class Test::Unit::TestCase
10
+ def setup
11
+ RubyUW::Base.reset_connection!
12
+ RubyUW::Base.connection.follow_meta_refresh = false
13
+ end
14
+
15
+ def path_to_html(html)
16
+ "file://" + File.join(File.dirname(__FILE__), 'fixture_pages', "#{html}.html")
17
+ end
18
+
19
+ def expect_get(return_page, with=nil, expectation_type = :expects)
20
+ return_html = RubyUW::Base.connection.get(path_to_html(return_page))
21
+ expectation_obj = RubyUW::Base.connection.send(expectation_type, :get).returns(return_html)
22
+ expectation_obj.with(with) unless with.nil?
23
+
24
+ return_html
25
+ end
26
+
27
+ def mock_flow(flow)
28
+ flow_seq = sequence('flow')
29
+
30
+ flow.each do |task, params, return_html|
31
+ return_page = RubyUW::Base.connection.get(path_to_html(return_html))
32
+
33
+ relay_form = return_page.form_with(:name => 'relay')
34
+ relay_form.stubs(:submit) if relay_form
35
+
36
+ RubyUW::Base.connection.expects("execute_#{task}!").with(anything, *params).returns(return_page).in_sequence(flow_seq)
37
+ end
38
+ end
39
+ end
40
+
41
+ # Ugly hack. Avoiding using send() since that will not work in
42
+ # Ruby 1.9. Also, since I'm trying to make SINGLETON methods
43
+ # public, I can't do the Class.send(:public, *Class.protected_methods)
44
+ # trick. So this is the ugly hack until I can find a way around it.
45
+ # Anyone?
46
+ class Class
47
+ def publicize_singleton_methods
48
+ class << self
49
+ @_publicize_internals = protected_instance_methods
50
+ public *@_publicize_internals
51
+ end
52
+
53
+ if block_given?
54
+ yield
55
+
56
+ class <<self
57
+ protected *@_publicize_internals
58
+ end
59
+ end
60
+ end
61
+
62
+ def protect_singleton_methods
63
+ class <<self
64
+ protected *@_publicize_internals
65
+ end
66
+ end
67
+ end