Skip to content
Newer
Older
100644 76 lines (65 sloc) 3.5 KB
b457d38 @bblimke Added minitest spec to ensure webmock works with Minitest::Spec. Unfo…
authored Jul 30, 2011
1 require File.expand_path(File.dirname(__FILE__) + '/http_request')
4710449 @bblimke Created separate folder with minitest tests instead of running them f…
authored Jul 30, 2011
2
3 module SharedTest
b457d38 @bblimke Added minitest spec to ensure webmock works with Minitest::Spec. Unfo…
authored Jul 30, 2011
4 include HttpRequestTestHelper
4710449 @bblimke Created separate folder with minitest tests instead of running them f…
authored Jul 30, 2011
5
6 def setup
7 super
84ef7a7 @nfo Added Test::Unit methods +assert_stub_requested+ and +assert_stub_not…
nfo authored Sep 7, 2011
8 @stub_http = stub_http_request(:any, "http://www.example.com")
9 @stub_https = stub_http_request(:any, "https://www.example.com")
4710449 @bblimke Created separate folder with minitest tests instead of running them f…
authored Jul 30, 2011
10 end
11
12 def test_error_on_non_stubbed_request
13 default_ruby_headers = (RUBY_VERSION >= "1.9.1") ? "{'Accept'=>'*/*', 'User-Agent'=>'Ruby'}" : "{'Accept'=>'*/*'}"
3cb8c3b @bblimke Limited details of a failure message to be ruby version independent.
authored Jul 30, 2011
14 assert_raise_with_message(WebMock::NetConnectNotAllowedError, %r{Real HTTP connections are disabled. Unregistered request: GET http://www.example.net/ with headers}) do
4710449 @bblimke Created separate folder with minitest tests instead of running them f…
authored Jul 30, 2011
15 http_request(:get, "http://www.example.net/")
16 end
17 end
18
19 def test_verification_that_expected_request_occured
20 http_request(:get, "http://www.example.com/")
21 assert_requested(:get, "http://www.example.com", :times => 1)
22 assert_requested(:get, "http://www.example.com")
23 end
24
84ef7a7 @nfo Added Test::Unit methods +assert_stub_requested+ and +assert_stub_not…
nfo authored Sep 7, 2011
25 def test_verification_that_expected_stub_occured
26 http_request(:get, "http://www.example.com/")
ed795fa @bblimke assert_requested and assert_not_requested can accept either method an…
authored Feb 4, 2012
27 assert_requested(@stub_http, :times => 1)
28 assert_requested(@stub_http)
84ef7a7 @nfo Added Test::Unit methods +assert_stub_requested+ and +assert_stub_not…
nfo authored Sep 7, 2011
29 end
30
4710449 @bblimke Created separate folder with minitest tests instead of running them f…
authored Jul 30, 2011
31 def test_verification_that_expected_request_didnt_occur
32 expected_message = "The request GET http://www.example.com/ was expected to execute 1 time but it executed 0 times"
33 expected_message << "\n\nThe following requests were made:\n\nNo requests were made.\n============================================================"
34 assert_fail(expected_message) do
35 assert_requested(:get, "http://www.example.com")
36 end
37 end
38
84ef7a7 @nfo Added Test::Unit methods +assert_stub_requested+ and +assert_stub_not…
nfo authored Sep 7, 2011
39 def test_verification_that_expected_request_didnt_occur
40 expected_message = "The request ANY http://www.example.com/ was expected to execute 1 time but it executed 0 times"
41 expected_message << "\n\nThe following requests were made:\n\nNo requests were made.\n============================================================"
42 assert_fail(expected_message) do
ed795fa @bblimke assert_requested and assert_not_requested can accept either method an…
authored Feb 4, 2012
43 assert_requested(@stub_http)
84ef7a7 @nfo Added Test::Unit methods +assert_stub_requested+ and +assert_stub_not…
nfo authored Sep 7, 2011
44 end
45 end
46
4710449 @bblimke Created separate folder with minitest tests instead of running them f…
authored Jul 30, 2011
47 def test_verification_that_expected_request_occured_with_body_and_headers
48 http_request(:get, "http://www.example.com/",
49 :body => "abc", :headers => {'A' => 'a'})
50 assert_requested(:get, "http://www.example.com",
51 :body => "abc", :headers => {'A' => 'a'})
52 end
53
4ad4079 @bblimke Added Test::Unit test to ensure hash_including query matcher works ou…
authored Feb 5, 2012
54 def test_verification_that_expected_request_occured_with_query_params
55 stub_request(:any, "http://www.example.com").with(:query => hash_including({"a" => ["b", "c"]}))
56 http_request(:get, "http://www.example.com/?a[]=b&a[]=c&x=1")
57 assert_requested(:get, "http://www.example.com",
58 :query => hash_including({"a" => ["b", "c"]}))
59 end
60
4710449 @bblimke Created separate folder with minitest tests instead of running them f…
authored Jul 30, 2011
61 def test_verification_that_non_expected_request_didnt_occur
62 expected_message = %r(The request GET http://www.example.com/ was expected to execute 0 times but it executed 1 time\n\nThe following requests were made:\n\nGET http://www.example.com/ with headers .+ was made 1 time\n\n============================================================)
63 assert_fail(expected_message) do
64 http_request(:get, "http://www.example.com/")
65 assert_not_requested(:get, "http://www.example.com")
66 end
67 end
84ef7a7 @nfo Added Test::Unit methods +assert_stub_requested+ and +assert_stub_not…
nfo authored Sep 7, 2011
68
69 def test_verification_that_non_expected_stub_didnt_occur
70 expected_message = %r(The request ANY http://www.example.com/ was expected to execute 0 times but it executed 1 time\n\nThe following requests were made:\n\nGET http://www.example.com/ with headers .+ was made 1 time\n\n============================================================)
71 assert_fail(expected_message) do
72 http_request(:get, "http://www.example.com/")
ed795fa @bblimke assert_requested and assert_not_requested can accept either method an…
authored Feb 4, 2012
73 assert_not_requested(@stub_http)
84ef7a7 @nfo Added Test::Unit methods +assert_stub_requested+ and +assert_stub_not…
nfo authored Sep 7, 2011
74 end
75 end
4710449 @bblimke Created separate folder with minitest tests instead of running them f…
authored Jul 30, 2011
76 end
Something went wrong with that request. Please try again.