rspec-webservice_matchers 4.8.1 → 4.9.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: ba8fd43304c72ef0e625db7c2f709e2accfb5782
4
- data.tar.gz: 6a7a8ae73935d83c4ae0dd074967a9dd8e957fa6
3
+ metadata.gz: f930e26ec837ba1ca066f2a911608b5c58edfc09
4
+ data.tar.gz: 0c2be7eae06450c998838d3e1530421ee9dcb6b2
5
5
  SHA512:
6
- metadata.gz: 7bf79fe28ee47a785d482d14badcb0c016d7960715dd31e1db673ba23ec13973a6f78ecf361d4608d56eb905f9af598ff904b51c366b12cd4e33cbdbf0b4eba9
7
- data.tar.gz: a7f7d3973bce00278dd1ef361cce87ec738eaedd873d82a1f48ef07bef0644edde260f362830864a973c158181562b9ae412fd67cf5cc204f9b5449ae0d73522
6
+ metadata.gz: 702e17e06e648086ce8c75c2838eb3997a7d44ccb741af282d22b46785fc5d44862966713e788c54acbe908f2290469fb170754c0fec303b8218dab3bfa7197b
7
+ data.tar.gz: 88be96f4ae2de62c765bb0a9fd6bc621e0024b6513ba945700922adeb4e76031f9b3e9ab04e9ed1247cb928bf305ee335679a4c9a96128245e44ab721c7c6ec6
data/HISTORY.md CHANGED
@@ -1,3 +1,11 @@
1
+ 4.9.0
2
+ -----
3
+ Adds new API for `be_fast`.
4
+
5
+ 4.8.1
6
+ -----
7
+ Fixes require bug.
8
+
1
9
  4.8.0
2
10
  -----
3
11
  Adds the new public API, beginning with the `be_up` matcher.
@@ -1,11 +1,23 @@
1
1
  # frozen_string_literal: true
2
2
  require 'cgi'
3
3
  require 'json'
4
+ require 'rspec/matchers'
4
5
  require 'rspec/webservice_matchers/util'
6
+ require 'validated_object'
5
7
 
6
8
  module RSpec
7
9
  module WebserviceMatchers
8
10
  module BeFast
11
+
12
+ class TestResult < ValidatedObject::Base
13
+ attr_accessor :success, :score
14
+ alias success? success
15
+
16
+ validates :success, inclusion: [true, false]
17
+ validates :score, inclusion: (0..100)
18
+ end
19
+
20
+
9
21
  def self.parse(json:)
10
22
  response = JSON.parse(json)
11
23
  unless response.key?('ruleGroups')
@@ -29,12 +41,21 @@ module RSpec
29
41
  BeFast.parse(json: response.body).fetch(:score)
30
42
  end
31
43
 
44
+ def self.test(url:)
45
+ TestResult.new do |r|
46
+ r.score = BeFast.page_speed_score(url: url)
47
+ r.success = r.score >= 85
48
+ end
49
+ end
50
+
51
+
32
52
  RSpec::Matchers.define :be_fast do
33
53
  score = nil
34
54
 
35
55
  match do |url|
36
- score = BeFast.page_speed_score(url: url)
37
- score >= 85
56
+ result = BeFast.test(url: url)
57
+ score = result.score
58
+ result.success?
38
59
  end
39
60
 
40
61
  failure_message do
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+ require 'rspec/matchers'
2
3
  require 'rspec/webservice_matchers/util'
3
4
  require 'validated_object'
4
5
 
@@ -18,7 +19,7 @@ module RSpec
18
19
 
19
20
  def self.test(url:nil, domain:nil)
20
21
  raise 'Must specify a url or domain' if url.nil? && domain.nil?
21
-
22
+
22
23
  TestResult.new do |r|
23
24
  r.status_code = Util.status(url || domain, follow: true)
24
25
  r.success = (r.status_code == 200)
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
  require 'rspec/webservice_matchers/util'
3
+ require 'rspec/matchers'
3
4
 
4
5
  module RSpec
5
6
  module WebserviceMatchers
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
  module RSpec
3
3
  module WebserviceMatchers
4
- VERSION = '4.8.1'
4
+ VERSION = '4.9.0'
5
5
  end
6
6
  end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+ require 'spec_helper'
3
+ require 'rspec/webservice_matchers/be_fast'
4
+ include RSpec::WebserviceMatchers
5
+
6
+ describe BeFast do
7
+ describe BeFast::TestResult do
8
+ it 'requires :success' do
9
+ expect {
10
+ BeFast::TestResult.new {}
11
+ }.to raise_error(ArgumentError, /success/i)
12
+ end
13
+
14
+ it 'requires :score' do
15
+ expect {
16
+ BeFast::TestResult.new { |r| r.success = true }
17
+ }.to raise_error(ArgumentError, /score/i)
18
+ end
19
+ end
20
+
21
+ describe '#test' do
22
+ it 'handles a fast site' do
23
+ result = BeFast.test url: 'http://nonstop.qa'
24
+ expect( result.success? ).to be true
25
+ expect( result.score ).to be >= 85
26
+ end
27
+ end
28
+ end
@@ -2,9 +2,9 @@
2
2
  require 'spec_helper'
