webspicy 0.20.6 → 0.20.11

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
  SHA256:
3
- metadata.gz: 013055707cad05016cb794561d47a0408d39d6f462387c9eb66d31542ff2218c
4
- data.tar.gz: b4c4778275ec96271b711ea0956c539fa35bf12b04d635fbc5062698996e7902
3
+ metadata.gz: 7eba5a8dc97e7c8f2053da2c52e45d728d1de38777ac2088db74aa2852f0ab8a
4
+ data.tar.gz: dfd0330f95b8c9e64b63919820b7b48ba1dc0f4a7696ba03877670f41a8812b3
5
5
  SHA512:
6
- metadata.gz: fcc079537f13b76af0e433c8591529824ea1e4f8b255f1411963e88cbd4df6953598504413dc8ad3da6db3005cf2c49867e80790594e3fb56cab039f2de450c7
7
- data.tar.gz: e4479277fcec22a0928ae75a0120bc5c0a9644e73be6bb75a577dd33a42a03c445996b9b846a33bd20e6e439b4047a8f3ab4a418abb965777b4ce047e1824d7e
6
+ metadata.gz: 243d021ca1344f09880a3fbda147c38dbacb8791c3e8f541acb524992f6c3e15bb997fbb4423b06c504c95f7a85079fa24d329379b8368cc0b04b11a0a0ab028
7
+ data.tar.gz: 47a7462b3b080b276f594b0b1df054488fa69c60038c51d2d22a664aeb83ada0c390380de1497a30d0f990bd97638fbc3acdfc636eb8fbe227e37d3c1512f6f0
@@ -447,7 +447,7 @@ module Webspicy
447
447
  @reporter << Tester::Reporter::Documentation.new
448
448
  @reporter << Tester::Reporter::Exceptions.new
449
449
  @reporter << Tester::Reporter::Summary.new
450
- @reporter << Tester::Reporter::ErrorCount.new
450
+ @reporter << Tester::Reporter::SuccessOrNot.new
451
451
  end
452
452
  attr_accessor :reporter
453
453
 
@@ -14,6 +14,10 @@ module Webspicy
14
14
  @location = Path(location)
15
15
  end
16
16
 
17
+ def relative_location
18
+ @location && @location.relative_to(config.folder)
19
+ end
20
+
17
21
  def locate(relative_path)
18
22
  file = @location.parent/relative_path
19
23
  raise "File not found: #{file}" unless file.exists?
@@ -21,7 +25,7 @@ module Webspicy
21
25
  end
22
26
 
23
27
  def name
24
- @raw[:name]
28
+ @raw[:name] || relative_location || "Unnamed"
25
29
  end
26
30
 
27
31
  def services
@@ -38,12 +38,12 @@ module Webspicy
38
38
  rescue FailFast
39
39
  end
40
40
  reporter.report
41
- reporter.find(Reporter::ErrorCount).report
41
+ reporter.find(Reporter::SuccessOrNot).report
42
42
  end
43
43
 
44
44
  def call!
45
45
  res = call
46
- abort("KO") unless res == 0
46
+ abort("KO") unless reporter.find(Reporter::SuccessOrNot).success?
47
47
  end
48
48
 
49
49
  def find_and_call(method, url, mutation)
@@ -149,6 +149,8 @@ module Webspicy
149
149
  end
150
150
 
151
151
  def call_test_case_target
152
+ @invocation = nil
153
+ @invocation_error = nil
152
154
  reporter.before_invocation
153
155
  @invocation = client.call(test_case)
154
156
  reporter.invocation_done
