Skip to content

Commit

Permalink
Improved naming of acceptance specs and shared examples groups.
Browse files Browse the repository at this point in the history
  • Loading branch information
bblimke committed Aug 28, 2011
1 parent 850c8f7 commit ce42508
Show file tree
Hide file tree
Showing 14 changed files with 1,003 additions and 1,004 deletions.
12 changes: 6 additions & 6 deletions spec/acceptance/curb/curb_spec.rb
Expand Up @@ -7,11 +7,11 @@
shared_examples_for "Curb" do
include CurbSpecHelper

it_should_behave_like "WebMock"
include_examples "with WebMock"

describe "when doing PUTs" do
it "should stub them" do
stub_http_request(:put, "www.example.com").with(:body => "01234")
stub_request(:put, "www.example.com").with(:body => "01234")
http_request(:put, "http://www.example.com", :body => "01234").
status.should == "200"
end
Expand Down Expand Up @@ -273,7 +273,7 @@
include CurbSpecHelper::NamedHttp

it "should work with blank arguments for post" do
stub_http_request(:post, "www.example.com").with(:body => "01234")
stub_request(:post, "www.example.com").with(:body => "01234")
c = Curl::Easy.new
c.url = "http://www.example.com"
c.post_body = "01234"
Expand All @@ -282,13 +282,13 @@
end

it "should work with several body arguments for post using the class method" do
stub_http_request(:post, "www.example.com").with(:user => {:first_name=>'Bartosz', :last_name=>'Blimke'})
stub_request(:post, "www.example.com").with(:user => {:first_name=>'Bartosz', :last_name=>'Blimke'})
c = Curl::Easy.http_post "http://www.example.com", 'user[first_name]=Bartosz', 'user[last_name]=Blimke'
c.response_code.should == 200
end

it "should work with blank arguments for put" do
stub_http_request(:put, "www.example.com").with(:body => "01234")
stub_request(:put, "www.example.com").with(:body => "01234")
c = Curl::Easy.new
c.url = "http://www.example.com"
c.put_data = "01234"
Expand All @@ -299,7 +299,7 @@
it "should work with multiple arguments for post" do
data = { :name => "john", :address => "111 example ave" }

stub_http_request(:post, "www.example.com").with(:body => data)
stub_request(:post, "www.example.com").with(:body => data)
c = Curl::Easy.new
c.url = "http://www.example.com"
c.http_post Curl::PostField.content('name', data[:name]), Curl::PostField.content('address', data[:address])
Expand Down
20 changes: 10 additions & 10 deletions spec/acceptance/em_http_request/em_http_request_spec.rb
Expand Up @@ -5,17 +5,17 @@
unless RUBY_PLATFORM =~ /java/
require 'acceptance/em_http_request/em_http_request_spec_helper'

describe "Webmock with EM::HttpRequest" do
describe "EM::HttpRequest" do
include EMHttpRequestSpecHelper

it_should_behave_like "WebMock"
include_examples "with WebMock"

#functionality only supported for em-http-request 1.x
if defined?(EventMachine::HttpConnection)
describe "with middleware" do

it "should work with request middleware" do
stub_http_request(:get, "www.example.com").with(:body => 'bar')
stub_request(:get, "www.example.com").with(:body => 'bar')

middleware = Class.new do
def request(client, head, body)
Expand All @@ -38,7 +38,7 @@ def request(client, head, body)
end

it "should work with response middleware" do
stub_http_request(:get, "www.example.com").to_return(:body => 'foo')
stub_request(:get, "www.example.com").to_return(:body => 'foo')

middleware = Class.new do
def response(resp)
Expand Down Expand Up @@ -102,7 +102,7 @@ def response(resp)
end