3
3
  require 'rspec/webservice_matchers/be_up'
4
4
 
5
- include RSpec::WebserviceMatchers::BeUp
5
+ include RSpec::WebserviceMatchers
6
6
 
7
- describe RSpec::WebserviceMatchers::BeUp do
7
+ describe BeUp do
8
8
  describe '#test' do
9
9
  it 'handles a simple 200' do
10
10
  result = BeUp.test url: 'http://www.website.com/'
@@ -26,30 +26,30 @@ describe RSpec::WebserviceMatchers::BeUp do
26
26
  end
27
27
 
28
28
 
29
- describe TestResult do
29
+ describe BeUp::TestResult do
30
30
  it 'requires :success' do
31
31
  expect {
32
- TestResult.new { |r| r.status_code = 200 }
32
+ BeUp::TestResult.new { |r| r.status_code = 200 }
33
33
  }.to raise_error(ArgumentError)
34
34
  end
35
35
 
36
36
  it 'requires :status_code' do
37
37
  expect {
38
- TestResult.new { |r| r.success = true }
38
+ BeUp::TestResult.new { |r| r.success = true }
39
39
  }.to raise_error(ArgumentError)
40
40
  end
41
41
 
42
42
  it 'accepts boolean :success & integer :status_code' do
43
- result = TestResult.new do |r|
43
+ result = BeUp::TestResult.new do |r|
44
44
  r.status_code = 404
45
45
  r.success = false
46
46
  end
47
- expect( result ).to be_an_instance_of(TestResult)
47
+ expect( result ).to be_an_instance_of(BeUp::TestResult)
48
48
  end
49
49
 
50
50
  it 'requires boolean :success' do
51
51
  expect {
52
- TestResult.new do |r|
52
+ BeUp::TestResult.new do |r|
53
53
  r.status_code = 200
54
54
  r.success = 1
55
55
  end
@@ -58,7 +58,7 @@ describe RSpec::WebserviceMatchers::BeUp do
58
58
 
59
59
  it 'requires integer :status_code' do
60
60
  expect {
61
- TestResult.new do |r|
61
+ BeUp::TestResult.new do |r|
62
62
  r.status_code = '404'
63
63
  r.success = false
64
64
  end
@@ -67,7 +67,7 @@ describe RSpec::WebserviceMatchers::BeUp do
67
67
 
68
68
  it 'cannot have status < 100' do
69
69
  expect {
70
- TestResult.new do |r|
70
+ BeUp::TestResult.new do |r|
71
71
  r.status_code = -5
72
72
  r.success = false
73
73
  end
@@ -76,7 +76,7 @@ describe RSpec::WebserviceMatchers::BeUp do
76
76
 
77
77
  it 'cannot have status > 510' do
78
78
  expect {
79
- TestResult.new do |r|
79
+ BeUp::TestResult.new do |r|
80
80
  r.status_code = 511
81
81
  r.success = false
82
82
  end
@@ -84,11 +84,11 @@ describe RSpec::WebserviceMatchers::BeUp do
84
84
  end
85
85
 
86
86
  it 'allows status 510' do
87
- result = TestResult.new do |r|
87
+ result = BeUp::TestResult.new do |r|
88
88
  r.status_code = 510
89
89
  r.success = false
90
90
  end
91
- expect( result ).to be_an_instance_of(TestResult)
91
+ expect( result ).to be_an_instance_of(BeUp::TestResult)
92
92
  end
93
93
  end
94
94
  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: 4.8.1
4
+ version: 4.9.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: 2016-03-29 00:00:00.000000000 Z
11
+ date: 2016-03-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -177,6 +177,7 @@ files:
177
177
  - lib/rspec/webservice_matchers/version.rb
178
178
  - rspec-webservice_matchers.gemspec
179
179
  - spec/fixtures/pagespeed.json
180
+ - spec/rspec/webservice_matchers/be_fast_spec.rb
180
181
  - spec/rspec/webservice_matchers/be_up_spec.rb
181
182
  - spec/rspec/webservice_matchers/page_speed_spec.rb
182
183
  - spec/rspec/webservice_matchers/protcol_spec.rb
@@ -210,6 +211,7 @@ specification_version: 4
210
211
  summary: Black-box web app configuration testing
211
212
  test_files:
212
213
  - spec/fixtures/pagespeed.json
214
+ - spec/rspec/webservice_matchers/be_fast_spec.rb
213
215
  - spec/rspec/webservice_matchers/be_up_spec.rb
214
216
  - spec/rspec/webservice_matchers/page_speed_spec.rb
215
217
  - spec/rspec/webservice_matchers/protcol_spec.rb