@@ -0,0 +1,39 @@
1
+ module Webspicy
2
+ class Tester
3
+ class Fakesendgrid
4
+ include Webspicy::Support::World::Item
5
+
6
+ DEFAULT_OPTIONS = {
7
+ endpoint: "http://fakesendgrid"
8
+ }
9
+
10
+ def initialize(options = {})
11
+ @options = DEFAULT_OPTIONS.merge(options)
12
+ end
13
+ attr_reader :options
14
+
15
+ def endpoint
16
+ options[:endpoint]
17
+ end
18
+
19
+ def clear!
20
+ res = HTTP.delete("#{endpoint}/api/mails")
21
+ end
22
+
23
+ def emails
24
+ res = HTTP.get("#{endpoint}/api/mails")
25
+ JSON.parse(res.body).map{|data| Email.new(data) }
26
+ end
27
+
28
+ def emails_count
29
+ emails.length
30
+ end
31
+
32
+ def last_email
33
+ emails.first
34
+ end
35
+
36
+ end # class Fakesendgrid
37
+ end # class Tester
38
+ end # module Webspicy
39
+ require_relative 'fakesendgrid/email'
@@ -0,0 +1,29 @@
1
+ module Webspicy
2
+ class Tester
3
+ class Fakesendgrid
4
+ class Email
5
+
6
+ def initialize(data)
7
+ @data = data
8
+ end
9
+ attr_reader :data
10
+
11
+ def from
12
+ @from ||= data["from"]["email"]
13
+ end
14
+
15
+ def to
16
+ @to ||= data["personalizations"]
17
+ .select{|h| h.key? "to" }
18
+ .map{|(h)| h["to"] }
19
+ .map{|(h)| h["email"] }
20
+ end
21
+
22
+ def subject
23
+ @subject ||= data["subject"]
24
+ end
25
+
26
+ end # class Email
27
+ end # class Fakesendgrid
28
+ end # class Tester
29
+ end # module Webspicy
@@ -30,7 +30,7 @@ module Webspicy
30
30
  end
31
31
 
32
32
  def last_email
33
- emails.last
33
+ emails.first
34
34
  end
35
35
 
36
36
  end # class Fakesmtp
@@ -7,7 +7,7 @@ module Webspicy
7
7
  @reporter << Reporter::FileProgress.new
8
8
  @reporter << Reporter::Exceptions.new
9
9
  @reporter << Reporter::FileSummary.new
10
- @reporter << Reporter::ErrorCount.new
10
+ @reporter << Reporter::SuccessOrNot.new
11
11
  end
12
12
 
13
13
  def run_scope
@@ -80,7 +80,6 @@ module Webspicy
80
80
  end # class Reporter
81
81
  end # class Tester
82
82
  end # module Webspicy
83
- require_relative 'reporter/error_count'
84
83
  require_relative 'reporter/progress'
85
84
  require_relative 'reporter/summary'
86
85
  require_relative 'reporter/documentation'
@@ -88,3 +87,5 @@ require_relative 'reporter/exceptions'
88
87
  require_relative 'reporter/composite'
89
88
  require_relative 'reporter/file_progress'
90
89
  require_relative 'reporter/file_summary'
90
+ require_relative 'reporter/success_or_not'
91
+ require_relative 'reporter/junit_xml_file'
@@ -15,7 +15,7 @@ module Webspicy
15
15
  @spec_file_errors << spec_file_error_line(spec_file, e)
16
16
  end
17
17
 
18
- def after_each_done
18
+ def test_case_done
19
19
  @failed_results << result unless result.success?
20
20
  end
21
21
 
@@ -24,6 +24,8 @@ module Webspicy
24
24
  report_failed_results
25
25
  end
26
26
 
27
+ private
28
+
27
29
  def report_spec_file_errors
28
30
  return if spec_file_errors.empty?
29
31
  io.puts
