Permalink
Browse files

add support for login

  • Loading branch information...
1 parent c5c7c8f commit 84428dc70c9fc37d0b910de652cb72de93303878 @jamesgolick committed May 2, 2009
Showing with 28 additions and 0 deletions.
  1. +2 −0 lib/trample/session.rb
  2. +19 −0 test/session_test.rb
  3. +7 −0 test/test_helper.rb
View
@@ -12,6 +12,8 @@ def initialize(config)
end
def trample
+ puts @config.login.inspect
+ hit @config.login unless @config.login.nil?
@config.iterations.times do
@config.pages.each do |p|
hit p
View
@@ -56,5 +56,24 @@ def setup
assert_received(RestClient) { |c| c.get("http://amazon.com/", :cookies => {"xyz" => "abc"}) }
end
end
+
+ context "A session with login" do
+ # TODO: the order of the requests isn't being tested here. not
+ # sure if it's possible with rr
+ should "hit the login once at the beginning of the session" do
+ @config = Trample::Configuration.new do
+ iterations 2
+ login do
+ post "http://google.com/login" do
+ {:user => "xyz", :password => "swordfish"}
+ end
+ end
+ get "http://google.com/"
+ end
+ stub_get(anything, :times => 2)
+ mock_post("http://google.com/login", :payload => {:user => "xyz", :password => "swordfish"}, :times => 1)
+ Trample::Session.new(@config).trample
+ end
+ end
end
View
@@ -29,5 +29,12 @@ def mock_post(url, opts={})
stub(response).cookies { opts[:return_cookies] || {} }
end
end
+
+ def stub_get(url, opts = {})
+ stub(RestClient).get(url, :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 84428dc

Please sign in to comment.