impostor 0.2.1 → 1.0.0

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.
Files changed (108) hide show
  1. data/.gemtest +0 -0
  2. data/.gitignore +1 -0
  3. data/.rspec +2 -0
  4. data/.rvmrc +1 -0
  5. data/Gemfile +17 -0
  6. data/Gemfile.lock +47 -0
  7. data/History.txt +8 -0
  8. data/Manifest.txt +87 -55
  9. data/README.txt +11 -11
  10. data/Rakefile +16 -20
  11. data/lib/impostor/auth.rb +103 -0
  12. data/lib/impostor/config.rb +171 -0
  13. data/lib/impostor/errors.rb +67 -0
  14. data/lib/impostor/phpbb2.rb +202 -0
  15. data/lib/impostor/phpbb3.rb +199 -0
  16. data/lib/impostor/post.rb +111 -0
  17. data/lib/impostor/topic.rb +115 -0
  18. data/lib/impostor/wwf79.rb +186 -0
  19. data/lib/impostor/wwf80.rb +190 -0
  20. data/lib/impostor.rb +108 -5
  21. data/spec/auth_spec.rb +148 -0
  22. data/spec/base_spec_helper.rb +12 -0
  23. data/{test/test_helper.rb → spec/caged_net_http.rb} +8 -17
  24. data/spec/config_spec.rb +136 -0
  25. data/spec/fixtures/junk.html +1 -0
  26. data/{test → spec}/fixtures/phpbb2-get-new_topic-form-good-response.html +0 -0
  27. data/{test → spec}/fixtures/phpbb2-get-viewtopic-for-new-topic-good-response.html +11 -11
  28. data/{test → spec}/fixtures/phpbb2-get-viewtopic-for-new-topic-malformed-response.html +0 -0
  29. data/{test → spec}/fixtures/phpbb2-index.html +0 -0
  30. data/{test → spec}/fixtures/phpbb2-logged-in.html +0 -0
  31. data/{test → spec}/fixtures/phpbb2-login.html +0 -0
  32. data/{test → spec}/fixtures/phpbb2-not-logged-in.html +0 -0
  33. data/{test → spec}/fixtures/phpbb2-post-new_topic-good-response.html +0 -0
  34. data/{test → spec}/fixtures/phpbb2-post-reply-good-response.html +0 -0
  35. data/{test → spec}/fixtures/phpbb2-post-reply-throttled-response.html +0 -0
  36. data/{test → spec}/fixtures/phpbb2-too-many-posts.html +0 -0
  37. data/{test → spec}/fixtures/phpbb3-get-new-topic-form-good-response.html +0 -0
  38. data/{test → spec}/fixtures/phpbb3-get-reply-form-good-response.html +0 -0
  39. data/{test → spec}/fixtures/phpbb3-logged-in.html +0 -0
  40. data/{test → spec}/fixtures/phpbb3-login.html +0 -0
  41. data/{test → spec}/fixtures/phpbb3-not-logged-in.html +0 -0
  42. data/{test → spec}/fixtures/phpbb3-post-new_topic-good-response.html +0 -0
  43. data/{test → spec}/fixtures/phpbb3-post-reply-good-response.html +0 -0
  44. data/spec/fixtures/vcr_cassettes/phpbb2-should-be-overlimit-creating-topic.yml +1308 -0
  45. data/spec/fixtures/vcr_cassettes/phpbb2-should-create-topic.yml +923 -0
  46. data/spec/fixtures/vcr_cassettes/phpbb2-should-login.yml +360 -0
  47. data/spec/fixtures/vcr_cassettes/phpbb2-should-not-create-new-topic.yml +497 -0
  48. data/spec/fixtures/vcr_cassettes/phpbb2-should-not-login.yml +287 -0
  49. data/spec/fixtures/vcr_cassettes/phpbb2-should-not-post.yml +497 -0
  50. data/spec/fixtures/vcr_cassettes/phpbb2-should-overlimit-error-post.yml +1140 -0
  51. data/spec/fixtures/vcr_cassettes/phpbb2-should-post.yml +751 -0
  52. data/spec/fixtures/vcr_cassettes/phpbb3-should-be-overlimit-creating-topic.yml +995 -0
  53. data/spec/fixtures/vcr_cassettes/phpbb3-should-create-topic.yml +675 -0
  54. data/spec/fixtures/vcr_cassettes/phpbb3-should-login.yml +245 -0
  55. data/spec/fixtures/vcr_cassettes/phpbb3-should-not-create-new-topic.yml +350 -0
  56. data/spec/fixtures/vcr_cassettes/phpbb3-should-not-login.yml +253 -0
  57. data/spec/fixtures/vcr_cassettes/phpbb3-should-not-post.yml +350 -0
  58. data/spec/fixtures/vcr_cassettes/phpbb3-should-overlimit-error-post.yml +1046 -0
  59. data/spec/fixtures/vcr_cassettes/phpbb3-should-post.yml +605 -0
  60. data/{test → spec}/fixtures/wwf79-forum_posts.html +0 -0
  61. data/{test → spec}/fixtures/wwf79-general-new-topic-error.html +0 -0
  62. data/{test → spec}/fixtures/wwf79-general-posting-error.html +0 -0
  63. data/{test → spec}/fixtures/wwf79-good-post-forum_posts.html +1 -1
  64. data/{test → spec}/fixtures/wwf79-index.html +0 -0
  65. data/{test → spec}/fixtures/wwf79-logged-in.html +0 -0
  66. data/{test → spec}/fixtures/wwf79-login.html +0 -0
  67. data/{test → spec}/fixtures/wwf79-new-topic-forum_posts-response.html +0 -0
  68. data/{test → spec}/fixtures/wwf79-new-topic-post_message_form.html +0 -0
  69. data/{test → spec}/fixtures/wwf79-not-logged-in.html +0 -0
  70. data/{test → spec}/fixtures/wwf79-too-many-posts.html +0 -0
  71. data/{test → spec}/fixtures/wwf79-too-many-topics.html +0 -0
  72. data/{test → spec}/fixtures/wwf80-general-posting-error.html +0 -0
  73. data/{test → spec}/fixtures/wwf80-get-new_topic-form-good-response.html +0 -0
  74. data/{test → spec}/fixtures/wwf80-get-viewtopic-for-new-topic-good-response.html +0 -0
  75. data/{test → spec}/fixtures/wwf80-index.html +0 -0
  76. data/{test → spec}/fixtures/wwf80-logged-in.html +0 -0
  77. data/{test → spec}/fixtures/wwf80-login.html +0 -0
  78. data/{test → spec}/fixtures/wwf80-new_reply_form.html +0 -0
  79. data/{test → spec}/fixtures/wwf80-not-logged-in.html +0 -0
  80. data/{test → spec}/fixtures/wwf80-post-new_topic-good-response.html +1 -1
  81. data/{test → spec}/fixtures/wwf80-post-reply-good-response.html +0 -0
  82. data/{test → spec}/fixtures/wwf80-too-many-posts.html +0 -0
  83. data/spec/impostor_spec_helper.rb +162 -0
  84. data/spec/integration/phpbb2_spec.rb +111 -0
  85. data/spec/integration/phpbb3_spec.rb +109 -0
  86. data/spec/integration_spec_helper.rb +7 -0
  87. data/spec/phpbb2_spec.rb +346 -0
  88. data/spec/phpbb3_spec.rb +332 -0
  89. data/spec/post_spec.rb +134 -0
  90. data/spec/spec_helper.rb +2 -0
  91. data/spec/test_impostor.rb +12 -0
  92. data/spec/topic_spec.rb +143 -0
  93. data/spec/wwf79_spec.rb +342 -0
  94. data/spec/wwf80_spec.rb +339 -0
  95. metadata +156 -87
  96. data/lib/www/impostor/phpbb2.rb +0 -258
  97. data/lib/www/impostor/phpbb3.rb +0 -236
  98. data/lib/www/impostor/wwf79.rb +0 -254
  99. data/lib/www/impostor/wwf80.rb +0 -264
  100. data/lib/www/impostor.rb +0 -269
  101. data/test/test_github.rb +0 -12
  102. data/test/test_www_impostor.rb +0 -165
  103. data/test/test_www_impostor_phpbb2.rb +0 -536
  104. data/test/test_www_impostor_phpbb3.rb +0 -483
  105. data/test/test_www_impostor_wwf79.rb +0 -535
  106. data/test/test_www_impostor_wwf80.rb +0 -535
  107. data/vendor/plugins/impostor/lib/autotest/discover.rb +0 -3
  108. data/vendor/plugins/impostor/lib/autotest/impostor.rb +0 -49
