webspicy 0.15.3 → 0.15.4

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
  SHA256:
3
- metadata.gz: d510f36443e5ef38eaabf4c09c6286c1e1aa556a9bb67fd5f5b67303b1faef4c
4
- data.tar.gz: bb8b064c714f10bef673d6e61fa0fe71037d8b0e0f8479a4bdb874bbce5484e6
3
+ metadata.gz: e8b9e1294df7f1eebb306f79f9fc39230a29217a8578b686ab3c9664e542466a
4
+ data.tar.gz: c5c07c651e3790c4016c7ffa5647f8b1bc78311b86bcef2a16e3a127be588bbd
5
5
  SHA512:
6
- metadata.gz: dce79c2eba1d8fa74408280cabc8d06eee163fc4f1e8d5b8dfbfb1d4f167063dba68c54a0b1f18d4a72ac2ae88baa5f1a169f9f54b9073cce2c1174efd0b02a8
7
- data.tar.gz: b0665863864804a9977c73f25eb22d12930cf623e0db3bf67ea07a15d81162434ecf0e5cf1c12007abba6a6d1ea37f8fdb91cb99afa82893fd4e0b15c7d98ec6
6
+ metadata.gz: 21e6a2e43bf83a096cd0d77b94a1677d142599cc8f7842cf69202ef489bb4fe8b5c3266460c8ab758ee77d6a0cca6100aa9e5cc9bf34cc18ccf45d427de41cac
7
+ data.tar.gz: 62bb90f71538abd9132d7925ae861f2f80c1def589246e6838f5f39ea9cf8e15cb75c5cbd315d88a54b0a410decbc5743c1ec1a5686485c6d84a1753ca89382a
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ../..
3
3
  specs:
4
- webspicy (0.15.3)
4
+ webspicy (0.15.4)
5
5
  finitio (>= 0.8.0)
6
6
  http (>= 2)
7
7
  mustermann (~> 1.0)
@@ -14,6 +14,7 @@ module Webspicy
14
14
  ### Load library
15
15
  ###
16
16
 
17
+ require 'webspicy/support'
17
18
  require 'webspicy/configuration'
18
19
  require 'webspicy/file_upload'
19
20
  require 'webspicy/scope'
@@ -11,6 +11,7 @@ module Webspicy
11
11
  @postconditions = []
12
12
  @listeners = Hash.new{|h,k| h[k] = [] }
13
13
  @rspec_options = default_rspec_options
14
+ @run_examples = default_run_examples
14
15
  @run_counterexamples = default_run_counterexamples
15
16
  @file_filter = default_file_filter
16
17
  @service_filter = default_service_filter
@@ -94,6 +95,23 @@ module Webspicy
94
95
  !children.empty?
95
96
  end
96
97
 
98
+ # Sets whether examples have to be ran or not.
99
+ def run_examples=(run_examples)
100
+ @run_examples = run_examples
101
+ end
102
+ attr_reader :run_examples
103
+
104
+ # Whether counter examples must be ran or not.
105
+ def run_examples?
106
+ @run_examples
107
+ end
108
+
109
+ # Returns the defaut value for run_examples
110
+ def default_run_examples
111
+ ENV['ROBUST'].nil? || (ENV['ROBUST'] != 'only')
112
+ end
113
+ private :default_run_examples
114
+
97
115
  # Sets whether counter examples have to be ran or not.
98
116
  def run_counterexamples=(run_counterexamples)
99
117
  @run_counterexamples = run_counterexamples
@@ -51,7 +51,7 @@ TestCase =
51
51
  requester :? String
52
52
  metadata :? { ...: .Object }
53
53
  expected :? {
54
- status :? Integer
54
+ status :? StatusRange
55
55
  content_type :? String|Nil
56
56
  error :? String
57
57
  headers :? .Hash
@@ -61,3 +61,7 @@ TestCase =
61
61
  }
62
62
 
63
63
  Params = .Array|.Hash
64
+
65
+ StatusRange = .Webspicy::Support::StatusRange
66
+ <int> Integer
67
+ <str> String(s | s =~ /^\dxx$/ )
@@ -57,7 +57,7 @@ module Webspicy
57
57
 
58
58
  def best_status_code(service)
59
59
  if ex = service.examples.first
60
- ex.expected_status || 200
60
+ (ex.expected_status && ex.expected_status.to_i) || 200
61
61
  else
62
62
  200
63
63
  end
@@ -53,7 +53,7 @@ module Webspicy
53
53
  end
54
54
 
55
55
  def is_expected_success?
56
- test_case.expected_status >= 200 && test_case.expected_status < 300
56
+ test_case.expected_status.to_i >= 200 && test_case.expected_status.to_i < 300
57
57
  end
58
58
 
59
59
  def is_success?
@@ -73,7 +73,7 @@ module Webspicy
73
73
  def expected_status_unmet
74
74
  expected = test_case.expected_status
75
75
  got = response.status
76
- expected == got ? nil : "#{expected} != #{got}"
76
+ expected === got ? nil : "#{expected} != #{got}"
77
77
  end
78
78
 
79
79
  def meets_expected_status?
