Skip to content

Commit

Permalink
Pass args to the shared example groups to filter out particular examp…
Browse files Browse the repository at this point in the history
…les.
  • Loading branch information
myronmarston committed Feb 5, 2012
1 parent fed4966 commit 910c1b5
Show file tree
Hide file tree
Showing 10 changed files with 29 additions and 54 deletions.
2 changes: 1 addition & 1 deletion spec/acceptance/em_http_request/em_http_request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
describe "EM::HttpRequest" do
include EMHttpRequestSpecHelper

include_examples "with WebMock"
include_context "with WebMock", :no_status_message

#functionality only supported for em-http-request 1.x
if defined?(EventMachine::HttpConnection)
Expand Down
2 changes: 1 addition & 1 deletion spec/acceptance/excon/excon_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

describe "Excon" do
include ExconSpecHelper
include_context "with WebMock"
include_context "with WebMock", :no_status_message, :no_url_auth

it 'should allow Excon requests to use query hash paramters' do
stub_request(:get, "http://example.com/resource/?a=1&b=2").to_return(:body => "abc")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
shared_context "allowing and disabling net connect" do
shared_context "allowing and disabling net connect" do |*adapter_info|
describe "when net connect" do
describe "is allowed", :net_connect => true do
before(:each) do
Expand Down
10 changes: 3 additions & 7 deletions spec/acceptance/shared/callbacks.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
shared_context "callbacks" do
shared_context "callbacks" do |*adapter_info|
describe "when after_request callback is declared" do
before(:each) do
WebMock.reset_callbacks
Expand Down Expand Up @@ -105,12 +105,8 @@
end

it "should pass real response to callback with status and message" do
# not supported by em-http-request, it always returns "unknown" for http_reason
# not supported by excon, it only returns a status code
unless [:em_http_request, :excon].include?(http_library)
@response.status[0].should == 302
@response.status[1].should == "Found"
end
@response.status[0].should == 302
@response.status[1].should == "Found" unless adapter_info.include?(:no_status_message)
end

it "should pass real response to callback with headers" do
Expand Down
2 changes: 1 addition & 1 deletion spec/acceptance/shared/enabling_and_disabling_webmock.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
shared_context "enabled and disabled webmock" do
shared_context "enabled and disabled webmock" do |*adapter_info|
describe "when webmock is disabled" do
before(:each) do
WebMock.disable!
Expand Down
2 changes: 1 addition & 1 deletion spec/acceptance/shared/precedence_of_stubs.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
shared_context "precedence of stubs" do
shared_context "precedence of stubs" do |*adapter_info|
describe "when choosing a matching request stub" do
it "should use the last declared matching request stub" do
stub_request(:get, "www.example.com").to_return(:body => "abc")
Expand Down
5 changes: 2 additions & 3 deletions spec/acceptance/shared/request_expectations.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
shared_context "request expectations" do
shared_context "request expectations" do |*adapter_info|
describe "when request expectations are set" do
describe "when net connect is not allowed" do
before(:each) do
Expand Down Expand Up @@ -437,9 +437,8 @@
end
end

describe "with authentication" do
describe "with authentication", :unless => (adapter_info.include?(:no_url_auth)) do
before(:each) do
pending "Excon does not accept basic auth user-info in URLs" if http_library == :excon
stub_request(:any, "http://user:pass@www.example.com")
stub_request(:any, "http://user:pazz@www.example.com")
end
Expand Down
34 changes: 9 additions & 25 deletions spec/acceptance/shared/returning_declared_responses.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class MyException < StandardError; end;

shared_context "declared responses" do
shared_context "declared responses" do |*adapter_info|
describe "when request stub declares that request should raise exception" do
it "should raise exception" do
stub_request(:get, "www.example.com").to_raise(MyException)
Expand Down Expand Up @@ -72,29 +72,21 @@ class MyException < StandardError; end;
http_request(:get, "http://www.example.com/").status.should == "500"
end

