Skip to content
This repository
Browse code

Pass args to the shared example groups to filter out particular examp…

…les.
  • Loading branch information...
commit 910c1b59767c3ce75c7b5c58513e0834c6760b8e 1 parent fed4966
Myron Marston myronmarston authored
2  spec/acceptance/em_http_request/em_http_request_spec.rb
@@ -9,7 +9,7 @@
9 9 describe "EM::HttpRequest" do
10 10 include EMHttpRequestSpecHelper
11 11
12   - include_examples "with WebMock"
  12 + include_context "with WebMock", :no_status_message
13 13
14 14 #functionality only supported for em-http-request 1.x
15 15 if defined?(EventMachine::HttpConnection)
2  spec/acceptance/excon/excon_spec.rb
@@ -4,7 +4,7 @@
4 4
5 5 describe "Excon" do
6 6 include ExconSpecHelper
7   - include_context "with WebMock"
  7 + include_context "with WebMock", :no_status_message, :no_url_auth
8 8
9 9 it 'should allow Excon requests to use query hash paramters' do
10 10 stub_request(:get, "http://example.com/resource/?a=1&b=2").to_return(:body => "abc")
2  spec/acceptance/shared/allowing_and_disabling_net_connect.rb
... ... @@ -1,4 +1,4 @@
1   -shared_context "allowing and disabling net connect" do
  1 +shared_context "allowing and disabling net connect" do |*adapter_info|
2 2 describe "when net connect" do
3 3 describe "is allowed", :net_connect => true do
4 4 before(:each) do
10 spec/acceptance/shared/callbacks.rb
... ... @@ -1,4 +1,4 @@
1   -shared_context "callbacks" do
  1 +shared_context "callbacks" do |*adapter_info|
2 2 describe "when after_request callback is declared" do
3 3 before(:each) do
4 4 WebMock.reset_callbacks
@@ -105,12 +105,8 @@
105 105 end
106 106
107 107 it "should pass real response to callback with status and message" do
108   - # not supported by em-http-request, it always returns "unknown" for http_reason
109   - # not supported by excon, it only returns a status code
110   - unless [:em_http_request, :excon].include?(http_library)
111   - @response.status[0].should == 302
112   - @response.status[1].should == "Found"
113   - end
  108 + @response.status[0].should == 302
  109 + @response.status[1].should == "Found" unless adapter_info.include?(:no_status_message)
114 110 end
115 111
116 112 it "should pass real response to callback with headers" do
2  spec/acceptance/shared/enabling_and_disabling_webmock.rb
... ... @@ -1,4 +1,4 @@
1   -shared_context "enabled and disabled webmock" do
  1 +shared_context "enabled and disabled webmock" do |*adapter_info|
2 2 describe "when webmock is disabled" do
3 3 before(:each) do
4 4 WebMock.disable!
2  spec/acceptance/shared/precedence_of_stubs.rb
... ... @@ -1,4 +1,4 @@
1   -shared_context "precedence of stubs" do
  1 +shared_context "precedence of stubs" do |*adapter_info|
2 2 describe "when choosing a matching request stub" do
3 3 it "should use the last declared matching request stub" do
4 4 stub_request(:get, "www.example.com").to_return(:body => "abc")
5 spec/acceptance/shared/request_expectations.rb
... ... @@ -1,4 +1,4 @@
1   -shared_context "request expectations" do
  1 +shared_context "request expectations" do |*adapter_info|
2 2 describe "when request expectations are set" do
3 3 describe "when net connect is not allowed" do
4 4 before(:each) do
@@ -437,9 +437,8 @@
437 437 end
438 438 end
439 439
440   - describe "with authentication" do
  440 + describe "with authentication", :unless => (adapter_info.include?(:no_url_auth)) do
441 441 before(:each) do
442   - pending "Excon does not accept basic auth user-info in URLs" if http_library == :excon
443 442 stub_request(:any, "http://user:pass@www.example.com")
444 443 stub_request(:any, "http://user:pazz@www.example.com")
445 444 end
34 spec/acceptance/shared/returning_declared_responses.rb
... ... @@ -1,6 +1,6 @@
1 1 class MyException < StandardError; end;
2 2
3   -shared_context "declared responses" do
  3 +shared_context "declared responses" do |*adapter_info|
4 4 describe "when request stub declares that request should raise exception" do
5 5 it "should raise exception" do
6 6 stub_request(:get, "www.example.com").to_raise(MyException)
@@ -72,14 +72,10 @@ class MyException < StandardError; end;
72 72 http_request(:get, "http://www.example.com/").status.should == "500"
73 73 end
74 74
75   - it "should return response with declared status message" do
  75 + it "should return response with declared status message", :unless => (adapter_info.include?(:no_status_message)) do
