Permalink
Browse files

Added support for sending post requests through httparty

  • Loading branch information...
1 parent 4d93dba commit 8566a6e3a9f1783a343b91032bf2ee004fa890e4 @gus gus committed Jul 9, 2010
Showing with 68 additions and 18 deletions.
  1. +5 −0 lib/riot/gear/context/http.rb
  2. +14 −18 test/actions/get_test.rb
  3. +48 −0 test/actions/post_test.rb
  4. +1 −0 test/teststrap.rb
@@ -10,6 +10,11 @@ def get(*args)
hookup { @smoke_response = topic.get(*args) }
end
+ # Setup the scenario via a POST requst to the provided path. Feel free to include a :body option
+ def post(*args)
+ hookup { @smoke_response = topic.post(*args) }
+ end
+
def persist_cookie(cookie_name)
hookup do
if cookie_value = cookie_values[cookie_name]
@@ -20,28 +20,24 @@
asserts("response body") { response.body }.equals("Foo")
end # without params
- context "with default params" do
- hookup do
- stub_request(:get, 'http://test.local/foo?bar=baz').to_return(:body => "", :status => 201)
- end
+ context "with params" do
+ hookup { stub_request(:get, 'http://test.local/foo?bar=baz').to_return(:body => "", :status => 201) }
- base_uri "http://test.local"
- default_params({"bar" => "baz"})
- get "/foo"
+ context "through default_params" do
+ base_uri "http://test.local"
+ default_params({"bar" => "baz"})
+ get "/foo"
- asserts("status code") { response.code }.equals(201)
- end # with default params
+ asserts("status code") { response.code }.equals(201)
+ end # through default_params
- context "with inline params" do
- hookup do
- stub_request(:get, 'http://test.local/foo?bar=baz').to_return(:body => "", :status => 201)
- end
-
- base_uri "http://test.local"
- get "/foo?bar=baz"
+ context "through query string" do
+ base_uri "http://test.local"
+ get "/foo?bar=baz"
- asserts("status code") { response.code }.equals(201)
- end # with inline params
+ asserts("status code") { response.code }.equals(201)
+ end # through query string
+ end # with params
end # with a base-uri
end # Sending a GET request
@@ -0,0 +1,48 @@
+require 'teststrap'
+
+context "Sending a POST request" do
+ teardown { reset_webmock }
+
+ asserts("not defining a base_uri") do
+ Riot::Context.new("foo") { post "/foo" }.run(Riot::SilentReporter.new)
+ end.raises(HTTParty::UnsupportedURIScheme)
+
+ context "with a base-uri" do
+ context "without params" do
+ hookup do
+ stub_request(:post, 'http://test.local/foo').with(:body => {"foo" => "bar"}.to_json).
+ to_return(:body => "Foo", :status => 200)
+ end
+
+ base_uri "http://test.local"
+ post "/foo", :body => {"foo" => "bar"}.to_json
+
+ asserts("status code") { response.code }.equals(200)
+ asserts("response body") { response.body }.equals("Foo")
+ end # without params
+
+ context "with params" do
+ hookup do
+ stub_request(:post, 'http://test.local/foo?bar=baz').
+ with(:body => {"goo" => "car"}.to_json).
+ to_return(:body => "", :status => 201)
+ end
+
+ context "through default_params" do
+ base_uri "http://test.local"
+ default_params({"bar" => "baz"})
+ post "/foo", :body => {"goo" => "car"}.to_json
+
+ asserts("status code") { response.code }.equals(201)
+ end # through default_params
+
+ context "through query string" do
+ base_uri "http://test.local"
+ post "/foo?bar=baz", :body => {"goo" => "car"}.to_json
+
+ asserts("status code") { response.code }.equals(201)
+ end # through query string
+ end # with params
+ end # with a base-uri
+
+end # Sending a GET request
View
@@ -3,6 +3,7 @@
$:.unshift((Pathname(__FILE__).dirname + ".." + "lib").to_s)
require 'rubygems'
+require 'json'
require 'riot'
require 'webmock'
Riot::Situation.instance_eval { include WebMock }

0 comments on commit 8566a6e

Please sign in to comment.