Permalink
Browse files

support procs for params

  • Loading branch information...
1 parent 711f099 commit b8cb9c51014d79afcb7a70b0a9398bba19c00259 @jamesgolick committed May 1, 2009
Showing with 11 additions and 3 deletions.
  1. +2 −2 lib/trample/configuration.rb
  2. +9 −1 test/configuration_test.rb
@@ -21,8 +21,8 @@ def get(url)
@pages << Page.new(:get, url)
end
- def post(url, params)
- @pages << Page.new(:post, url, params)
+ def post(url, params = nil, &block)
+ @pages << Page.new(:post, url, params || block)
end
def ==(other)
View
@@ -3,11 +3,13 @@
class ConfigurationTest < Test::Unit::TestCase
context "Configuring trample" do
setup do
+ @params_proc = lambda { { :q => "the meaning of life" } }
@config = Trample::Configuration.new do
concurrency 2
iterations 1
get "http://google.com/"
post "http://google.com/", {:q => "something"}
+ post "http://google.com/", &@params_proc
end
end
@@ -25,7 +27,12 @@ class ConfigurationTest < Test::Unit::TestCase
should "add post requests to the array of pages, including their params" do
expected = Trample::Page.new(:post, "http://google.com/", {:q => "something"})
- assert_equal expected, @config.pages.last
+ assert_equal expected, @config.pages[1]
+ end
+
+ should "add post requests to the array of pages, including their block-based params" do
+ expected = Trample::Page.new(:post, "http://google.com/", @params_proc)
+ assert_equal expected, @config.pages[2]
end
should "be equal if all the objects are the same" do
@@ -34,6 +41,7 @@ class ConfigurationTest < Test::Unit::TestCase
iterations 1
get "http://google.com/"
post "http://google.com/", {:q => "something"}
+ post "http://google.com/", &@params_proc
end
assert_equal identical_config, @config
end

0 comments on commit b8cb9c5

Please sign in to comment.