@@ -89,7 +89,7 @@ module Webspicy
89
89
  if ect.nil?
90
90
  got.nil? ? nil : "#{ect} != #{got}"
91
91
  else
92
- ect.to_s == got.to_s ? nil : "#{ect} != #{got}"
92
+ got.to_s.start_with?(ect.to_s) ? nil : "#{ect} != #{got}"
93
93
  end
94
94
  end
95
95
 
@@ -82,7 +82,7 @@ module Webspicy
82
82
  end
83
83
 
84
84
  def is_expected_status?(status)
85
- expected_status == status
85
+ expected_status === status
86
86
  end
87
87
 
88
88
  def expected_error
@@ -49,7 +49,7 @@ module Webspicy
49
49
  def each_example(service)
50
50
  service.examples.select(&to_filter_proc(config.test_case_filter)).each{|e|
51
51
  yield(expand_example(service, e))
52
- }
52
+ } if config.run_examples?
53
53
  end
54
54
 
55
55
  def each_counterexamples(service, &bl)
@@ -0,0 +1 @@
1
+ require_relative 'support/status_range'
@@ -0,0 +1,46 @@
1
+ module Webspicy
2
+ module Support
3
+ class StatusRange
4
+
5
+ def initialize(range)
6
+ @range = range
7
+ end
8
+ attr_reader :range
9
+
10
+ def self.int(i)
11
+ new(i..i)
12
+ end
13
+
14
+ def to_int
15
+ @range.first
16
+ end
17
+
18
+ def self.str(s)
19
+ from = s[/^(\d)/,1].to_i * 100
20
+ new(from...from+100)
21
+ end
22
+
23
+ def to_str
24
+ "#{@range.first/100}xx"
25
+ end
26
+
27
+ def to_i
28
+ @range.first
29
+ end
30
+
31
+ def ===(status)
32
+ range === status
33
+ end
34
+
35
+ def ==(other)
36
+ other.is_a?(StatusRange) && self.range == other.range
37
+ end
38
+ alias :eql? :==
39
+
40
+ def hash
41
+ @range.hash
42
+ end
43
+
44
+ end # class StatusRange
45
+ end # module Support
46
+ end # module Webspicy
@@ -2,7 +2,7 @@ module Webspicy
2
2
  module Version
3
3
  MAJOR = 0
4
4
  MINOR = 15
5
- TINY = 3
5
+ TINY = 4
6
6
  end
7
7
  VERSION = "#{Version::MAJOR}.#{Version::MINOR}.#{Version::TINY}"
8
8
  end
@@ -53,7 +53,7 @@ module Webspicy
53
53
  expect(subject).to be_a(Resource::Service::TestCase)
54
54
  expect(subject.description).to eql("Hello world")
55
55
  expect(subject.expected).to eql({
56
- status: 200,
56
+ status: Support::StatusRange.int(200),
57
57
  content_type: "application/json"
58
58
  })
59
59
  end
@@ -0,0 +1,29 @@
1
+ require "spec_helper"
2
+ module Webspicy
3
+ module Support
4
+ describe StatusRange do
5
+
6
+ it 'has a int information contract' do
7
+ expect(StatusRange.int(100).range).to eql(100..100)
8
+ expect(StatusRange.int(100).to_int).to eql(100)
9
+ end
10
+
11
+ it 'has a str information contract' do
12
+ expect(StatusRange.str("3xx").range).to eql(300...400)
13
+ expect(StatusRange.str("3xx").to_str).to eql("3xx")
14
+ end
15
+
16
+ it 'has a to_i that returns the first status of the range' do
17
+ expect(StatusRange.int(300).to_i).to eql(300)
18
+ expect(StatusRange.str("3xx").to_i).to eql(300)
19
+ end
20
+
21
+ it 'has a matching method' do
22
+ expect(StatusRange.str("3xx") === 300).to eql(true)
23
+ expect(StatusRange.str("3xx") === 302).to eql(true)
24
+ expect(StatusRange.str("3xx") === 400).to eql(false)
25
+ end
26
+
27
+ end
28
+ end
29
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: webspicy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.15.3
4
+ version: 0.15.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bernard Lambeau
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-05-05 00:00:00.000000000 Z
11
+ date: 2020-05-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -224,6 +224,8 @@ files:
224
224
  - lib/webspicy/resource/service/invocation.rb
225
225
  - lib/webspicy/resource/service/test_case.rb
226
226
  - lib/webspicy/scope.rb
227
+ - lib/webspicy/support.rb
228
+ - lib/webspicy/support/status_range.rb
227
229
  - lib/webspicy/tester.rb
228
230
  - lib/webspicy/tester/asserter.rb
229
231
  - lib/webspicy/tester/assertions.rb
@@ -239,6 +241,7 @@ files:
239
241
  - spec/unit/scope/test_expand_example.rb
240
242
  - spec/unit/scope/test_to_real_url.rb
241
243
  - spec/unit/spec_helper.rb
244
+ - spec/unit/support/test_status_range.rb
242
245
  - spec/unit/test_configuration.rb
243
246
  - spec/unit/tester/test_assertions.rb
244
247
  - tasks/gem.rake