rspec-webservice_matchers 0.1.1 → 0.2.0

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: 7a91cd72d70ca58ac4b471caef6ff810ee90b2b1
4
- data.tar.gz: fbda72dad2ca7a23c05be9fc90af9fcb98dfe198
3
+ metadata.gz: f213b57f745129ca27f161fafab51468beec886c
4
+ data.tar.gz: 8e9a30715b9de34263e66db6f4776caed4fd6418
5
5
  SHA512:
6
- metadata.gz: 8b846008102ec2520cff3be9481d15dc5862dbdcca59025199dbdb6f7c9a887534858cfb9b6dd3bd32b3b31c7bf6a91ba34df8c19065ed32f93e41bfdc46e42c
7
- data.tar.gz: f7c089dfbee764e7b96f05cd71e41c03ad97e4ea1ed6dbeb306b57bebc6efb808806a3dcd42111549e7c30725829e5887365f368dacf1a9f17e4114906bf4e1b
6
+ metadata.gz: dc69ca69ee807788b27af421a90088f6b0f3c4cd14126a215e58c2bd6bb66d7882225d1b7c3399e54d8e8cf720070f24f7fd7e63371dc6b477a32eac6695fddd
7
+ data.tar.gz: 17301939ab8f4cc7ffacd7b53cfd55880074285c56663f90eb0d4b97a4308b155159dd26d85119a3d9a64afa51d915f8b1b87c419581d79aaf3442353f53e821
data/README.md CHANGED
@@ -2,28 +2,35 @@
2
2
 
3
3
  This [gem](https://rubygems.org/gems/rspec-webservice_matchers) 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
+ This library takes a very minimalist approach: by simply adding new RSpec matchers,
6
+ you can use your own RSpec writing style; no new DSL to learn.
7
+
5
8
  Installation
6
9
  ------------
7
10
  ```Shell
8
11
  $ gem install rspec-webservice_matchers
9
12
  ```
10
13
 
14
+ What You Get
15
+ ------------
16
+ These new RSpec matchers:
11
17
 
12
- Example
13
- -------
14
-
15
- Currently, three matchers are implemented:
16
-
18
+ * `be_status`
17
19
  * `have_a_valid_cert`
20
+ * `enforce_https_everywhere` (See [EFF](https://www.eff.org/https-everywhere))
18
21
  * `redirect_permanently_to`
19
- * `enforce_https_everywhere` (See the [EFF site](https://www.eff.org/https-everywhere) for more info)
22
+
23
+
24
+ Example
25
+ -------
20
26
 
21
27
  ```Ruby
22
28
  require 'rspec/webservice_matchers'
23
29
 
24
- describe 'My app' do
25
- it 'is configured for ssl' do
26
- expect('www.myapp.com').to have_a_valid_cert
30
+ describe 'My app' do
31
+ context 'www.myapp.com' do
32
+ it { should be_status 200 }
33
+ it { should have_a_valid_cert }
27
34
  end
28
35
 
29
36
  it 'redirects to www' do
@@ -39,6 +46,13 @@ end
39
46
 
40
47
  TODO
41
48
  ----
42
- * 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.
49
+ * Matchers for more high-level cases, such as the two kinds of temp. redirect
43
50
  * Matchers for JSON schema
51
+ * More matchers refactored from [weblaws.org](http://www.weblaws.org/) code
52
+
53
+ Related Projects
54
+ ----------------
55
+ * [serverspec](http://serverspec.org)
56
+ * [HTTP Assertions](https://github.com/dogweather/HTTP-Assertions)
57
+
44
58
 
@@ -1,5 +1,5 @@
1
1
  module RSpec
2
2
  module WebserviceMatchers
3
- VERSION = "0.1.1"
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  end
@@ -53,9 +53,30 @@ module RSpec
53
53
  end
54
54
  end
55
55
 
56
+ # Pass when a URL returns the expected status code
57
+ # Codes are defined in http://www.rfc-editor.org/rfc/rfc2616.txt
58
+ RSpec::Matchers.define :be_status do |expected|
59
+ match do |url_or_domain_name|
60
+ url = RSpec::WebserviceMatchers.make_url(url_or_domain_name)
61
+ result = Curl::Easy.http_head(url)
62
+ (result.response_code == expected.to_i)
63
+ end
64
+ end
65
+
56
66
 
57
67
  private
58
68
 
69
+ # Ensure that the given string is a URL,
70
+ # making it into one if necessary.
71
+ def self.make_url(url_or_domain_name)
72
+ unless %r|^https?://| === url_or_domain_name
73
+ "http://#{url_or_domain_name}"
74
+ else
75
+ url_or_domain_name
76
+ end
77
+ end
78
+
79
+
59
80
  # Return a hash of response headers from the
60
81
  # given curl result.
61
82
  # TODO: Submit as a pull request to the Curb gem.
@@ -0,0 +1,18 @@
1
+ require 'rspec/webservice_matchers'
2
+
3
+ #
4
+ # TODO: set up a test server or mocks for these.
5
+ #
6
+ describe 'status_code' do
7
+ it 'can check 200 for successful resource requests' do
8
+ 'http://www.rfc-editor.org/rfc/rfc2616.txt'.should be_status 200
9
+ end
10
+
11
+ it 'handles domain names as well as URLs' do
12
+ 'www.rfc-editor.org'.should be_status 200
13
+ end
14
+
15
+ it 'can check 503 for the Service Unavailable status' do
16
+ '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
17
+ end
18
+ end
metadata CHANGED
@@ -1,69 +1,69 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-webservice_matchers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
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-01-17 00:00:00.000000000 Z
11
+ date: 2014-01-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.3'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.3'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: curb
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ~>
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0.8'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ~>
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0.8'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rspec
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ~>
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
61
  version: '2'
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ~>
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '2'
69
69
  description: Black-box web app configuration testing
@@ -73,7 +73,7 @@ executables: []
73
73
  extensions: []
74
74
  extra_rdoc_files: []
75
75
  files:
76
- - .gitignore
76
+ - ".gitignore"
77
77
  - Gemfile
78
78
  - LICENSE.txt
79
79
  - README.md
@@ -81,6 +81,7 @@ files:
81
81
  - lib/rspec/webservice_matchers.rb
82
82
  - lib/rspec/webservice_matchers/version.rb
83
83
  - rspec-webservice_matchers.gemspec
84
+ - spec/rspec/webservice_matchers/protcol_spec.rb
84
85
  - spec/rspec/webservice_matchers/redirect_spec.rb
85
86
  - spec/rspec/webservice_matchers/ssl_spec.rb
86
87
  homepage: https://github.com/dogweather/rspec-webservice_matchers
@@ -93,12 +94,12 @@ require_paths:
93
94
  - lib
94
95
  required_ruby_version: !ruby/object:Gem::Requirement
95
96
  requirements:
96
- - - '>='
97
+ - - ">="
97
98
  - !ruby/object:Gem::Version
98
99
  version: '0'
99
100
  required_rubygems_version: !ruby/object:Gem::Requirement
100
101
  requirements:
101
- - - '>='
102
+ - - ">="
102
103
  - !ruby/object:Gem::Version
103
104
  version: '0'
104
105
  requirements: []
@@ -108,5 +109,6 @@ signing_key:
108
109
  specification_version: 4
109
110
  summary: Black-box web app configuration testing
110
111
  test_files:
112
+ - spec/rspec/webservice_matchers/protcol_spec.rb
111
113
  - spec/rspec/webservice_matchers/redirect_spec.rb
112
114
  - spec/rspec/webservice_matchers/ssl_spec.rb