Skip to content

Commit

Permalink
support procs for params
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesgolick committed May 1, 2009
1 parent 711f099 commit b8cb9c5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/trample/configuration.rb
Expand Up @@ -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)
Expand Down
10 changes: 9 additions & 1 deletion test/configuration_test.rb
Expand Up @@ -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

Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit b8cb9c5

Please sign in to comment.