it "should return response with declared status message" do
it "should return response with declared status message", :unless => (adapter_info.include?(:no_status_message)) do
stub_request(:get, "www.example.com").to_return(:status => [500, "Internal Server Error"])
response = http_request(:get, "http://www.example.com/")
# not supported by em-http-request, it always returns "unknown" for http_reason
# not supported by excon, it only returns a status code
unless [:em_http_request, :excon].include?(http_library)
response.message.should == "Internal Server Error"
end
response.message.should == "Internal Server Error"
end

it "should return response with a default status code" do
stub_request(:get, "www.example.com")
http_request(:get, "http://www.example.com/").status.should == "200"
end

it "should return default response with empty message if response was not declared" do
it "should return default response with empty message if response was not declared", :unless => (adapter_info.include?(:no_status_message)) do
stub_request(:get, "www.example.com")
response = http_request(:get, "http://www.example.com/")
# not supported by em-http-request, it always returns "unknown" for http_reason
# not supported by excon, it only returns a status code
unless [:em_http_request, :excon].include?(http_library)
response.message.should == ""
end
response.message.should == ""
end

describe "when response body was declared as IO" do
Expand Down Expand Up @@ -188,12 +180,8 @@ def call(request)
@response.status.should == "202"
end

it "should return recorded status message" do
# not supported by em-http-request, it always returns "unknown" for http_reason
# not supported by excon, it only returns a status code
unless [:em_http_request, :excon].include?(http_library)
@response.message.should == "OK"
end
it "should return recorded status message", :unless => (adapter_info.include?(:no_status_message)) do
@response.message.should == "OK"
end

it "should ensure file is closed" do
Expand Down Expand Up @@ -226,12 +214,8 @@ def call(request)
@response.status.should == "202"
end

it "should return recorded status message" do
# not supported by em-http-request, it always returns "unknown" for http_reason
# not supported by excon, it only returns a status code
unless [:em_http_request, :excon].include?(http_library)
@response.message.should == "OK"
end
it "should return recorded status message", :unless => (adapter_info.include?(:no_status_message)) do
@response.message.should == "OK"
end
end

Expand Down
8 changes: 2 additions & 6 deletions spec/acceptance/shared/stubbing_requests.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
shared_examples_for "stubbing requests" do
shared_examples_for "stubbing requests" do |*adapter_info|
describe "when requests are stubbed" do
describe "based on uri" do
it "should return stubbed response even if request have escaped parameters" do
Expand Down Expand Up @@ -295,11 +295,7 @@
end
end

describe "when stubbing request with basic authentication" do
before do
pending "Excon does not accept basic auth user-info in URLs" if http_library == :excon
end

describe "when stubbing request with basic authentication", :unless => (adapter_info.include?(:no_url_auth)) do
it "should match if credentials are the same" do
stub_request(:get, "user:pass@www.example.com")
http_request(:get, "http://user:pass@www.example.com/").status.should == "200"
Expand Down
16 changes: 8 additions & 8 deletions spec/acceptance/webmock_shared.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,26 @@
NOT_ESCAPED_PARAMS = "z='Stop!' said Fred&x=ab c"
end

shared_examples "with WebMock" do
shared_examples "with WebMock" do |*adapter_info|
describe "with WebMock" do
let(:webmock_server_url) {"http://#{WebMockServer.instance.host_with_port}/"}
before(:each) do
WebMock.disable_net_connect!
WebMock.reset!
end

include_context "allowing and disabling net connect"
include_context "allowing and disabling net connect", *adapter_info

include_context "stubbing requests"
include_context "stubbing requests", *adapter_info

include_context "declared responses"
include_context "declared responses", *adapter_info

include_context "precedence of stubs"
include_context "precedence of stubs", *adapter_info

include_context "request expectations"
include_context "request expectations", *adapter_info

include_context "callbacks"
include_context "callbacks", *adapter_info

include_context "enabled and disabled webmock"
include_context "enabled and disabled webmock", *adapter_info
end
end

0 comments on commit 910c1b5

Please sign in to comment.