Permalink
Browse files

add support for post requests

  • Loading branch information...
1 parent 2b144ee commit c5c7c8fd32a3ac9c35083983f586f97f96fd6af7 @jamesgolick committed May 2, 2009
Showing with 20 additions and 2 deletions.
  1. +9 −1 lib/trample/session.rb
  2. +3 −1 test/session_test.rb
  3. +8 −0 test/test_helper.rb
View
10 lib/trample/session.rb
@@ -30,8 +30,16 @@ def hit(page)
def request(page)
time do
- @last_response = RestClient.send(page.request_method, page.url, :cookies => cookies)
+ @last_response = send(page.request_method, page)
end
end
+
+ def get(page)
+ RestClient.get(page.url, :cookies => cookies)
+ end
+
+ def post(page)
+ RestClient.post(page.url, page.parameters, :cookies => cookies)
+ end
end
end
View
4 test/session_test.rb
@@ -6,6 +6,7 @@ def setup
iterations 2
get "http://google.com/"
get "http://amazon.com/"
+ post "http://google.com/"
end
@session = Trample::Session.new(@config)
end
@@ -18,6 +19,7 @@ def setup
before_should "visit the pages iterations times each" do
mock_get("http://google.com/", :times => 2)
mock_get("http://amazon.com/", :times => 2)
+ mock_post("http://google.com/", :times => 2)
end
end
@@ -32,7 +34,7 @@ def setup
end
should "record the length of time it took to visit that page" do
- assert_equal [1.4, 1.4, 1.4, 1.4], @session.response_times
+ assert_equal [1.4, 1.4, 1.4, 1.4, 1.4, 1.4], @session.response_times
end
end
View
8 test/test_helper.rb
@@ -21,5 +21,13 @@ def mock_get(url, opts={})
stub(response).cookies { opts[:return_cookies] || {} }
end
end
+
+ def mock_post(url, opts={})
+ mock(RestClient).post(url, opts[:payload],
+ :cookies => opts[:cookies] || {}).times(opts[:times]) do
+ response = RestClient::Response.new("", stub!)
+ stub(response).cookies { opts[:return_cookies] || {} }
+ end
+ end
end

0 comments on commit c5c7c8f

Please sign in to comment.