rspec-webservice_matchers 1.4.0 → 1.4.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2b1695496042a67e3abc9091838f8c18a0a5ba55
4
- data.tar.gz: ee02bda5eb989137c8cfec9f782d2f45344c8b7d
3
+ metadata.gz: bc5dff69f7d8e076b45349e851cffed6c3154dae
4
+ data.tar.gz: 234b5ec72bbb82e23535f5650ea7ea7bffd9bae1
5
5
  SHA512:
6
- metadata.gz: 9f8acb1ade62b454163648f8e7d59562d64953f748af61576a0b797d2922d2fc74131481caeb8578ab22cab78bd25da96463bf557c89e6ec2eeee09354ea1cbf
7
- data.tar.gz: 9d5ad3154d0db6175977d39b4181eb637cacaf1a64f7591b0665d03c75fab8fff043cdf09e10a38b9f6801b332fc7cbc3950590f85133c3aa20411aba10eae5f
6
+ metadata.gz: 0e62ebf6d183a2aa82bb4f595342e55b4b54a4de1b6afbd4c11f4d54485510858ae7c9071e8272849665d2dae88eb9cce2216c1c622b74d2009eacbabeffc2af
7
+ data.tar.gz: 3079c979f64cb292ede888caed703afeef2c936740efa068b2762791204951afbf6063d1cda781ff198a9ea93c6fa2faed26d9930d86dc2e0af6096a1ffa21f4
data/.travis.yml CHANGED
@@ -2,3 +2,4 @@ language: ruby
2
2
  rvm:
3
3
  - "2.0.0"
4
4
  - "2.1.0"
5
+ - "2.1.1"
@@ -82,16 +82,27 @@ module RSpec
82
82
  end
83
83
  end
84
84
 
85
+
85
86
  # Pass when a URL returns the expected status code
86
87
  # Codes are defined in http://www.rfc-editor.org/rfc/rfc2616.txt
87
88
  RSpec::Matchers.define :be_status do |expected|
89
+ actual_code = nil
90
+
88
91
  match do |url_or_domain_name|
89
92
  url = RSpec::WebserviceMatchers.make_url(url_or_domain_name)
90
93
  response = RSpec::WebserviceMatchers.connection.head(url)
91
- response.status == expected.to_i
94
+ actual = response.status
95
+ expected = expected.to_i
96
+ actual_code = actual
97
+ actual == expected
98
+ end
99
+
100
+ failure_message_for_should do
101
+ "Received status #{actual_code}"
92
102
  end
93
103
  end
94
104
 
105
+
95
106
  # Pass when the response code is 200, following redirects
96
107
  # if necessary.
97
108
  RSpec::Matchers.define :be_up do
@@ -1,5 +1,5 @@
1
1
  module RSpec
2
2
  module WebserviceMatchers
3
- VERSION = "1.4.0"
3
+ VERSION = "1.4.1"
4
4
  end
5
5
  end
@@ -1,20 +1,10 @@
1
- require 'webmock/rspec'
1
+ require 'spec_helper'
2
2
  require 'rspec/webservice_matchers'
3
3
 
4
- #
5
- # TODO: set up mocks or VCR for the rest of these.
6
- # SEE: http://www.slideshare.net/kjbuckley/testing-http-calls-with-webmock-and-vcr
7
- #
8
4
 
9
- WebMock.stub_request :any, 'http://www.website.com/a/page.txt'
10
- WebMock.stub_request :any, 'http://www.website.com/'
11
-
12
- WebMock.allow_net_connect!
13
-
14
-
15
- describe 'status_code' do
5
+ describe 'be_status' do
16
6
  it 'can check 200 for successful resource requests' do
17
- 'http://www.website.com/a/page.txt'.should be_status 200
7
+ 'http://a-page.com/a/page.txt'.should be_status 200
18
8
  end
19
9
 
20
10
  it 'handles domain names as well as URLs' do
