webspicy 0.18.0 → 0.19.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (105) hide show
  1. checksums.yaml +4 -4
  2. data/bin/webspicy +6 -1
  3. data/doc/1-black-box-scene.md +109 -0
  4. data/doc/2-black-box-testing.md +27 -0
  5. data/doc/3-specification-importance.md +41 -0
  6. data/doc/4-sequence-diagram.md +82 -0
  7. data/lib/webspicy.rb +17 -7
  8. data/lib/webspicy/configuration.rb +48 -8
  9. data/lib/webspicy/configuration/scope.rb +22 -8
  10. data/lib/webspicy/formaldoc.fio +5 -5
  11. data/lib/webspicy/specification.rb +2 -0
  12. data/lib/webspicy/specification/condition.rb +23 -0
  13. data/lib/webspicy/specification/errcondition.rb +1 -0
  14. data/lib/webspicy/specification/postcondition.rb +1 -0
  15. data/lib/webspicy/specification/precondition.rb +1 -0
  16. data/lib/webspicy/specification/service.rb +11 -6
  17. data/lib/webspicy/specification/test_case.rb +8 -9
  18. data/lib/webspicy/support.rb +21 -0
  19. data/lib/webspicy/support/hooks.rb +65 -0
  20. data/lib/webspicy/support/world.rb +47 -0
  21. data/lib/webspicy/tester.rb +136 -3
  22. data/lib/webspicy/tester/client.rb +22 -42
  23. data/lib/webspicy/tester/file_checker.rb +22 -0
  24. data/lib/webspicy/tester/invocation.rb +15 -48
  25. data/lib/webspicy/tester/reporter.rb +85 -0
  26. data/lib/webspicy/tester/reporter/composite.rb +38 -0
  27. data/lib/webspicy/tester/reporter/documentation.rb +67 -0
  28. data/lib/webspicy/tester/reporter/error_count.rb +25 -0
  29. data/lib/webspicy/tester/reporter/exceptions.rb +60 -0
  30. data/lib/webspicy/tester/reporter/file_progress.rb +22 -0
  31. data/lib/webspicy/tester/reporter/file_summary.rb +42 -0
  32. data/lib/webspicy/tester/reporter/progress.rb +28 -0
  33. data/lib/webspicy/tester/reporter/summary.rb +62 -0
  34. data/lib/webspicy/tester/result.rb +139 -0
  35. data/lib/webspicy/tester/result/assert_met.rb +29 -0
  36. data/lib/webspicy/tester/result/check.rb +33 -0
  37. data/lib/webspicy/tester/result/errcondition_met.rb +29 -0
  38. data/lib/webspicy/tester/result/error_schema_met.rb +24 -0
  39. data/lib/webspicy/tester/result/output_schema_met.rb +24 -0
  40. data/lib/webspicy/tester/result/postcondition_met.rb +29 -0
  41. data/lib/webspicy/tester/result/response_header_met.rb +43 -0
  42. data/lib/webspicy/tester/result/response_status_met.rb +25 -0
  43. data/lib/webspicy/version.rb +1 -1
  44. data/lib/webspicy/web.rb +4 -0
  45. data/lib/webspicy/web/client.rb +15 -0
  46. data/lib/webspicy/{tester → web}/client/http_client.rb +34 -14
  47. data/lib/webspicy/{tester → web}/client/rack_test_client.rb +3 -3
  48. data/lib/webspicy/{tester → web}/client/support.rb +2 -2
  49. data/lib/webspicy/web/invocation.rb +65 -0
  50. data/lib/webspicy/web/mocker.rb +90 -0
  51. data/lib/webspicy/{mocker → web/mocker}/config.ru +3 -2
  52. data/lib/webspicy/{openapi.rb → web/openapi.rb} +0 -0
  53. data/lib/webspicy/web/openapi/generator.rb +129 -0
  54. data/spec/unit/specification/test_condition.rb +26 -0
  55. data/spec/unit/support/hooks/test_fire_after_each.rb +53 -0
  56. data/spec/unit/{tester/client/test_around.rb → support/hooks/test_fire_around.rb} +15 -10
  57. data/spec/unit/support/hooks/test_fire_before_each.rb +53 -0
  58. data/spec/unit/support/world/fixtures/array.json +8 -0
  59. data/spec/unit/support/world/fixtures/queue.rb +1 -0
  60. data/spec/unit/support/world/fixtures/single.json +11 -0
  61. data/spec/unit/support/world/fixtures/yaml.yml +3 -0
  62. data/spec/unit/support/world/test_world.rb +56 -0
  63. data/spec/unit/test_configuration.rb +49 -0
  64. data/spec/unit/web/mocker/test_mocker.rb +35 -0
  65. data/spec/unit/web/openapi/test_generator.rb +31 -0
  66. metadata +61 -59
  67. data/examples/restful/Gemfile +0 -5
  68. data/examples/restful/Rakefile +0 -25
  69. data/examples/restful/app.rb +0 -180
  70. data/examples/restful/webspicy/config.rb +0 -24
  71. data/examples/restful/webspicy/formaldef/todo/_one/delete.yml +0 -55
  72. data/examples/restful/webspicy/formaldef/todo/_one/get.simpler.yml +0 -46
  73. data/examples/restful/webspicy/formaldef/todo/_one/get.yml +0 -50
  74. data/examples/restful/webspicy/formaldef/todo/_one/patch.yml +0 -66
  75. data/examples/restful/webspicy/formaldef/todo/_one/put.yml +0 -65
  76. data/examples/restful/webspicy/formaldef/todo/get.yml +0 -36
  77. data/examples/restful/webspicy/formaldef/todo/options.yml +0 -32
  78. data/examples/restful/webspicy/formaldef/todo/post.csv.yml +0 -43
  79. data/examples/restful/webspicy/formaldef/todo/post.file.yml +0 -40
  80. data/examples/restful/webspicy/formaldef/todo/post.yml +0 -51
  81. data/examples/restful/webspicy/formaldef/todo/todos.csv +0 -4
  82. data/examples/restful/webspicy/rack.rb +0 -7
  83. data/examples/restful/webspicy/real.rb +0 -8
  84. data/examples/restful/webspicy/schema.fio +0 -20
  85. data/examples/restful/webspicy/support/must_be_an_admin.rb +0 -20
  86. data/examples/restful/webspicy/support/must_be_authenticated.rb +0 -48
  87. data/examples/restful/webspicy/support/todo_not_removed.rb +0 -21
  88. data/examples/restful/webspicy/support/todo_removed.rb +0 -20
  89. data/examples/single_spec/spec.yml +0 -59
  90. data/examples/website/config.rb +0 -2
  91. data/examples/website/schema.fio +0 -1
  92. data/examples/website/specification/get-http.yml +0 -30
  93. data/examples/website/specification/get-https.yml +0 -30
  94. data/lib/webspicy/checker.rb +0 -10
  95. data/lib/webspicy/mocker.rb +0 -88
  96. data/lib/webspicy/openapi/generator.rb +0 -127
  97. data/lib/webspicy/rspec/checker.rb +0 -2
  98. data/lib/webspicy/rspec/checker/rspec_checker.rb +0 -24
  99. data/lib/webspicy/rspec/support/rspec_runnable.rb +0 -27
  100. data/lib/webspicy/rspec/tester.rb +0 -4
  101. data/lib/webspicy/rspec/tester/rspec_asserter.rb +0 -121
  102. data/lib/webspicy/rspec/tester/rspec_matchers.rb +0 -114
  103. data/lib/webspicy/rspec/tester/rspec_tester.rb +0 -63
  104. data/spec/unit/mocker/test_mocker.rb +0 -32
  105. data/spec/unit/openapi/test_generator.rb +0 -28