data/spec/post_spec.rb ADDED
@@ -0,0 +1,134 @@
1
+ require File.join(File.dirname(__FILE__), 'spec_helper')
2
+
3
+ describe "impostor's post routines" do
4
+
5
+ describe "the no-op test impostor post without implemented template methods" do
6
+
7
+ it "should post via composed template methods" do
8
+
9
+ config = self.config
10
+ auth = self.auth
11
+ post = self.post(config, auth)
12
+
13
+ reply_uri = mock "reply_uri"
14
+ reply_page = mock "reply page"
15
+ reply_form = mock "reply form"
16
+ result_page = mock "result page"
17
+
18
+ auth.should_receive(:login_with_raises).once.and_return(true)
19
+ post.should_receive(:get_reply_uri).with(1,2).once.and_return(reply_uri)
20
+ post.should_receive(:get_reply_page).with(reply_uri).once.and_return(reply_page)
21
+ post.should_receive(:get_post_form).with(reply_page).once.and_return(reply_form)
22
+ post.should_receive(:set_message).with(reply_form, "Hello World").once
23
+ post.should_receive(:post_message).with(reply_form).once.and_return(result_page)
24
+ post.should_receive(:get_post_from_result).with(result_page).once.and_return(3)
25
+
26
+ lambda {
27
+ post.post(formum=1, topic=2, message="Hello World").should == {
28
+ :forum => 1,
29
+ :topic => 2,
30
+ :post => 3,
31
+ :message => "Hello World",
32
+ :result => true
33
+ }
34
+ }.should_not raise_error
35
+
36
+ end
37
+
38
+ it "should have logged in error when posting and not logged in" do
39
+
40
+ config = self.config
41
+ auth = self.auth
42
+ post = self.post(config, auth)
43
+
44
+ auth.should_receive(:login_with_raises).and_raise(Impostor::LoginError)
45
+
46
+ lambda {
47
+ post.post(formum=1, topic=2, message="Hello World")
48
+ }.should raise_error( Impostor::LoginError )
49
+ end
50
+
51
+ end
52
+
53
+ describe "the base post template methods" do
54
+
55
+ it "should have post error when forum is missing in #validate_post_input" do
56
+ lambda { post.validate_post_input(nil, 2, "Hello World") }.should raise_error(
57
+ Impostor::PostError,
58
+ "Impostor error: forum not set (StandardError)"
59
+ )
60
+ end
61
+
62
+ it "should have post error when topic is missing in #validate_post_input" do
63
+ lambda { post.validate_post_input(1, nil, "Hello World") }.should raise_error(
64
+ Impostor::PostError,
65
+ "Impostor error: topic not set (StandardError)"
66
+ )
67
+ end
68
+
69
+ it "should have post error when message is missing in #validate_post_input" do
70
+ lambda { post.validate_post_input(1, 2, nil) }.should raise_error(
71
+ Impostor::PostError,
72
+ "Impostor error: message not set (StandardError)"
73
+ )
74
+ end
75
+
76
+ it "should raise not implemented error when get_reply_uri called" do
77
+ lambda { post.get_reply_uri(nil, nil) }.should raise_error(
78
+ Impostor::MissingTemplateMethodError,
79
+ "Impostor error: get_reply_uri must be implemented (StandardError)"
80
+ )
81
+ end
82
+
83
+ it "should get_reply_page" do
84
+ post = self.post
85
+ uri = mock "uri"
86
+ post.config.agent.should_receive(:get).with(uri)
87
+ lambda {
88
+ post.get_reply_page(uri)
89
+ }.should_not raise_error
90
+ end
91
+
92
+ it "should raise not implemented error when get_post_form called" do
93
+ lambda { post.get_post_form(nil) }.should raise_error(
94
+ Impostor::MissingTemplateMethodError,
95
+ "Impostor error: get_post_form must be implemented (StandardError)"
96
+ )
97
+ end
98
+
99
+ it "should raise not implemented error when set_message called" do
100
+ form = mock "form"
101
+ form.should_receive(:message=).with("Hello World")
102
+ lambda {
103
+ post.set_message(form, "Hello World").should == form
104
+ }.should_not raise_error
105
+ end
106
+
107
+ it "should post_message" do
108
+ post = self.post
109
+ form = mock "post form"
110
+ form.should_receive(:submit)
111
+ lambda {
112
+ post.post_message(form)
113
+ }.should_not raise_error
114
+ end
115
+
116
+ it "should bubble up post errors when underlying errors occur in post_message" do
117
+ post = self.post
118
+ form = mock "post form"
119
+ form.should_receive(:submit).and_raise( Impostor::PostError )
120
+ lambda {
121
+ post.post_message(form)
122
+ }.should raise_error( Impostor::PostError )
123
+ end
124
+
125
+ it "should raise not implemented error when get_post_from_result called" do
126
+ lambda { post.get_post_from_result(nil) }.should raise_error(
127
+ Impostor::MissingTemplateMethodError,
128
+ "Impostor error: get_post_from_result must be implemented (StandardError)"
129
+ )
130
+ end
131
+
132
+ end
133
+
134
+ end
@@ -0,0 +1,2 @@
1
+ require File.join(File.dirname(__FILE__), 'base_spec_helper')
2
+ require 'caged_net_http'
@@ -0,0 +1,12 @@
1
+ module Impostor::Test
2
+
3
+ module Auth
4
+ end
5
+
6
+ module Post
7
+ end
8
+
9
+ module Topic
10
+ end
11
+
12
+ end
@@ -0,0 +1,143 @@
1
+ require File.join(File.dirname(__FILE__), 'spec_helper')
2
+
3
+ describe "impostor's topic routines" do
4
+
5
+ describe "the no-op test impostor topic without implemented template methods" do
6
+
7
+ it "should create new_topic via composed template methods" do
8
+
9
+ config = self.config
10
+ auth = self.auth
11
+ topic = self.topic(config, auth)
12
+
13
+ new_topic_uri = mock "new topic uri"
14
+ new_topic_page = mock "new topic page"
15
+ new_topic_form = mock "new topic form"
16
+ new_topic_result = mock "new topic result page"
17
+
18
+ auth.should_receive(:login_with_raises).once.and_return(true)
19
+ topic.should_receive(:get_new_topic_uri).with(1, "OMG!", "Hello World").and_return(new_topic_uri)
20
+
21
+ topic.should_receive(:get_new_topic_page).with(new_topic_uri).and_return(new_topic_page)
22
+ topic.should_receive(:get_new_topic_form).with(new_topic_page).and_return(new_topic_form)
23
+ topic.should_receive(:set_subject_and_message).with(new_topic_form, "OMG!", "Hello World")
24
+ topic.should_receive(:post_new_topic).with(new_topic_form).and_return(new_topic_result)
25
+ topic.should_receive(:validate_new_topic_result).with(new_topic_result).and_return(new_topic_result)
26
+ topic.should_receive(:get_topic_from_result).with(new_topic_result).and_return(2)
27
+ config.should_receive(:add_subject).with(1, 2, "OMG!")
28
+
29
+ lambda {
30
+ topic.new_topic(formum=1, subject="OMG!", message="Hello World").should == {
31
+ :forum => 1,
32
+ :topic => 2,
33
+ :subject => "OMG!",
34
+ :message => "Hello World",
35
+ :result => true
36
+ }
37
+ }.should_not raise_error
38
+
39
+ end
40
+
41
+ it "should have logged in error when creating a new topic and not logged in" do
42
+
43
+ config = self.config
44
+ auth = self.auth
45
+ topic = self.topic(config, auth)
46
+
47
+ auth.should_receive(:login_with_raises).and_raise(Impostor::LoginError)
48
+
49
+ lambda {
50
+ topic.new_topic(formum=1, subject="OMG!", message="Hello World")
51
+ }.should raise_error( Impostor::LoginError )
52
+ end
53
+
54
+ end
55
+
56
+ describe "the base topic template methods" do
57
+
58
+ it "should have topic error when forum is missing in #validate_topic_input" do
59
+ lambda { topic.validate_topic_input(nil, subject="OMG!", message="Hello World") }.should raise_error(
60
+ Impostor::TopicError,
61
+ "Impostor error: forum not set (StandardError)"
62
+ )
63
+ end
64
+
65
+ it "should have topic error when subject is missing in #validate_topic_input" do
66
+ lambda { topic.validate_topic_input(forum=1, nil, message="Hello World") }.should raise_error(
67
+ Impostor::TopicError,
68
+ "Impostor error: subject not set (StandardError)"
69
+ )
70
+ end
71
+
72
+ it "should have topic error when message is missing in #validate_topic_input" do
73
+ lambda { topic.validate_topic_input(forum=1, subject="OMG!", nil) }.should raise_error(
74
+ Impostor::TopicError,
75
+ "Impostor error: message not set (StandardError)"
76
+ )
77
+ end
78
+
79
+ it "should raise not implemented error when get_new_topic_uri called" do
80
+ lambda { topic.get_new_topic_uri(nil, nil, nil) }.should raise_error(
81
+ Impostor::MissingTemplateMethodError,
82
+ "Impostor error: get_new_topic_uri must be implemented (StandardError)"
83
+ )
84
+ end
85
+
86
+ it "should raise not implemented error when get_new_topic_page called" do
87
+ topic = self.topic
88
+ uri = mock "uri"
89
+ topic.config.agent.should_receive(:get).with(uri)
90
+ lambda {
91
+ topic.get_new_topic_page(uri)
92
+ }.should_not raise_error
93
+ end
94
+
95
+ it "should raise not implemented error when get_new_topic_form called" do
96
+ lambda { topic.get_new_topic_form(nil) }.should raise_error(
97
+ Impostor::MissingTemplateMethodError,
98
+ "Impostor error: get_new_topic_form must be implemented (StandardError)"
99
+ )
100
+ end
101
+
102
+ it "should raise not implemented error when set_subject_and_message called" do
103
+ lambda { topic.set_subject_and_message(nil, nil, nil) }.should raise_error(
104
+ Impostor::MissingTemplateMethodError,
105
+ "Impostor error: set_subject_and_message must be implemented (StandardError)"
106
+ )
107
+ end
108
+
109
+ it "should post_new_topic" do
110
+ topic = self.topic
111
+ form = mock "topic form"
112
+ form.should_receive(:submit)
113
+ lambda {
114
+ topic.post_new_topic(form)
115
+ }.should_not raise_error
116
+ end
117
+
118
+ it "should bubble topic errors when underlying errors occur in post_new_topic" do
119
+ topic = self.topic
120
+ form = mock "topic form"
121
+ form.should_receive(:submit).and_raise( StandardError )
122
+ lambda {
123
+ topic.post_new_topic(form)
124
+ }.should raise_error( Impostor::TopicError )
125
+ end
126
+
127
+ it "should raise not implemented error when validate_new_topic_result called" do
128
+ lambda { topic.validate_new_topic_result(nil) }.should raise_error(
129
+ Impostor::MissingTemplateMethodError,
130
+ "Impostor error: validate_new_topic_result must be implemented (StandardError)"
131
+ )
132
+ end
133
+
134
+ it "should raise not implemented error when get_topic_from_result called" do
135
+ lambda { topic.get_topic_from_result(nil) }.should raise_error(
136
+ Impostor::MissingTemplateMethodError,
137
+ "Impostor error: get_topic_from_result must be implemented (StandardError)"
138
+ )
139
+ end
140
+
141
+ end
142
+
143
+ end
@@ -0,0 +1,342 @@
1
+ require File.join(File.dirname(__FILE__), 'spec_helper')
2
+
3
+ describe "a Web Wiz Forum 7.9 impostor" do
4
+
5
+ describe "authentication routines" do
6
+
7
+ before do
8
+ @auth = wwf79_auth
9
+
10
+ @login_uri = URI.parse("http://example.com/forum/login_user.asp")
11
+
12
+ @login_page = load_fixture_page(
13
+ "wwf79-login.html",
14
+ @auth.config.login_page, 200, @auth.config.agent
15
+ )
16
+
17
+ @logged_in_page = load_fixture_page(
18
+ "wwf79-logged-in.html",
19
+ @auth.config.app_root, 200, @auth.config.agent
20
+ )
21
+
22
+ @not_logged_in_page = load_fixture_page(
23
+ "wwf79-not-logged-in.html",
24
+ @auth.config.app_root, 200, @auth.config.agent
25
+ )
26
+
27
+ @junk_page = load_fixture_page(
28
+ "junk.html", @auth.config.login_page, 200, @auth.config.agent
29
+ )
30
+ end
31
+
32
+ it "should logout only if not logged in" do
33
+ @auth.should_receive(:authenticated?).once.and_return(false)
34
+ @auth.logout.should_not be_true
35
+ end
36
+
37
+ it "should logout" do
38
+ @auth.config.should_receive(:save_topics).once
39
+ @auth.config.should_receive(:save_cookie_jar).once
40
+ @auth.instance_variable_set("@authenticated", true)
41
+
42
+ @auth.logout.should be_true
43
+ @auth.authenticated?.should_not be_true
44
+ end
45
+
46
+ it "should be logged_in? when wwf 7.9 displays the user name" do
47
+ lambda {
48
+ @auth.logged_in?(@logged_in_page).should be_true
49
+ }.should_not raise_error
50
+ end
51
+
52
+ it "should not be logged_in? when wwf 7.9 does not display the user name" do
53
+ lambda {
54
+ @auth.logged_in?(@not_logged_in_page).should_not be_true
55
+ }.should_not raise_error
56
+ end
57
+
58
+ it "should return a page from fetch_login_page" do
59
+ @auth.config.agent.should_receive(:get).with(@login_uri)
60
+
61
+ lambda {
62
+ @auth.fetch_login_page
63
+ }.should_not raise_error
64
+ end
65
+
66
+ it "should handle an error in fetch_login_page" do
67
+ @auth.config.agent.should_receive(:get).with(@login_uri).and_raise(StandardError)
68
+
69
+ lambda {
70
+ @auth.fetch_login_page
71
+ }.should raise_error( Impostor::LoginError )
72
+ end
73
+
74
+ it "should return a login form from get_login_form" do
75
+ lambda {
76
+ @auth.get_login_form(@login_page).name.should == 'frmLogin'
77
+ }.should_not raise_error
78
+ end
79
+
80
+ it "should raise login error when get_login_form receives a bad page" do
81
+ lambda {
82
+ @auth.get_login_form(@junk_page)
83
+ }.should raise_error( Impostor::LoginError )
84
+ end
85
+
86
+ it "should setup login form in set_username_and_password" do
87
+ form = mock "login form"
88
+ button = mock "submit button"
89
+ Mechanize::Form::Button.should_receive(:new).and_return(button)
90
+ form.should_receive(:[]=).with("name", "tester")
91
+ form.should_receive(:[]=).with("password", "password")
92
+ form.should_receive(:add_button_to_query).with(button)
93
+ lambda {
94
+ @auth.set_username_and_password(form).should == form
95
+ }.should_not raise_error
96
+ end
97
+
98
+ it "should return a logged in page when posting the login" do
99
+ form = @auth.get_login_form(@login_page)
100
+ @auth.config.agent.should_receive(:submit).with(instance_of(Mechanize::Form), nil, {}).and_return(@logged_in_page)
101
+ lambda {
102
+ @auth.post_login(form).should == @logged_in_page
103
+ }.should_not raise_error
104
+ end
105
+
106
+ it "should raise a login error when posting has an underlying exception" do
107
+ form = @login_page.form('frmLogin')
108
+ @auth.config.agent.should_receive(:submit).with(instance_of(Mechanize::Form), nil, {}).and_raise(StandardError)
109
+ lambda {
110
+ @auth.post_login(form)
111
+ }.should raise_error( Impostor::LoginError )
112
+ end
113
+
114
+ it "should login" do
115
+ @auth.config.agent.should_receive(:get).with(@login_uri).and_return(@login_page)
116
+ @auth.config.agent.should_receive(:submit).with(instance_of(Mechanize::Form), nil, {}).and_return(@logged_in_page)
117
+
118
+ lambda {
119
+ @auth.login.should be_true
120
+ }.should_not raise_error
121
+ end
122
+ end
123
+
124
+ describe "posting routines" do
125
+
126
+ before do
127
+ @post = wwf79_post
128
+
129
+ @reply_uri = URI.parse("http://example.com/forum/forum_posts.asp?TID=2&TPN=10000")
130
+ @reply_response_page = load_fixture_page(
131
+ "wwf79-forum_posts.html",
132
+ @reply_uri, 200, @post.config.agent
133
+ )
134
+
135
+ @good_post_page = load_fixture_page(
136
+ "wwf79-good-post-forum_posts.html",
137
+ @post.config.app_root, 200, @post.config.agent
138
+ )
139
+
140
+ @posting_error_page = load_fixture_page(
141
+ "wwf79-general-posting-error.html",
142
+ @post.config.app_root, 200, @post.config.agent
143
+ )
144
+
145
+ @junk_page = load_fixture_page(
146
+ "junk.html", @post.config.login_page, 200, @post.config.agent
147
+ )
148
+ end
149
+
150
+ it "should post a message in the topic of a forum" do
151
+ @post.auth.should_receive(:login_with_raises)
152
+ @post.config.agent.should_receive(:get).with(@reply_uri).and_return(@reply_response_page)
153
+ @post.config.agent.should_receive(:submit).with(instance_of(Mechanize::Form), nil, {}).and_return(@good_post_page)
154
+
155
+ lambda {
156
+ @post.post(formum=1, topic=2, message="Hello World").should == {
157
+ :forum => 1,
158
+ :topic => 2,
159
+ :post => 1203,
160
+ :message => "Hello World",
161
+ :result => true
162
+ }
163
+ }.should_not raise_error
164
+ end
165
+
166
+ it "should get a reply uri from get_reply_uri(forum, topic)" do
167
+ lambda {
168
+ @post.get_reply_uri(1,2).should == @reply_uri
169
+ }.should_not raise_error
170
+ end
171
+
172
+ it "should get_reply_page(uri)" do
173
+ @post.config.agent.should_receive(:get).with(@reply_uri).and_return(@reply_response_page)
174
+ lambda {
175
+ @post.get_reply_page(@reply_uri).should == @reply_response_page
176
+ }.should_not raise_error
177
+ end
178
+
179
+ it "should return reply from with get_post_form(page)" do
180
+ lambda {
181
+ @post.get_post_form(@reply_response_page).name.should == 'frmAddMessage'
182
+ }.should_not raise_error
183
+ end
184
+
185
+ it "should raise error when page to get_post_form(page) receives a bad page" do
186
+ lambda {
187
+ @post.get_post_form(@junk_page)
188
+ }.should raise_error( Impostor::PostError )
189
+ end
190
+
191
+ it "should set_message(form, message)" do
192
+ form = @post.get_post_form(@reply_response_page)
193
+ form.should_receive(:message=, "Hello World")
194
+ lambda {
195
+ @post.set_message(form, "Hello World")
196
+ }.should_not raise_error
197
+ end
198
+
199
+ it "should return response page from post_message(form)" do
200
+ form = mock "post form"
201
+ form.should_receive(:submit).and_return @good_post_page
202
+ lambda {
203
+ @post.post_message(form).should == @good_post_page
204
+ }.should_not raise_error
205
+ end
206
+
207
+ it "should raise post error when post_form fails" do
208
+ form = mock "post form"
209
+ form.should_receive(:submit).and_raise( Impostor::PostError )
210
+ lambda {
211
+ @post.post_message(form)
212
+ }.should raise_error( Impostor::PostError )
213
+ end
214
+
215
+ it "should not raise post error on valid reply get_post_from_result(page)" do
216
+ lambda {
217
+ @post.get_post_from_result(@good_post_page).should be_true
218
+ }.should_not raise_error
219
+ end
220
+
221
+ it "should raise post error on invalid reply get_post_from_result(page)" do
222
+ lambda {
223
+ @post.get_post_from_result(@posting_error_page)
224
+ }.should raise_error( Impostor::PostError )
225
+ end
226
+
227
+ end
228
+
229
+ describe "topic routines" do
230
+
231
+ before do
232
+ @topic = wwf79_topic
233
+
234
+ @new_topic_uri = URI.parse("http://example.com/forum/post_message_form.asp?FID=1")
235
+
236
+ @new_topic_page = load_fixture_page(
237
+ "wwf79-new-topic-post_message_form.html",
238
+ @new_topic_uri, 200, @topic.config.agent
239
+ )
240
+
241
+ @new_topic_result = load_fixture_page(
242
+ "wwf79-good-post-forum_posts.html",
243
+ @new_topic_uri, 200, @topic.config.agent
244
+ )
245
+
246
+ @posting_error_page = load_fixture_page(
247
+ "wwf79-general-posting-error.html",
248
+ @topic.config.app_root, 200, @topic.config.agent
249
+ )
250
+ end
251
+
252
+ it "should return new topic uri when get_new_topic_uri called" do
253
+ lambda {
254
+ @topic.get_new_topic_uri(1, "OMG!", "Hello World").should == @new_topic_uri
255
+ }.should_not raise_error
256
+ end
257
+
258
+ it "should return new topic page when get_new_topic_page called" do
259
+ @topic.config.agent.should_receive(:get).with(@new_topic_uri).and_return(@new_topic_page)
260
+
261
+ lambda {
262
+ new_topic_uri = @topic.get_new_topic_uri(1, "OMG!", "Hello World")
263
+ @topic.get_new_topic_page(new_topic_uri)
264
+ }.should_not raise_error
265
+ end
266
+
267
+ it "should return new topic form when get_new_topic_form called" do
268
+ lambda {
269
+ @topic.get_new_topic_form(@new_topic_page).name.should == 'frmAddMessage'
270
+ }.should_not raise_error
271
+ end
272
+
273
+ it "should raise topic error when get_new_topic_form has error" do
274
+ @new_topic_page.should_receive(:form).with("frmAddMessage").and_return nil
275
+ lambda {
276
+ @topic.get_new_topic_form(@new_topic_page)
277
+ }.should raise_error( Impostor::TopicError )
278
+ end
279
+
280
+ it "should set subject and message on a form when set_subject_and_message called" do
281
+ form = mock "wwf79 topic form"
282
+ form.should_receive(:subject=).with("OMG!")
283
+ form.should_receive(:message=).with("Hello World")
284
+ lambda {
285
+ @topic.set_subject_and_message(form, "OMG!", "Hello World")
286
+ }.should_not raise_error
287
+ end
288
+
289
+ it "should post new topic with form when post_new_topic called" do
290
+ @topic.config.agent.should_receive(:submit).with(instance_of(Mechanize::Form), nil, {}).and_return(@new_topic_result)
291
+ new_topic_form = @topic.get_new_topic_form(@new_topic_page)
292
+ lambda {
293
+ @topic.post_new_topic(new_topic_form)
294
+ }.should_not raise_error
295
+ end
296
+
297
+ it "should raise topic error when posting_new_topic has an error" do
298
+ form = mock "a wwf79 form"
299
+ form.should_receive(:submit).and_raise(StandardError)
300
+ lambda {
301
+ @topic.post_new_topic(form)
302
+ }.should raise_error( Impostor::TopicError )
303
+ end
304
+
305
+ it "should not raise topic error on valid reply validate_new_topic_result(page)" do
306
+ lambda {
307
+ @topic.validate_new_topic_result(@new_topic_result).should be_true
308
+ }.should_not raise_error
309
+ end
310
+
311
+ it "should raise topic error on invalid reply validate_new_topic_result(page)" do
312
+ lambda {
313
+ @topic.validate_new_topic_result(@posting_error_page)
314
+ }.should raise_error( Impostor::TopicError )
315
+ end
316
+
317
+ it "should return the created topic id from get_topic_from_result" do
318
+ #lambda {
319
+ @topic.get_topic_from_result(@new_topic_result).should == 2
320
+ #}.should_not raise_error
321
+ end
322
+
323
+ it "should create new topic" do
324
+
325
+ @topic.auth.should_receive(:login_with_raises)
326
+ @topic.config.agent.should_receive(:get).with(@new_topic_uri).and_return(@new_topic_page)
327
+ @topic.config.agent.should_receive(:submit).with(instance_of(Mechanize::Form), nil, {}).and_return(@new_topic_result)
328
+ @topic.config.should_receive(:add_subject).with(1, 2, "OMG!")
329
+
330
+ lambda {
331
+ @topic.new_topic(formum=1, subject="OMG!", message="Hello World").should == {
332
+ :forum => 1,
333
+ :topic => 2,
334
+ :subject => "OMG!",
335
+ :message => "Hello World",
336
+ :result => true
337
+ }
338
+ }.should_not raise_error
339
+ end
340
+ end
341
+
342
+ end