76 76 stub_request(:get, "www.example.com").to_return(:status => [500, "Internal Server Error"])
77 77 response = http_request(:get, "http://www.example.com/")
78   - # not supported by em-http-request, it always returns "unknown" for http_reason
79   - # not supported by excon, it only returns a status code
80   - unless [:em_http_request, :excon].include?(http_library)
81   - response.message.should == "Internal Server Error"
82   - end
  78 + response.message.should == "Internal Server Error"
83 79 end
84 80
85 81 it "should return response with a default status code" do
@@ -87,14 +83,10 @@ class MyException < StandardError; end;
87 83 http_request(:get, "http://www.example.com/").status.should == "200"
88 84 end
89 85
90   - it "should return default response with empty message if response was not declared" do
  86 + it "should return default response with empty message if response was not declared", :unless => (adapter_info.include?(:no_status_message)) do
91 87 stub_request(:get, "www.example.com")
92 88 response = http_request(:get, "http://www.example.com/")
93   - # not supported by em-http-request, it always returns "unknown" for http_reason
94   - # not supported by excon, it only returns a status code
95   - unless [:em_http_request, :excon].include?(http_library)
96   - response.message.should == ""
97   - end
  89 + response.message.should == ""
98 90 end
99 91
100 92 describe "when response body was declared as IO" do
@@ -188,12 +180,8 @@ def call(request)
188 180 @response.status.should == "202"
189 181 end
190 182
191   - it "should return recorded status message" do
192   - # not supported by em-http-request, it always returns "unknown" for http_reason
193   - # not supported by excon, it only returns a status code
194   - unless [:em_http_request, :excon].include?(http_library)
195   - @response.message.should == "OK"
196   - end
  183 + it "should return recorded status message", :unless => (adapter_info.include?(:no_status_message)) do
  184 + @response.message.should == "OK"
197 185 end
198 186
199 187 it "should ensure file is closed" do
@@ -226,12 +214,8 @@ def call(request)
226 214 @response.status.should == "202"
227 215 end
228 216
229   - it "should return recorded status message" do
230   - # not supported by em-http-request, it always returns "unknown" for http_reason
231   - # not supported by excon, it only returns a status code
232   - unless [:em_http_request, :excon].include?(http_library)
233   - @response.message.should == "OK"
234   - end
  217 + it "should return recorded status message", :unless => (adapter_info.include?(:no_status_message)) do
  218 + @response.message.should == "OK"
235 219 end
236 220 end
237 221
8 spec/acceptance/shared/stubbing_requests.rb
... ... @@ -1,4 +1,4 @@
1   -shared_examples_for "stubbing requests" do
  1 +shared_examples_for "stubbing requests" do |*adapter_info|
2 2 describe "when requests are stubbed" do
3 3 describe "based on uri" do
4 4 it "should return stubbed response even if request have escaped parameters" do
@@ -295,11 +295,7 @@
295 295 end
296 296 end
297 297
298   - describe "when stubbing request with basic authentication" do
299   - before do
300   - pending "Excon does not accept basic auth user-info in URLs" if http_library == :excon
301   - end
302   -
  298 + describe "when stubbing request with basic authentication", :unless => (adapter_info.include?(:no_url_auth)) do
303 299 it "should match if credentials are the same" do
304 300 stub_request(:get, "user:pass@www.example.com")
305 301 http_request(:get, "http://user:pass@www.example.com/").status.should == "200"
16 spec/acceptance/webmock_shared.rb
@@ -13,7 +13,7 @@
13 13 NOT_ESCAPED_PARAMS = "z='Stop!' said Fred&x=ab c"
14 14 end
15 15
16   -shared_examples "with WebMock" do
  16 +shared_examples "with WebMock" do |*adapter_info|
17 17 describe "with WebMock" do
18 18 let(:webmock_server_url) {"http://#{WebMockServer.instance.host_with_port}/"}
19 19 before(:each) do
@@ -21,18 +21,18 @@
21 21 WebMock.reset!
22 22 end
23 23
24   - include_context "allowing and disabling net connect"
  24 + include_context "allowing and disabling net connect", *adapter_info
25 25
26   - include_context "stubbing requests"
  26 + include_context "stubbing requests", *adapter_info
27 27
28   - include_context "declared responses"
  28 + include_context "declared responses", *adapter_info
29 29
30   - include_context "precedence of stubs"
  30 + include_context "precedence of stubs", *adapter_info
31 31
32   - include_context "request expectations"
  32 + include_context "request expectations", *adapter_info
33 33
34   - include_context "callbacks"
  34 + include_context "callbacks", *adapter_info
35 35
36   - include_context "enabled and disabled webmock"
  36 + include_context "enabled and disabled webmock", *adapter_info
37 37 end
38 38 end

0 comments on commit 910c1b5

Please sign in to comment.
Something went wrong with that request. Please try again.