webspicy 0.13.0 → 0.14.0

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
- SHA256:
3
- metadata.gz: df662e6e4d8e94403071753f7f4e3a61919bf6fc8e5913316b847fee3b03d9d3
4
- data.tar.gz: 4e18c04cff9b572d4173a267590f6e91cbfe1bbbf40236944c7fad50edff88dc
2
+ SHA1:
3
+ metadata.gz: 5b78ed1d162fe75c83bd7bffa819b61ec7153dab
4
+ data.tar.gz: c5a6ba9ee1d76e1e861d1952fd135664a5e1b408
5
5
  SHA512:
6
- metadata.gz: 997f7223ba296843ff3ef1c4acaeed45815921c88e03ae756d7e27cf0c4ab60b3a644ddea34e0ac3df4bed41c3472a1135ac15801efc0052cca0c190ca5aceee
7
- data.tar.gz: b1cdceb0a8a3b9bc756e2f7a763b4e529c4bb370d7db916d83c273f6e692cb08aa652f296571d846f3112c344d144f03117fecab9d21c7b622c0ed5867231af6
6
+ metadata.gz: 31da61f468c86496d77f1eb659e17e4b02ec4de80ba14e6a6220a26cde324c9b0113099c4457f45a05be378ccd2acbaba172268fe60000172704c992623a8554
7
+ data.tar.gz: a347f32c634c884cfdb29ee92e5a4b0d6ca5134b9f9ec95ac8ee604e244ac3f332fc71b846e47c9a3744febcf63fcc631c0f7a0cf1cc452f880f25370c2a3406
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ../..
3
3
  specs:
4
- webspicy (0.13.0)
4
+ webspicy (0.14.0)
5
5
  finitio (>= 0.8.0)
6
6
  http (~> 2)
7
7
  mustermann (~> 1.0)
@@ -28,6 +28,8 @@ services:
28
28
 
29
29
  - description: |-
30
30
  when requested with a valid CSV file
31
+ tags:
32
+ - upload
31
33
  file_upload:
32
34
  path: ./todos.csv
33
35
  content_type: "text/csv"
@@ -14,6 +14,7 @@ module Webspicy
14
14
  @run_counterexamples = default_run_counterexamples
15
15
  @file_filter = default_file_filter
16
16
  @service_filter = default_service_filter
17
+ @test_case_filter = default_test_case_filter
17
18
  @client = HttpClient
18
19
  Path.require_tree(folder/'support') if (folder/'support').exists?
19
20
  yield(self) if block_given?
@@ -152,7 +153,10 @@ module Webspicy
152
153
  # set. In that case, a file filter is set that matches the file name to the
153
154
  # variable value, through a regular expression.
154
155
  def default_file_filter
155
- ENV['RESOURCE'] ? Regexp.compile(ENV['RESOURCE']) : nil
156
+ return nil unless res = ENV['RESOURCE']
157
+ negated = res =~ /^!/
158
+ rx = Regexp.compile(negated ? "#{res[1..-1]}" : res)
159
+ negated ? ->(f){ !(f.to_s =~ rx) } : rx
156
160
  end
157
161
  private :default_file_filter
158
162
 
@@ -171,7 +175,7 @@ module Webspicy
171
175
  end
172
176
  attr_reader :service_filter
173
177
 
174
- # Returns the default service filters.
178
+ # Returns the default service filter.
175
179
  #
176
180
  # By default no filter is set unless a METHOD environment variable is set.
177
181
  # In that case, a service filter is returned that filters the services whose
@@ -181,6 +185,35 @@ module Webspicy
181
185
  end
182
186
  private :default_service_filter
183
187
 