@@ -0,0 +1,22 @@
1
+ module Webspicy
2
+ class Tester
3
+ class Reporter
4
+ class FileProgress < Reporter
5
+
6
+ def spec_file_error(e)
7
+ io.print colorize_error("X")
8
+ end
9
+
10
+ def spec_file_done
11
+ io.print colorize_success(".")
12
+ end
13
+
14
+ def report
15
+ io.puts
16
+ io.puts
17
+ end
18
+
19
+ end # class FileProgress
20
+ end # class Reporter
21
+ end # class Tester
22
+ end # module Webspicy
@@ -0,0 +1,42 @@
1
+ module Webspicy
2
+ class Tester
3
+ class Reporter
4
+ class FileSummary < Reporter
5
+
6
+ def initialize(*args, &bl)
7
+ super
8
+ @spec_files_count = 0
9
+ @errors_count = 0
10
+ end
11
+ attr_reader :spec_files_count, :errors_count
12
+
13
+ def before_spec_file
14
+ @spec_files_count += 1
15
+ end
16
+
17
+ def spec_file_error(e)
18
+ @errors_count += 1
19
+ end
20
+
21
+ def report
22
+ msg = "#{plural('spec file', spec_files_count)}, "\
23
+ "#{plural('error', errors_count)}"
24
+ if success?
25
+ msg = colorize_success(msg)
26
+ else
27
+ msg = colorize_error(msg)
28
+ end
29
+ io.puts(msg)
30
+ io.puts
31
+ end
32
+
33
+ private
34
+
35
+ def success?
36
+ @errors_count == 0
37
+ end
38
+
39
+ end # class FileSummary
40
+ end # class Reporter
41
+ end # class Tester
42
+ end # module Webspicy
@@ -0,0 +1,28 @@
1
+ module Webspicy
2
+ class Tester
3
+ class Reporter
4
+ class Progress < Reporter
5
+
6
+ def spec_file_error(e)
7
+ io.print colorize_error("X")
8
+ end
9
+
10
+ def after_each_done
11
+ if result.success?
12
+ io.print colorize_success(".")
13
+ elsif result.failure?
14
+ io.print colorize_error("F")
15
+ elsif result.error?
16
+ io.print colorize_error("E")
17
+ end
18
+ end
19
+
20
+ def report
21
+ io.puts
22
+ io.puts
23
+ end
24
+
25
+ end # class Progress
26
+ end # class Reporter
27
+ end # class Tester
28
+ end # module Webspicy
@@ -0,0 +1,62 @@
1
+ module Webspicy
2
+ class Tester
3
+ class Reporter
4
+ class Summary < Reporter
5
+
6
+ def initialize(*args, &bl)
7
+ super
8
+ @spec_files_count = 0
9
+ @examples_count = 0
10
+ @counterexamples_count = 0
11
+ @assertions_count = 0
12
+ @errors_count = 0
13
+ @failures_count = 0
14
+ end
15
+ attr_reader :spec_files_count, :examples_count, :counterexamples_count
16
+ attr_reader :assertions_count, :errors_count, :failures_count
17
+
18
+ def before_spec_file
19
+ @spec_files_count += 1
20
+ end
21
+
22
+ def spec_file_error(e)
23
+ @errors_count += 1
24
+ end
25
+
26
+ def after_each_done
27
+ if tester.test_case.counterexample?
28
+ @counterexamples_count += 1
29
+ else
30
+ @examples_count += 1
31
+ end
32
+ @assertions_count += tester.result.assertions_count
33
+ @errors_count += tester.result.errors_count
34
+ @failures_count += tester.result.failures_count
35
+ end
36
+
37
+ def report
38
+ msg = "#{plural('spec file', spec_files_count)}, "\
39
+ "#{plural('example', examples_count)}, "\
40
+ "#{plural('counterexample', counterexamples_count)}\n"\
41
+ "#{plural('assertion', assertions_count)}, "\
42
+ "#{plural('error', errors_count)}, "\
43
+ "#{plural('failure', failures_count)}"
44
+ if success?
45
+ msg = colorize_success(msg)
46
+ else
47
+ msg = colorize_error(msg)
48
+ end
49
+ io.puts(msg)
50
+ io.puts
51
+ end
52
+
53
+ private
54
+
55
+ def success?
56
+ @errors_count == 0 && @failures_count == 0
57
+ end
58
+
59
+ end # class Summary
60
+ end # class Reporter
61
+ end # class Tester
62
+ end # module Webspicy
@@ -0,0 +1,139 @@
1
+ module Webspicy
2
+ class Tester
3
+ class Result
4
+ extend Forwardable
5
+
6
+ def initialize(tester)
7
+ @tester = tester
8
+ @invocation = tester.invocation
9
+ @assertions = []
10
+ @failures = []
11
+ @errors = []
12
+ check!
13
+ end
14
+ attr_reader :tester, :invocation
15
+ attr_reader :assertions, :failures, :errors
16
+
17
+ def_delegators :@tester, *[
18
+ :reporter
19
+ ]
20
+
21
+ def_delegators :@invocation, *[
22
+ :config,
23
+ :scope,
24
+ :client,
25
+ :specification,
26
+ :service,
27
+ :test_case
28
+ ]
29
+
30
+ def self.from(tester)
31
+ new(tester)
32
+ end
33
+
34
+ def success?
35
+ failures.empty? && errors.empty?
36
+ end
37
+
38
+ def failure?
39
+ errors.empty? && !failures.empty?
40
+ end
41
+
42
+ def error?
43
+ !errors.empty?
44
+ end
45
+
46
+ def assertions_count
47
+ assertions.size
48
+ end
49
+
50
+ def failures_count
51
+ failures.size
52
+ end
53
+
54
+ def errors_count
55
+ errors.size
56
+ end
57
+
58
+ private
59
+
60
+ def check!
61
+ check_response!
62
+ check_output! if success? && test_case.example?
63
+ check_error! if success? && test_case.counterexample?
64
+ check_assertions! if success?
65
+ check_postconditions! if success? && test_case.example?
66
+ check_errconditions! if success? && test_case.counterexample?
67
+ end
68
+
69
+ private
70
+
71
+ def check_response!
72
+ check_one! Result::ResponseStatusMet
73
+ if ect = test_case.expected_content_type
74
+ check_one! Result::ResponseHeaderMet.new(self, "Content-Type", ect, :start_with)
75
+ end
76
+ test_case.expected_headers.each_pair do |k,v|
77
+ check_one! Result::ResponseHeaderMet.new(self, k, v)
78
+ end
79
+ end
80
+
81
+ def check_output!
82
+ check_one! Result::OutputSchemaMet
83
+ end
84
+
85
+ def check_error!
86
+ check_one! Result::ErrorSchemaMet
87
+ end
88
+
89
+ def check_assertions!
90
+ test_case.assert.each do |a|
91
+ check_one! Result::AssertMet.new(self, a)
92
+ end
93
+ end
94
+
95
+ def check_postconditions!
96
+ service.postconditions.each do |c|
97
+ check_one! Result::PostconditionMet.new(self, c)
98
+ end
99
+ end
100
+
101
+ def check_errconditions!
102
+ service.errconditions.each do |c|
103
+ check_one! Result::ErrconditionMet.new(self, c)
104
+ end
105
+ end
106
+
107
+ def check_one!(check)
108
+ if check.is_a?(Class)
109
+ check_one!(check.new(self))
110
+ else
111
+ return unless check.must?
112
+ begin
113
+ check.call
114
+ reporter.check_success(check)
115
+ rescue *PASSTHROUGH_EXCEPTIONS
116
+ raise
117
+ rescue Failure => e
118
+ self.failures << [check, e]
119
+ reporter.check_failure(check, e)
120
+ rescue Exception => e
121
+ self.errors << [check, e]
122
+ reporter.check_error(check, e)
123
+ ensure
124
+ self.assertions << check
125
+ end
126
+ end
127
+ end
128
+
129
+ end # class Result
130
+ end # class Tester
131
+ end # module Webspicy
132
+ require_relative "result/check"
133
+ require_relative "result/response_status_met"
134
+ require_relative "result/response_header_met"
135
+ require_relative "result/output_schema_met"
136
+ require_relative "result/error_schema_met"
137
+ require_relative "result/assert_met"
138
+ require_relative "result/postcondition_met"
139
+ require_relative "result/errcondition_met"
@@ -0,0 +1,29 @@
1
+ module Webspicy
2
+ class Tester
3
+ class Result
4
+ class AssertMet < Check
5
+
6
+ def initialize(result, assertion)
7
+ super(result)
8
+ @assertion = assertion
9
+ end
10
+ attr_reader :assertion
11
+
12
+ def behavior
13
+ "Assert #{assertion}"
14
+ end
15
+
16
+ def must?
17
+ true
18
+ end
19
+
20
+ def call
21
+ on = invocation.dressed_body
22
+ asserter = Tester::Asserter.new(on)
23
+ asserter.instance_eval(assertion)
24
+ end
25
+
26
+ end # class AssertMet
27
+ end # class Result
28
+ end # class Tester
29
+ end # module error
@@ -0,0 +1,33 @@
1
+ module Webspicy
2
+ class Tester
3
+ class Result
4
+ class Check
5
+ extend Forwardable
6
+
7
+ def initialize(result)
8
+ @result = result
9
+ end
10
+ attr_reader :result
11
+
12
+ def_delegators :@result, *[
13
+ :config,
14
+ :scope,
15
+ :client,
16
+ :specification,
17
+ :service,
18
+ :test_case,
19
+ :invocation
20
+ ]
21
+
22
+ def_delegators :invocation, *[
23
+ :response
24
+ ]
25
+
26
+ def _!(msg)
27
+ raise Failure, msg
28
+ end
29
+
30
+ end # class Check
31
+ end # class Result
32
+ end # class Tester
33
+ end # module Webspicy
@@ -0,0 +1,29 @@
1
+ module Webspicy
2
+ class Tester
3
+ class Result
4
+ class ErrconditionMet < Check
5
+
6
+ def initialize(result, post)
7
+ super(result)
8
+ @post = post
9
+ end
10
+ attr_reader :post
11
+
12
+ def behavior
13
+ post.to_s
14
+ end
15
+
16
+ def must?
17
+ true
18
+ end
19
+
20
+ def call
21
+ if err = post.check(invocation)
22
+ _! err
23
+ end
24
+ end
25
+
26
+ end # class ErrconditionMet
27
+ end # class Result
28
+ end # class Tester
29
+ end # module Webspicy
@@ -0,0 +1,24 @@
1
+ module Webspicy
2
+ class Tester
3
+ class Result
4
+ class ErrorSchemaMet < Check
5
+
6
+ def behavior
7
+ "Error data meets the expected error schema"
8
+ end
9
+
10
+ def must?
11
+ !test_case.is_expected_status?(204)
12
+ end
13
+
14
+ def call
15
+ output = invocation.loaded_body
16
+ service.error_schema.dress(output)
17
+ rescue Finitio::TypeError => ex
18
+ _! "Invalid error: #{ex.message}"
19
+ end
20
+
21
+ end # class ErrorSchemaMet
22
+ end # class Result
23
+ end # class Tester
24
+ end # module error
@@ -0,0 +1,24 @@
1
+ module Webspicy
2
+ class Tester
3
+ class Result
4
+ class OutputSchemaMet < Check
5
+
6
+ def behavior
7
+ "Its output meets the expected data schema"
8
+ end
9
+
10
+ def must?
11
+ !test_case.is_expected_status?(204)
12
+ end
13
+
14
+ def call
15
+ output = invocation.loaded_body
16
+ service.output_schema.dress(output)
17
+ rescue Finitio::TypeError => ex
18
+ _! "Invalid output: #{ex.message}"
19
+ end
20
+
21
+ end # class OutputSchemaMet
22
+ end # class Result
23
+ end # class Tester
24
+ end # module Webspicy