mitchellh-rubyuw 0.4.1 → 0.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.1
1
+ 0.4.2
@@ -0,0 +1,18 @@
1
+ # General purpose errors used within MyUW
2
+
3
+ class MyUW
4
+ class NotLoggedInError < StandardError; end
5
+
6
+ # A generic error to capture strange invalid HTML
7
+ # results. These errors can typically be used to
8
+ # find edge cases of HTML (such as maintenance
9
+ # pages and so on) in MyUW
10
+ class InvalidPageError < StandardError
11
+ attr_reader :page
12
+
13
+ def initialize(page, msg=nil)
14
+ @page = page
15
+ super(msg)
16
+ end
17
+ end
18
+ end
data/lib/myuw/session.rb CHANGED
@@ -28,7 +28,7 @@ class MyUW
28
28
  # Make sure that email and password are filled out or this is
29
29
  # useless
30
30
  if @email.nil? || @password.nil?
31
- raise("Email and password weren't specified for MyUW session")
31
+ raise ArgumentError.new("Email and password weren't specified for MyUW session")
32
32
  end
33
33
 
34
34
  # Log out first
@@ -37,7 +37,7 @@ class MyUW
37
37
  # Go to the MyUW page and get to the login form
38
38
  login_page = get_login_page
39
39
  login_form = login_page.form_with(:name => 'query')
40
- raise("Login form was not found on the MyUW page") if login_form.nil?
40
+ raise InvalidPageError.new(login_page, "Login form was not found on the MyUW page") if login_form.nil?
41
41
  login_form.user = @email
42
42
  login_form.pass = @password
43
43
  relay_page = login_form.submit()
@@ -67,7 +67,7 @@ class MyUW
67
67
 
68
68
  # Click the login button to get to the forum
69
69
  entry_button = home.search("//input[@type='submit' and @value='Log in with your UW NetID']")
70
- raise("Failed to find the log in button") if entry_button.empty?
70
+ raise InvalidPageError.new(home, "Failed to find the log in button") if entry_button.empty?
71
71
 
72
72
  home
73
73
  end
data/lib/myuw/sln.rb CHANGED
@@ -29,9 +29,9 @@ class MyUW
29
29
 
30
30
  # Fetches the information for the given SLN.
31
31
  def fetch_data
32
- raise("SLN not set.") if @sln.nil?
33
- raise("Term not set.") if @term.nil?
34
- raise("User must be logged in to fetch SLN data") unless @myuw.logged_in?
32
+ raise ArgumentError.new("SLN not set.") if @sln.nil?
33
+ raise ArgumentError.new("Term not set.") if @term.nil?
34
+ raise NotLoggedInError.new("User must be logged in to fetch SLN data") unless @myuw.logged_in?
35
35
 
36
36
  # Request the actual page
37
37
  page = get_sln_page
@@ -61,9 +61,9 @@ class MyUW
61
61
  def get_sln_page
62
62
  page = @myuw.browser.get("https://sdb.admin.washington.edu/timeschd/uwnetid/sln.asp?QTRYR=#{@term}&SLN=#{@sln}")
63
63
  if page.uri.to_s == "http://www.washington.edu/students/timeschd/badrequest.html"
64
- raise("Attempted to fetch SLN data too soon.")
64
+ raise RequestSLNTooSoonError.new("Attempted to fetch SLN data too soon.")
65
65
  elsif page.body.to_s =~ /SLN: #{@sln} does not exist./
66
- raise("SLN does not exist.")
66
+ raise InvalidSLNError.new("SLN does not exist.")
67
67
  end
68
68
 
69
69
  page
@@ -112,4 +112,9 @@ class MyUW
112
112
  @data[:notes] = info_nodes[0].inner_text.strip
113
113
  end
114
114
  end
115
+
116
+ #
117
+ # Exceptions
118
+ class InvalidSLNError < StandardError; end
119
+ class RequestSLNTooSoonError < StandardError; end
115
120
  end
data/lib/myuw.rb CHANGED
@@ -3,6 +3,7 @@ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
3
  require 'rubygems'
4
4
  require 'mechanize'
5
5
 
6
+ require 'myuw/errors'
6
7
  require 'myuw/session'
7
8
  require 'myuw/sln'
8
9
 
data/rubyuw.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{rubyuw}
5
- s.version = "0.4.1"
5
+ s.version = "0.4.2"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Mitchell Hashimoto"]
@@ -18,6 +18,7 @@ Gem::Specification.new do |s|
18
18
  "Rakefile",
19
19
  "VERSION",
20
20
  "lib/myuw.rb",
21
+ "lib/myuw/errors.rb",
21
22
  "lib/myuw/session.rb",
22
23
  "lib/myuw/sln.rb",
23
24
  "rubyuw.gemspec",
@@ -48,7 +48,7 @@ class LiveSLNTest < Test::Unit::TestCase
48
48
 
49
49
  @sln.sln = @sln.sln # Force reload
50
50
 