it "should work with streaming" do
stub_http_request(:get, "www.example.com").to_return(:body => "abc")
stub_request(:get, "www.example.com").to_return(:body => "abc")
response = ""
EM.run {
http = EventMachine::HttpRequest.new('http://www.example.com/').get
Expand All @@ -112,28 +112,28 @@ def response(resp)
end

it "should work with responses that use chunked transfer encoding" do
stub_http_request(:get, "www.example.com").to_return(:body => "abc", :headers => { 'Transfer-Encoding' => 'chunked' })
stub_request(:get, "www.example.com").to_return(:body => "abc", :headers => { 'Transfer-Encoding' => 'chunked' })
http_request(:get, "http://www.example.com").body.should == "abc"
end

it "should work with optional query params" do
stub_http_request(:get, "www.example.com/?x=3&a[]=b&a[]=c").to_return(:body => "abc")
stub_request(:get, "www.example.com/?x=3&a[]=b&a[]=c").to_return(:body => "abc")
http_request(:get, "http://www.example.com/?x=3", :query => {"a" => ["b", "c"]}).body.should == "abc"
end

it "should work with optional query params declared as string" do
stub_http_request(:get, "www.example.com/?x=3&a[]=b&a[]=c").to_return(:body => "abc")
stub_request(:get, "www.example.com/?x=3&a[]=b&a[]=c").to_return(:body => "abc")
http_request(:get, "http://www.example.com/?x=3", :query => "a[]=b&a[]=c").body.should == "abc"
end

it "should work when the body is passed as a Hash" do
stub_http_request(:post, "www.example.com").with(:body => {:a => "1", :b => "2"}).to_return(:body => "ok")
stub_request(:post, "www.example.com").with(:body => {:a => "1", :b => "2"}).to_return(:body => "ok")
http_request(:post, "http://www.example.com", :body => {:a => "1", :b => "2"}).body.should == "ok"
end

describe "mocking EM::HttpClient API" do
before do
stub_http_request(:get, "www.example.com/")
stub_request(:get, "www.example.com/")
WebMock::HttpLibAdapters::EmHttpRequestAdapter.enable!
end
subject do
Expand Down
26 changes: 11 additions & 15 deletions spec/acceptance/httpclient/httpclient_spec.rb
Expand Up @@ -4,40 +4,36 @@

require 'acceptance/httpclient/httpclient_spec_helper'

describe "Webmock with HTTPClient" do
describe "HTTPClient" do
include HTTPClientSpecHelper

before(:each) do
HTTPClientSpecHelper.async_mode = false
end

it_should_behave_like "WebMock"
include_examples "with WebMock"

it "should yield block on response if block provided" do
stub_http_request(:get, "www.example.com").to_return(:body => "abc")
stub_request(:get, "www.example.com").to_return(:body => "abc")
response_body = ""
http_request(:get, "http://www.example.com/") do |body|
response_body = body
end
response_body.should == "abc"
end

it "should match requests if headers are the same but in different order" do
stub_http_request(:get, "www.example.com").with(:headers => {"a" => ["b", "c"]} )
http_request(
:get, "http://www.example.com/",
:headers => {"a" => ["c", "b"]}).status.should == "200"
end


describe "async requests" do
it "should match requests if headers are the same but in different order" do
stub_request(:get, "www.example.com").with(:headers => {"a" => ["b", "c"]} )
http_request(
:get, "http://www.example.com/",
:headers => {"a" => ["c", "b"]}).status.should == "200"
end

describe "when using async requests" do
before(:each) do
HTTPClientSpecHelper.async_mode = true
end

it_should_behave_like "WebMock"

include_examples "with WebMock"
end

end
4 changes: 2 additions & 2 deletions spec/acceptance/net_http/net_http_spec.rb
Expand Up @@ -6,8 +6,8 @@

include NetHTTPSpecHelper

describe "Webmock with Net:HTTP" do
it_should_behave_like "WebMock"
describe "Net:HTTP" do
include_examples "with WebMock"

let(:port){ WebMockServer.instance.port }

Expand Down
18 changes: 9 additions & 9 deletions spec/acceptance/patron/patron_spec.rb
Expand Up @@ -8,10 +8,10 @@
require 'tmpdir'
require 'fileutils'

describe "Webmock with Patron" do
describe "Patron" do
include PatronSpecHelper

it_should_behave_like "WebMock"
include_examples "with WebMock"

describe "when custom functionality is used" do
before(:each) do
Expand All @@ -33,13 +33,13 @@


it "should work with get_file" do
stub_http_request(:get, "www.example.com").to_return(:body => "abc")
stub_request(:get, "www.example.com").to_return(:body => "abc")
@sess.get_file("/", @file_path)
File.read(@file_path).should == "abc"
end

it "should raise same error as Patron if file is not readable for get request" do
stub_http_request(:get, "www.example.com")
stub_request(:get, "www.example.com")
File.open("/tmp/read_only_file", "w") do |tmpfile|
tmpfile.chmod(0400)
end
Expand All @@ -54,18 +54,18 @@

it "should work with put_file" do
File.open(@file_path, "w") {|f| f.write "abc"}
stub_http_request(:put, "www.example.com").with(:body => "abc")
stub_request(:put, "www.example.com").with(:body => "abc")
@sess.put_file("/", @file_path)
end

it "should work with post_file" do
File.open(@file_path, "w") {|f| f.write "abc"}
stub_http_request(:post, "www.example.com").with(:body => "abc")
stub_request(:post, "www.example.com").with(:body => "abc")
@sess.post_file("/", @file_path)
end

it "should raise same error as Patron if file is not readable for post request" do
stub_http_request(:post, "www.example.com").with(:body => "abc")
stub_request(:post, "www.example.com").with(:body => "abc")
lambda {
@sess.post_file("/", "/path/to/non/existing/file")
}.should raise_error(ArgumentError, "Unable to open specified file.")
Expand All @@ -75,15 +75,15 @@

describe "handling errors same way as patron" do
it "should raise error if put request has neither upload_data nor file_name" do
stub_http_request(:post, "www.example.com")
stub_request(:post, "www.example.com")
lambda {
@sess.post("/", nil)
}.should raise_error(ArgumentError, "Must provide either data or a filename when doing a PUT or POST")
end
end

it "should work with WebDAV copy request" do
stub_http_request(:copy, "www.example.com/abc").with(:headers => {'Destination' => "/def"})
stub_request(:copy, "www.example.com/abc").with(:headers => {'Destination' => "/def"})
@sess.copy("/abc", "/def")
end

Expand Down

0 comments on commit ce42508

Please sign in to comment.