@@ -25,24 +15,32 @@ describe 'status_code' do
25
15
  'www.website.com'.should be_status '200'
26
16
  end
27
17
 
28
- it 'can check 503 for the Service Unavailable status' do
29
- 'http://www.weblaws.org/texas/laws/tex._spec._dist._local_laws_code_section_1011.202_tax_to_pay_general_obligation_bonds'.should be_status 503
18
+ it 'can check for the 503 - Service Unavailable status' do
19
+ 'http://outoforder.com/'.should be_status 503
20
+ end
21
+
22
+ it 'can check for 404' do
23
+ expect('http://notfound.com/no.txt').to be_status 404
24
+ end
25
+
26
+ it 'gives the actual code received in case of failure' do
27
+ expect {
28
+ expect('http://notfound.com/no.txt').to be_status 200
29
+ }.to fail_matching(/404/)
30
30
  end
31
31
  end
32
32
 
33
33
 
34
34
  describe 'be_up' do
35
- let(:rfc_url) {'http://www.rfc-editor.org/rfc/rfc2616.txt'}
36
-
37
35
  it 'follows redirects when necessary' do
38
- 'weblaws.org'.should be_up
36
+ 'perm-redirector.com'.should be_up
39
37
  end
40
38
 
41
39
  it 'can also handle a simple 200' do
42
- rfc_url.should be_up
40
+ 'http://www.website.com/'.should be_up
43
41
  end
44
42
 
45
43
  it 'is available via a public API' do
46
- RSpec::WebserviceMatchers.up?(rfc_url).should be true
44
+ RSpec::WebserviceMatchers.up?('http://www.website.com/').should be true
47
45
  end
48
46
  end
@@ -0,0 +1,33 @@
1
+ require 'webmock/rspec'
2
+
3
+ RSpec.configure do |config|
4
+ config.before(:each) do
5
+
6
+ WebMock.stub_request :any, 'http://a-page.com/a/page.txt'
7
+ WebMock.stub_request :any, 'www.website.com'
8
+ WebMock.stub_request(:any, /notfound.com/).to_return(status: 404)
9
+ WebMock.stub_request(:any, 'outoforder.com').to_return(status: 503)
10
+
11
+ WebMock.stub_request(:any, 'perm-redirector.com')
12
+ .to_return(status: 301, headers: {Location: 'http://www.website.com/'})
13
+
14
+ WebMock.allow_net_connect!
15
+ end
16
+ end
17
+
18
+
19
+ module RSpec
20
+ module Matchers
21
+ def fail
22
+ raise_error(RSpec::Expectations::ExpectationNotMetError)
23
+ end
24
+
25
+ def fail_with(message)
26
+ raise_error(RSpec::Expectations::ExpectationNotMetError, message)
27
+ end
28
+
29
+ def fail_matching(regex)
30
+ raise_error(RSpec::Expectations::ExpectationNotMetError, regex)
31
+ end
32
+ end
33
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-webservice_matchers
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0
4
+ version: 1.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robb Shecter
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-13 00:00:00.000000000 Z
11
+ date: 2014-03-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -127,6 +127,7 @@ files:
127
127
  - spec/rspec/webservice_matchers/protcol_spec.rb
128
128
  - spec/rspec/webservice_matchers/redirect_spec.rb
129
129
  - spec/rspec/webservice_matchers/ssl_spec.rb
130
+ - spec/spec_helper.rb
130
131
  homepage: https://github.com/dogweather/rspec-webservice_matchers
131
132
  licenses:
132
133
  - MIT
@@ -155,3 +156,4 @@ test_files:
155
156
  - spec/rspec/webservice_matchers/protcol_spec.rb
156
157
  - spec/rspec/webservice_matchers/redirect_spec.rb
157
158
  - spec/rspec/webservice_matchers/ssl_spec.rb
159
+ - spec/spec_helper.rb