188
+ # Installs a test case filter.
189
+ #
190
+ # A test case filter can be added to restrict the scope attention only to
191
+ # the test cases that match the service installed. Supported values are:
192
+ #
193
+ # - Proc: each test case is passed in turn. Only test cases for which a
194
+ # truthy value is returned will be considered by the scope.
195
+ # - ===: any instance responding to `===` can be used as a matcher, following
196
+ # Ruby conventions. The match is done on a Service instance.
197
+ def test_case_filter=(tag_filter)
198
+ @test_case_filter = test_case_filter
199
+ end
200
+ attr_reader :test_case_filter
201
+
202
+ # Returns the default test case filter.
203
+ #
204
+ # By default no filter is set unless a TAG environment variable is set.
205
+ # In that case, a test case filter is returned that filters the test cases
206
+ # whose tags map the specified value.
207
+ def default_test_case_filter
208
+ return nil unless tags = ENV['TAG']
209
+ no, yes = tags.split(/\s*,\s*/).partition{|t| t =~ /^!/ }
210
+ no, yes = no.map{|t| t[1..-1 ]}, yes
211
+ ->(tc){
212
+ (yes.empty? || !(yes & tc.tags).empty?) \
213
+ && \
214
+ (no.empty? || (no & tc.tags).empty?)
215
+ }
216
+ end
184
217
 
185
218
  # Installs a client class to use to invoke web services for real.
186
219
  #
@@ -1,6 +1,8 @@
1
1
  Method =
2
2
  String( s | s =~ /^(GET|POST|POST_FORM|PUT|DELETE|PATCH|OPTIONS)$/ )
3
3
 
4
+ Tag = String( s | s.length > 0 )
5
+
4
6
  Schema =
5
7
  .Finitio::System <fio> String
6
8
  \( s | ::Webspicy.schema(s) )
@@ -53,6 +55,7 @@ TestCase =
53
55
  headers :? .Hash
54
56
  }
55
57
  assert :? [String]
58
+ tags :? [Tag]
56
59
  }
57
60
 
58
61
  Params = .Array|.Hash
@@ -32,6 +32,10 @@ module Webspicy
32
32
  @raw[:metadata] ||= {}
33
33
  end
34
34
 
35
+ def tags
36
+ @raw[:tags] ||= []
37
+ end
38
+
35
39
  def dress_params
36
40
  @raw.fetch(:dress_params){ true }
37
41
  end
@@ -47,20 +47,20 @@ module Webspicy
47
47
  end
48
48
 
49
49
  def each_example(service)