@@ -0,0 +1,151 @@
1
+ module Webspicy
2
+ class Tester
3
+ class Reporter
4
+ class JunitXmlFile < Reporter
5
+
6
+ TPL = <<~XML
7
+ <?xml version="1.0" encoding="UTF-8"?>
8
+ <testsuites
9
+ disabled="{{counts.disabled}}"
10
+ errors="{{counts.errors}}"
11
+ failures="{{counts.failures}}"
12
+ tests="{{counts.total}}"
13
+ time="{{time}}s"
14
+ >
15
+ {{#testsuites}}
16
+ <testsuite
17
+ name="{{name}}"
18
+ tests="{{counts.total}}"
19
+ errors="{{counts.errors}}"
20
+ failures="{{counts.failures}}"
21
+ time="{{time}}s"
22
+ >
23
+ {{#testcases}}
24
+ <testcase
25
+ name="{{name}}"
26
+ assertions="{{assert}}"
27
+ classname="{{classname}}"
28
+ status=""
29
+ time="{{time}}s"
30
+ >
31
+ {{#errors}}
32
+ <error
33
+ message="{{message}}"
34
+ type="{{type}}"
35
+ ></error>
36
+ {{/errors}}
37
+ {{#failures}}
38
+ <failure
39
+ message="{{message}}"
40
+ type="{{type}}"
41
+ ></failure>
42
+ {{/failures}}
43
+ </testcase>
44
+ {{/testcases}}
45
+ </testsuite>
46
+ {{/testsuites}}
47
+ </testsuites>
48
+ XML
49
+
50
+ def initialize(path_or_io = STDOUT)
51
+ @path_or_io = path_or_io
52
+ path_or_io.parent.mkdir_p if path_or_io.is_a?(Path)
53
+ end
54
+
55
+ attr_reader :template_data, :timer_all, :timer_specification, :timer_testcase
56
+
57
+ def before_all
58
+ @timer_all = Time.now
59
+ @template_data = OpenStruct.new({
60
+ counts: Hash.new{|h,k| h[k] = 0 },
61
+ testsuites: []
62
+ })
63
+ end
64
+
65
+ def after_all
66
+ template_data.time = Time.now - timer_all
67
+ end
68
+
69
+ def before_specification
70
+ @timer_specification = Time.now
71
+ template_data.testsuites << OpenStruct.new({
72
+ :name => specification.name,
73
+ :counts => Hash.new{|h,k| h[k] = 0 },
74
+ :testcases => []
75
+ })
76
+ end
77
+
78
+ def specification_done
79
+ template_data.testsuites[-1].time = Time.now - timer_specification
80
+ end
81
+
82
+ def spec_file_error(e)
83
+ template_data.testsuites[-1].testcases << OpenStruct.new({
84
+ :name => "Specification can be loaded",
85
+ :assert => 1,
86
+ :classname => "Webspicy.Specification",
87
+ :failures => [],
88
+ :errors => [OpenStruct.new({
89
+ :type => e.class,
90
+ :message => e.message
91
+ })]
92
+ })
93
+ end
94
+
95
+ def before_test_case
96
+ @timer_testcase = Time.now
97
+ template_data.testsuites[-1].testcases << OpenStruct.new({
98
+ :name => test_case.description,
99
+ :assert => test_case.assert.length,
100
+ :classname => test_case.class.name.to_s.gsub(/::/, "."),
101
+ :failures => [],
102
+ :errors => [],
103
+ })
104
+ template_data.counts[:total] += 1
105
+ template_data.testsuites[-1].counts[:total] += 1
106
+ end
107
+
108
+ def test_case_done
109
+ template_data.testsuites[-1].testcases[-1].time = Time.now - timer_testcase
110
+ end
111
+
112
+ def check_failure(check, ex)
113
+ template_data.testsuites[-1].testcases[-1].failures << OpenStruct.new({
114
+ :type => check.class.name,
115
+ :message => ex.message
116
+ })
117
+ template_data.counts[:failures] += 1
118
+ template_data.testsuites[-1].counts[:failures] += 1
119
+ end
120
+
121
+ def check_error(check, ex)
122
+ template_data.testsuites[-1].testcases[-1].errors << OpenStruct.new({
123
+ :type => check.class.name,
124
+ :message => ex.message
125
+ })
126
+ template_data.counts[:errors] += 1
127
+ template_data.testsuites[-1].counts[:errors] += 1
128
+ end
129
+
130
+ def report
131
+ require 'mustache'
132
+ with_io do |io|
133
+ io << Mustache.render(TPL, template_data)
134
+ end
135
+ end
136
+
137
+ private
138
+
139
+ def with_io(&bl)
140
+ case io = @path_or_io
141
+ when IO, StringIO
142
+ bl.call(io)
143
+ else
144
+ Path(io).open('w', &bl)
145
+ end
146
+ end
147
+
148
+ end # class JunitXmlFile
149
+ end # class Reporter
150
+ end # class Tester
151
+ end # module Webspicy
@@ -7,7 +7,7 @@ module Webspicy
7
7
  io.print colorize_error("X", config)
8
8
  end
9
9
 
10
- def after_each_done
10
+ def test_case_done
11
11
  if result.success?
12
12
  io.print colorize_success(".", config)
13
13
  elsif result.failure?
@@ -0,0 +1,14 @@
1
+ module Webspicy
2
+ class Tester
3
+ class Reporter
4
+ class SuccessOrNot < Summary
5
+
6
+ def report
7
+ total_error_count
8
+ end
9
+
10
+ end # class SuccessOrNot
11
+ ErrorCount = SuccessOrNot # for backward compatibility
12
+ end # class Reporter
13
+ end # class Tester
14
+ end # module Webspicy
@@ -26,7 +26,7 @@ module Webspicy
26
26
  @spec_file_errors_count += 1
27
27
  end
28
28
 
29
- def after_each_done
29
+ def test_case_done
30
30
  if tester.test_case.counterexample?
31
31
  @counterexamples_count += 1
32
32
  else
@@ -54,8 +54,12 @@ module Webspicy
54
54
  io.flush
55
55
  end
56
56
 
57
+ def total_error_count
58
+ @spec_file_errors_count + @errors_count + @failures_count
59
+ end
60
+
57
61
  def success?
58
- @spec_file_errors_count == 0 && @errors_count == 0 && @failures_count == 0
62
+ total_error_count == 0
59
63
  end
60
64
 
61
65
  end # class Summary
@@ -18,6 +18,7 @@ module Webspicy
18
18
  check!
19
19
  else
20
20
  @errors << [InvocationSuceeded.new(self), tester.invocation_error]
21
+ reporter.check_error(*errors.first)
21
22
  end
22
23
  end
23
24
  attr_reader :tester, :scope, :client
@@ -2,7 +2,7 @@ module Webspicy
2
2
  module Version
3
3
  MAJOR = 0
4
4
  MINOR = 20
5
- TINY = 6
5
+ TINY = 11
6
6
  end
7
7
  VERSION = "#{Version::MAJOR}.#{Version::MINOR}.#{Version::TINY}"
8
8
  end
@@ -9,7 +9,7 @@ module Webspicy
9
9
 
10
10
  def singleservice(raw)
11
11
  converted = {
12
- name: raw[:name] || "Unamed specification",
12
+ name: raw[:name],
13
13
  url: raw[:url],
14
14
  services: [
15
15
  Webspicy::Web.service(raw.reject{|k| k==:url or k==:name }, Webspicy.current_scope)
@@ -0,0 +1,51 @@
1
+ require 'spec_helper'
2
+ require 'webspicy/tester/fakesendgrid'
3
+ module Webspicy
4
+ class Tester
5
+ class Fakesendgrid
6
+ describe Email do
7
+
8
+ DATA = JSON.parse <<~J
9
+ {
10
+ "datetime": "2021-06-02T15:29:27.161Z",
11
+ "from": {
12
+ "email": "info@mydomain.be",
13
+ "name": "Foo Bar"
14
+ },
15
+ "subject": "Hello World",
16
+ "personalizations": [
17
+ {
18
+ "to": [
19
+ {
20
+ "email": "support@mydomain.fr"
21
+ }
22
+ ]
23
+ }
24
+ ],
25
+ "content": [
26
+ {
27
+ "value": "test",
28
+ "type": "text/plain"
29
+ },
30
+ {
31
+ "value": "test <b>test</b> test",
32
+ "type": "text/html"
33
+ }
34
+ ]
35
+ }
36
+ J
37
+
38
+ subject{
39
+ Email.new(DATA)
40
+ }
41
+
42
+ it 'works as expected' do
43
+ expect(subject.from).to eql("info@mydomain.be")
44
+ expect(subject.to).to eql(["support@mydomain.fr"])
45
+ expect(subject.subject).to eql("Hello World")
46
+ end
47
+
48
+ end
49
+ end
50
+ end
51
+ end
data/tasks/test.rake CHANGED
@@ -5,8 +5,12 @@ namespace :test do
5
5
 
6
6
  desc "Runs unit tests on the library itself"
7
7
  RSpec::Core::RakeTask.new(:unit) do |t|
8
+ require 'path'
9
+ root_folder = Path.dir.parent
10
+ test_results = root_folder/"test-results"
11
+ puts (test_results/"unit-tests.xml").inspect
8
12
  t.pattern = "spec/unit/**/test_*.rb"
9
- t.rspec_opts = ["-Ilib", "-Ispec/unit", "--color", "--backtrace", "--format=progress"]
13
+ t.rspec_opts = ["-Ilib", "-Ispec/unit", "--color", "--backtrace", "--format=progress", "--format RspecJunitFormatter", "--out #{test_results}/unit-tests.xml"]
10
14
  end
11
15
  tests << :unit
12
16
 
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.20.6
4
+ version: 0.20.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bernard Lambeau
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-04-20 00:00:00.000000000 Z
11
+ date: 2021-06-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -98,16 +98,16 @@ dependencies:
98
98
  name: http
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - ">="
101
+ - - "~>"
102
102
  - !ruby/object:Gem::Version
103
- version: '4'
103
+ version: 4.4.1
104
104
  type: :runtime
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - ">="
108
+ - - "~>"
109
109
  - !ruby/object:Gem::Version
110
- version: '4'
110
+ version: 4.4.1
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: path
113
113
  requirement: !ruby/object:Gem::Requirement
@@ -198,11 +198,23 @@ dependencies:
198
198
  - - "~>"
199
199
  - !ruby/object:Gem::Version
200
200
  version: 0.8.2
201
+ - !ruby/object:Gem::Dependency
202
+ name: mustache
203
+ requirement: !ruby/object:Gem::Requirement
204
+ requirements:
205
+ - - "~>"
206
+ - !ruby/object:Gem::Version
207
+ version: '1.0'
208
+ type: :runtime
209
+ prerelease: false
210
+ version_requirements: !ruby/object:Gem::Requirement
211
+ requirements:
212
+ - - "~>"
213
+ - !ruby/object:Gem::Version
214
+ version: '1.0'
201
215
  description: Webspicy helps testing web services as software operation black boxes
202
216
  email: blambeau@gmail.com
203
217
  executables:
204
- - sandr
205
- - search
206
218
  - webspicy
207
219
  extensions: []
208
220
  extra_rdoc_files: []
@@ -210,8 +222,6 @@ files:
210
222
  - Gemfile
211
223
  - README.md
212
224
  - Rakefile
213
- - bin/sandr
214
- - bin/search
215
225
  - bin/webspicy
216
226
  - doc/1-black-box-scene.md
217
227
  - doc/2-black-box-testing.md
@@ -251,6 +261,8 @@ files:
251
261
  - lib/webspicy/tester/assertions.rb
252
262
  - lib/webspicy/tester/client.rb
253
263
  - lib/webspicy/tester/failure.rb
264
+ - lib/webspicy/tester/fakesendgrid.rb
265
+ - lib/webspicy/tester/fakesendgrid/email.rb
254
266
  - lib/webspicy/tester/fakeses.rb
255
267
  - lib/webspicy/tester/fakeses/email.rb
256
268
  - lib/webspicy/tester/fakesmtp.rb
@@ -260,11 +272,12 @@ files:
260
272
  - lib/webspicy/tester/reporter.rb
261
273
  - lib/webspicy/tester/reporter/composite.rb
262
274
  - lib/webspicy/tester/reporter/documentation.rb
263
- - lib/webspicy/tester/reporter/error_count.rb
264
275
  - lib/webspicy/tester/reporter/exceptions.rb
265
276
  - lib/webspicy/tester/reporter/file_progress.rb
266
277
  - lib/webspicy/tester/reporter/file_summary.rb
278
+ - lib/webspicy/tester/reporter/junit_xml_file.rb
267
279
  - lib/webspicy/tester/reporter/progress.rb
280
+ - lib/webspicy/tester/reporter/success_or_not.rb
268
281
  - lib/webspicy/tester/reporter/summary.rb
269
282
  - lib/webspicy/tester/result.rb
270
283
  - lib/webspicy/tester/result/assert_met.rb
@@ -312,6 +325,7 @@ files:
312
325
  - spec/unit/support/world/fixtures/yaml.yml
313
326
  - spec/unit/support/world/test_world.rb
314
327
  - spec/unit/test_configuration.rb
328
+ - spec/unit/tester/fakesendgrid/test_email.rb
315
329
  - spec/unit/tester/fakeses/test_email.rb
316
330
  - spec/unit/tester/fakesmtp/test_email.rb
317
331
  - spec/unit/tester/test_asserter.rb
@@ -326,7 +340,7 @@ homepage: http://github.com/enspirit/webspicy
326
340
  licenses:
327
341
  - MIT
328
342
  metadata: {}
329
- post_install_message:
343
+ post_install_message:
330
344
  rdoc_options: []
331
345
  require_paths:
332
346
  - lib
@@ -341,8 +355,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
341
355
  - !ruby/object:Gem::Version
342
356
  version: '0'
343
357
  requirements: []
344
- rubygems_version: 3.2.1
345
- signing_key:
358
+ rubygems_version: 3.2.15
359
+ signing_key:
346
360
  specification_version: 4
347
361
  summary: Webspicy helps testing web services as software operation black boxes!
348
362
  test_files: []
data/bin/sandr DELETED
@@ -1,14 +0,0 @@
1
- #!/usr/bin/env ruby
2
- require 'path'
3
-
4
- def sandr(file)
5
- file.write file.read.gsub(ARGV[0], ARGV[1])
6
- end
7
-
8
- Path.dir.parent.glob("lib/**/*.rb") do |file|
9
- sandr(file)
10
- end
11
-
12
- Path.dir.parent.glob("spec/**/*.rb") do |file|
13
- sandr(file)
14
- end
data/bin/search DELETED
@@ -1,2 +0,0 @@
1
- #!/bin/bash
2
- grep -Rn --color $1 lib spec
@@ -1,29 +0,0 @@
1
- module Webspicy
2
- class Tester
3
- class Reporter
4
- class ErrorCount < Reporter
5
-
6
- def initialize(*args, &bl)
7
- super
8
- @errors = Hash.new{|h,k| 0 }
9
- end
10
- attr_reader :errors
11
-
12
- [
13
- :spec_file_error,
14
- :check_error,
15
- :check_failure
16
- ].each do |meth|
17
- define_method(meth) do |*args, &bl|
18
- @errors[meth] += 1
19
- end
20
- end
21
-
22
- def report
23
- @errors.values.inject(0){|memo,x| memo+x }
24
- end
25
-
26
- end # class ErrorCount
27
- end # class Reporter
28
- end # class Tester
29
- end # module Webspicy