rspec-webservice_matchers 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 265e8b7dcda9ee745d3e6af87d0edbd62316ddad
4
- data.tar.gz: 3eabeefa683eaefe004da1e52f0a35ca32c776e0
3
+ metadata.gz: 9868caf0250aca39ae098dde21665e23514be03e
4
+ data.tar.gz: 60d4fbe7246451ec22ff3ac0059289cc0b0201e0
5
5
  SHA512:
6
- metadata.gz: 4eb9d89a6427201f36ce5dddfcf8d42c0dd028b3a13a40a1b195e0be8137d4d434d444c055eb8c33c22313c5b7c10a6bf2713ea8411c9ace5378255556795d84
7
- data.tar.gz: bce72bddfe63271945820583047d1be14ae2d52db12fc0f63485d31f1c43bbfb3943c46494f0591f4a7f9cda5d7df426cc4a0d86cb1b9c74f74ec41628b1cb31
6
+ metadata.gz: f518432f3c125e75f6cf984b599e7223d558bef01891e874403c10554d8e02eb7a2c58d0fd9c80aff6649e2fbfa53ad3994aa4bfbc6bc623af2d919becf414b1
7
+ data.tar.gz: dbc75327ee297423c7ba2b8959972893492eaa2df962af2bc00e6af43a3dbf20bb3e786296f6f96ab36ec90551ce6d80c9f1eba7151d5ed47207cc6190daf15d
data/README.md CHANGED
@@ -2,9 +2,6 @@
2
2
 
3
3
  This gem enables you to black-box test a web app's server configuration. For example, whether its SSL certificate is correctly configured and not expired. It's a tool for doing **Test Driven Devops**. (I just made that up.)
4
4
 
5
- TODO: Add matchers for HTTP result codes.
6
-
7
-
8
5
  Installation
9
6
  ------------
10
7
  ```Shell
@@ -15,16 +12,25 @@ $ gem install rspec-webservice_matchers
15
12
  Example
16
13
  -------
17
14
 
15
+ Currently, two matchers are implemented, `have_a_valid_cert` and `redirect_permanently_to`:
16
+
18
17
  ```Ruby
19
18
  require 'rspec/webservice_matchers'
20
19
 
21
20
  describe 'My app' do
22
21
  it 'is configured for ssl' do
23
- # New-style RSpec syntax
24
22
  expect('www.myapp.com').to have_a_valid_cert
25
-
26
- # Old-style RSpec syntax
27
- 'www.myapp.com'.should have_a_valid_cert
23
+ end
24
+
25
+ it 'redirects to www' do
26
+ expect('http://myapp.com').to redirect_permanently_to 'http://www.myapp.com/'
28
27
  end
29
28
  end
30
29
  ```
30
+
31
+
32
+ TODO
33
+ ----
34
+ * Matchers for more HTTP result codes. I'm adding these in by refactoring code out of my [oregonlaws.org](http://www.oregonlaws.org/) and [weblaws.org](http://www.weblaws.org/) projects.
35
+ * Matchers for JSON schema
36
+
@@ -1,5 +1,5 @@
1
1
  module RSpec
2
2
  module WebserviceMatchers
3
- VERSION = "0.0.2"
3
+ VERSION = "0.0.3"
4
4
  end
5
5
  end
@@ -14,17 +14,7 @@ module RSpec
14
14
  end
15
15
  end
16
16
 
17
- #
18
- # Custom RSpec matcher: have_a_valid_cert
19
- #
20
- RSpec::Matchers.define :have_a_valid_cert do
21
- match do |domain_name|
22
- RSpec::WebserviceMatchers.has_valid_ssl_cert?(domain_name)
23
- end
24
- end
25
-
26
-
27
- # Would this matcher be helpful?
17
+ # Would this function be helpful?
28
18
 
29
19
  #
30
20
  # Return true if the domain serves content via SSL
@@ -41,5 +31,31 @@ module RSpec
41
31
  # end
42
32
  # end
43
33
 
34
+
35
+ # RSpec Custom Matchers ###########################################
36
+ # See https://www.relishapp.com/rspec/rspec-expectations/v/3-0/docs/custom-matchers/define-matcher
37
+
38
+
39
+ RSpec::Matchers.define :have_a_valid_cert do
40
+ match do |domain_name|
41
+ RSpec::WebserviceMatchers.has_valid_ssl_cert?(domain_name)
42
+ end
43
+ end
44
+
45
+ RSpec::Matchers.define :redirect_permanently_to do |expected|
46
+ match do |url|
47
+ # TODO: Refactor this code. Submit as pull request to Curb.
48
+ result = Curl::Easy.http_head(url)
49
+ header_lines = result.head.split("\r\n")
50
+ header_lines.delete_at(0) # The first reponse header is already parsed.
51
+ header = {}
52
+ header_lines.each do |line|
53
+ key, value = line.split(': ')
54
+ header[key] = value
55
+ end
56
+ result.response_code == 301 && header['Location'] == expected
57
+ end
58
+ end
59
+
44
60
  end
45
61
  end
@@ -0,0 +1,8 @@
1
+ require 'rspec/webservice_matchers'
2
+
3
+ describe 'redirect_permanently_to' do
4
+ it 'passes when receiving a 301 to the given URL' do
5
+ # TODO: Set up a server for this. (Or a mock?)
6
+ expect('http://weblaws.org').to redirect_permanently_to('http://www.weblaws.org/')
7
+ end
8
+ end
@@ -4,14 +4,14 @@ describe 'have_a_valid_cert matcher' do
4
4
 
5
5
  it 'passes when SSL is properly configured' do
6
6
  # EFF created the HTTPS Everywhere movement
7
- # TODO: set up test servers for this.
7
+ # TODO: set up a test server for this.
8
8
  expect('www.eff.org').to have_a_valid_cert
9
9
  end
10
10
 
11
11
  it 'fails if the server is not serving SSL at all' do
12
12
  expect {
13
13
  # www.psu.edu only supports HTTP, port 80.
14
- # TODO: set up test servers for this.
14
+ # TODO: set up a test server for this.
15
15
  expect('www.psu.edu').to have_a_valid_cert
16
16
  }.to raise_error(RSpec::Expectations::ExpectationNotMetError)
17
17
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-webservice_matchers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robb Shecter
@@ -67,6 +67,7 @@ files:
67
67
  - lib/rspec/webservice_matchers.rb
68
68
  - lib/rspec/webservice_matchers/version.rb
69
69
  - rspec-webservice_matchers.gemspec
70
+ - spec/rspec/webservice_matchers/redirect_spec.rb
70
71
  - spec/rspec/webservice_matchers/ssl_spec.rb
71
72
  homepage: https://github.com/dogweather/rspec-webservice_matchers
72
73
  licenses:
@@ -93,4 +94,5 @@ signing_key:
93
94
  specification_version: 4
94
95
  summary: Handy matchers for testing web services
95
96
  test_files:
97
+ - spec/rspec/webservice_matchers/redirect_spec.rb
96
98
  - spec/rspec/webservice_matchers/ssl_spec.rb