50
- service.examples.each{|e|
50
+ service.examples.select(&to_filter_proc(config.test_case_filter)).each{|e|
51
51
  yield(expand_example(service, e), false)
52
52
  }
53
53
  end
54
54
 
55
55
  def each_counterexamples(service, &bl)
56
- service.counterexamples.each{|e|
56
+ service.counterexamples.select(&to_filter_proc(config.test_case_filter)).each{|e|
57
57
  yield(expand_example(service, e), true)
58
58
  } if config.run_counterexamples?
59
59
  end
60
60
 
61
61
  def each_generated_counterexamples(service, &bl)
62
62
  Webspicy.with_scope(self) do
63
- service.generated_counterexamples.each{|e|
63
+ service.generated_counterexamples.select(&to_filter_proc(config.test_case_filter)).each{|e|
64
64
  yield(expand_example(service, e), true)
65
65
  }
66
66
  end if config.run_counterexamples?
@@ -1,7 +1,7 @@
1
1
  module Webspicy
2
2
  module Version
3
3
  MAJOR = 0
4
- MINOR = 13
4
+ MINOR = 14
5
5
  TINY = 0
6
6
  end
7
7
  VERSION = "#{Version::MAJOR}.#{Version::MINOR}.#{Version::TINY}"
@@ -111,9 +111,19 @@ module Webspicy
111
111
  ENV['RESOURCE'] = 'getTodo.yml'
112
112
  config = Configuration.new
113
113
  expect(config.file_filter).to be_a(Regexp)
114
+ expect(config.file_filter).to match("foo/bar/getTodo.yml")
115
+ expect(config.file_filter).not_to match("foo/bar/getTodos.yml")
114
116
  end
115
117
 
116
- it 'ignores the environment is set explicitly' do
118
+ it 'allows expressing a no match' do
119
+ ENV['RESOURCE'] = '!getTodo.yml'
120
+ config = Configuration.new
121
+ expect(config.file_filter).to be_a(Proc)
122
+ expect(config.file_filter.call("foo/bar/getTodos.yml")).to eq(true)
123
+ expect(config.file_filter.call("foo/bar/getTodo.yml")).to eq(false)
124
+ end
125
+
126
+ it 'ignores the environment if set explicitly' do
117
127
  ENV['RESOURCE'] = 'getTodo.yml'
118
128
  config = Configuration.new do |c|
119
129
  c.file_filter = nil
@@ -144,6 +154,68 @@ module Webspicy
144
154
  end
145
155
  end
146
156
 
157
+ describe 'test_case_filter' do
158
+
159
+ let(:tc){ OpenStruct.new(tags: ["foo", "bar"]) }
160
+
161
+ subject {
162
+ Configuration.new.test_case_filter
163
+ }
164
+
165
+ it 'is nil by default' do
166
+ expect(subject).to be_nil
167
+ end
168
+
169
+ it 'allows setting a single tag' do
170
+ ENV['TAG'] = 'foo'
171
+ expect(subject).to be_a(Proc)
172
+ expect(subject.call(tc)).to eql(true)
173
+ end
174
+
175
+ it 'allows no matching a single tag' do
176
+ ENV['TAG'] = 'baz'
177
+ expect(subject).to be_a(Proc)
178
+ expect(subject.call(tc)).to eql(false)
179
+ end
180
+
181
+ it 'allows setting multiple tags' do
182
+ ENV['TAG'] = 'foo,baz'
183
+ expect(subject).to be_a(Proc)
184
+ expect(subject.call(tc)).to eql(true)
185
+ end
186
+
187
+ it 'allows no matching any of multiple tags' do
188
+ ENV['TAG'] = 'foi,baz'
189
+ expect(subject).to be_a(Proc)
190
+ expect(subject.call(tc)).to eql(false)
191
+ end
192
+
193
+ it 'allows setting a single negative tag' do
194
+ ENV['TAG'] = '!foo'
195
+ expect(subject).to be_a(Proc)
196
+ expect(subject.call(tc)).to eql(false)
197
+ end
198
+
199
+ it 'allows not matching a single negative tag' do
200
+ ENV['TAG'] = '!baz'
201
+ expect(subject).to be_a(Proc)
202
+ expect(subject.call(tc)).to eql(true)
203
+ end
204
+
205
+ it 'allows mixing positive & negative tags and have a match' do
206
+ ENV['TAG'] = 'foo,!baz'
207
+ expect(subject).to be_a(Proc)
208
+ expect(subject.call(tc)).to eql(true)
209
+ end
210
+
211
+ it 'allows mixing positive & negative tags and have no match' do
212
+ ENV['TAG'] = 'foo,!bar'
213
+ expect(subject).to be_a(Proc)
214
+ expect(subject.call(tc)).to eql(false)
215
+ end
216
+
217
+ end
218
+
147
219
  describe 'before/after/listeners' do
148
220
 
149
221
  let(:before_eacher) { ->(){} }
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.13.0
4
+ version: 0.14.0
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-01-21 00:00:00.000000000 Z
11
+ date: 2020-02-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -259,7 +259,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
259
259
  - !ruby/object:Gem::Version
260
260
  version: '0'
261
261
  requirements: []
262
- rubygems_version: 3.1.0.pre1
262
+ rubyforge_project:
263
+ rubygems_version: 2.6.11
263
264
  signing_key:
264
265
  specification_version: 4
265
266
  summary: Webspicy helps testing web services as software operation black boxes!