51
- assert_raise RuntimeError do
51
+ assert_raise MyUW::RequestSLNTooSoonError do
52
52
  @sln.course
53
53
  end
54
54
  end
@@ -56,7 +56,7 @@ class LiveSLNTest < Test::Unit::TestCase
56
56
  should "raise an error for an invalid SLN/quarter" do
57
57
  @sln.sln = 91919 # Tested to not exist
58
58
 
59
- assert_raise RuntimeError do
59
+ assert_raise MyUW::InvalidSLNError do
60
60
  @sln.course
61
61
  end
62
62
  end
@@ -52,7 +52,7 @@
52
52
  </tr>
53
53
  </table>
54
54
  <H1>Current Section Status - Autumn Quarter 2009</H1>
55
- <B>SLN: 91919 does not exist.</B><BR><BR>
55
+ <B>SLN: 123456 does not exist.</B><BR><BR>
56
56
 
57
57
  <P></P>
58
58
  <table border='0' cellpadding='0' cellspacing='0' align='center' width='100%'>
@@ -20,7 +20,7 @@ class SessionTest < Test::Unit::TestCase
20
20
  should "raise an exception if no email/password are set" do
21
21
  @session.email = @session.password = nil
22
22
 
23
- assert_raise RuntimeError do
23
+ assert_raise ArgumentError do
24
24
  @session.login
25
25
  end
26
26
  end
@@ -28,7 +28,7 @@ class SessionTest < Test::Unit::TestCase
28
28
  should "raise an exception if the login form is not found" do
29
29
  stub_get_login_page(@myuw, "no_form_login")
30
30
 
31
- assert_raise RuntimeError do
31
+ assert_raise MyUW::InvalidPageError do
32
32
  @session.login
33
33
  end
34
34
  end
@@ -57,7 +57,7 @@ class SessionTest < Test::Unit::TestCase
57
57
  fixture_page = @browser.get(path_to_html("no_login_button"))
58
58
  @browser.expects(:get).with("http://myuw.washington.edu").once.returns(fixture_page)
59
59
 
60
- assert_raise RuntimeError do
60
+ assert_raise MyUW::InvalidPageError do
61
61
  @session.logged_in?
62
62
  end
63
63
  end
@@ -17,30 +17,47 @@ class MockedSlnTest < Test::Unit::TestCase
17
17
  assert_equal sln_obj.term, "AUT+2009"
18
18
  end
19
19
 
20
- should "raise a RuntimeError if there is no SLN set" do
20
+ should "raise a NotLoggedInError if not logged in and requesting an SLN" do
21
+ @myuw.stubs(:logged_in?).returns(false)
22
+
23
+ assert_raise MyUW::NotLoggedInError do
24
+ @sln.course
25
+ end
26
+ end
27
+
28
+ should "raise a ArgumentError if there is no SLN set" do
21
29
  @sln.sln = nil
22
30
  assert @sln.term # Sanity
23
31
 
24
- assert_raise RuntimeError do
32
+ assert_raise ArgumentError do
25
33
  @sln.course
26
34
  end
27
35
  end
28
36
 
29
- should "raise a RuntimeError if there is no term set" do
37
+ should "raise a ArgumentError if there is no term set" do
30
38
  @sln.term = nil
31
39
  assert @sln.sln
32
40
 
33
- assert_raise RuntimeError do
41
+ assert_raise ArgumentError do
34
42
  @sln.course
35
43
  end
36
44
  end
37
45
 
38
- should "raise a RuntimeError if an SLN is requested again too soon" do
46
+ should "raise a InvalidSLNError if an invalid SLN is requested" do
47
+ fixture_page = @browser.get(path_to_html("sln_does_not_exist"))
48
+ @browser.expects(:get).returns(fixture_page)
49
+
50
+ assert_raise MyUW::InvalidSLNError do
51
+ @sln.get_sln_page
52
+ end
53
+ end
54
+
55
+ should "raise a RequestSLNTooSoonError if an SLN is requested again too soon" do
39
56
  fixture_page = @browser.get(path_to_html("bad_request"))
40
57
  fixture_page.uri = "http://www.washington.edu/students/timeschd/badrequest.html"
41
58
  @browser.expects(:get).with("https://sdb.admin.washington.edu/timeschd/uwnetid/sln.asp?QTRYR=#{@sln.term}&SLN=#{@sln.sln}").returns(fixture_page)
42
59
 
43
- assert_raise RuntimeError do
60
+ assert_raise MyUW::RequestSLNTooSoonError do
44
61
  @sln.get_sln_page
45
62
  end
46
63
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mitchellh-rubyuw
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mitchell Hashimoto
@@ -36,6 +36,7 @@ files:
36
36
  - Rakefile
37
37
  - VERSION
38
38
  - lib/myuw.rb
39
+ - lib/myuw/errors.rb
39
40
  - lib/myuw/session.rb
40
41
  - lib/myuw/sln.rb
41
42
  - rubyuw.gemspec