webspicy 0.18.0 → 0.20.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (122) 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 -9
  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 +5 -2
  12. data/lib/webspicy/specification/condition.rb +48 -0
  13. data/lib/webspicy/specification/err.rb +18 -0
  14. data/lib/webspicy/specification/oldies.rb +4 -0
  15. data/lib/webspicy/specification/oldies/bridge.rb +32 -0
  16. data/lib/webspicy/specification/{errcondition.rb → oldies/errcondition.rb} +6 -0
  17. data/lib/webspicy/specification/{postcondition.rb → oldies/postcondition.rb} +6 -0
  18. data/lib/webspicy/specification/{precondition.rb → oldies/precondition.rb} +6 -2
  19. data/lib/webspicy/specification/post.rb +20 -0
  20. data/lib/webspicy/specification/post/missing_condition_impl.rb +15 -0
  21. data/lib/webspicy/specification/post/unexpected_condition_impl.rb +15 -0
  22. data/lib/webspicy/specification/pre.rb +19 -0
  23. data/lib/webspicy/specification/{precondition → pre}/global_request_headers.rb +4 -4
  24. data/lib/webspicy/specification/{precondition → pre}/robust_to_invalid_input.rb +4 -4
  25. data/lib/webspicy/specification/service.rb +34 -5
  26. data/lib/webspicy/specification/test_case.rb +11 -9
  27. data/lib/webspicy/support.rb +31 -0
  28. data/lib/webspicy/support/hooks.rb +65 -0
  29. data/lib/webspicy/support/world.rb +47 -0
  30. data/lib/webspicy/tester.rb +202 -3
  31. data/lib/webspicy/tester/assertions.rb +2 -2
  32. data/lib/webspicy/tester/client.rb +4 -50
  33. data/lib/webspicy/tester/fakeses.rb +41 -0
  34. data/lib/webspicy/tester/fakeses/email.rb +38 -0
  35. data/lib/webspicy/tester/fakesmtp.rb +39 -0
  36. data/lib/webspicy/tester/fakesmtp/email.rb +27 -0
  37. data/lib/webspicy/tester/file_checker.rb +22 -0
  38. data/lib/webspicy/tester/invocation.rb +15 -48
  39. data/lib/webspicy/tester/reporter.rb +85 -0
  40. data/lib/webspicy/tester/reporter/composite.rb +38 -0
  41. data/lib/webspicy/tester/reporter/documentation.rb +74 -0
  42. data/lib/webspicy/tester/reporter/error_count.rb +25 -0
  43. data/lib/webspicy/tester/reporter/exceptions.rb +62 -0
  44. data/lib/webspicy/tester/reporter/file_progress.rb +25 -0
  45. data/lib/webspicy/tester/reporter/file_summary.rb +43 -0
  46. data/lib/webspicy/tester/reporter/progress.rb +30 -0
  47. data/lib/webspicy/tester/reporter/summary.rb +63 -0
  48. data/lib/webspicy/tester/result.rb +142 -0
  49. data/lib/webspicy/tester/result/assert_met.rb +29 -0
  50. data/lib/webspicy/tester/result/check.rb +33 -0
  51. data/lib/webspicy/tester/result/errcondition_met.rb +29 -0
  52. data/lib/webspicy/tester/result/error_schema_met.rb +25 -0
  53. data/lib/webspicy/tester/result/invocation_succeeded.rb +13 -0
  54. data/lib/webspicy/tester/result/output_schema_met.rb +25 -0
  55. data/lib/webspicy/tester/result/postcondition_met.rb +29 -0
  56. data/lib/webspicy/tester/result/response_header_met.rb +43 -0
  57. data/lib/webspicy/tester/result/response_status_met.rb +25 -0
  58. data/lib/webspicy/version.rb +2 -2
  59. data/lib/webspicy/web.rb +4 -0
  60. data/lib/webspicy/web/client.rb +15 -0
  61. data/lib/webspicy/{tester → web}/client/http_client.rb +34 -14
  62. data/lib/webspicy/{tester → web}/client/rack_test_client.rb +3 -3
  63. data/lib/webspicy/{tester → web}/client/support.rb +2 -2
  64. data/lib/webspicy/web/invocation.rb +69 -0
  65. data/lib/webspicy/web/mocker.rb +90 -0
  66. data/lib/webspicy/{mocker → web/mocker}/config.ru +3 -2
  67. data/lib/webspicy/{openapi.rb → web/openapi.rb} +0 -0
  68. data/lib/webspicy/web/openapi/generator.rb +129 -0
  69. data/spec/unit/specification/{precondition → pre}/test_global_request_headers.rb +9 -4
  70. data/spec/unit/specification/test_condition.rb +44 -0
  71. data/spec/unit/support/hooks/test_fire_after_each.rb +53 -0
  72. data/spec/unit/{tester/client/test_around.rb → support/hooks/test_fire_around.rb} +15 -10
  73. data/spec/unit/support/hooks/test_fire_before_each.rb +53 -0
  74. data/spec/unit/support/world/fixtures/array.json +8 -0
  75. data/spec/unit/support/world/fixtures/queue.rb +1 -0
  76. data/spec/unit/support/world/fixtures/single.json +11 -0
  77. data/spec/unit/support/world/fixtures/yaml.yml +3 -0
  78. data/spec/unit/support/world/test_world.rb +56 -0
  79. data/spec/unit/test_configuration.rb +49 -0
  80. data/spec/unit/tester/fakeses/test_email.rb +40 -0
  81. data/spec/unit/web/mocker/test_mocker.rb +35 -0
  82. data/spec/unit/web/openapi/test_generator.rb +31 -0
  83. metadata +80 -65
  84. data/examples/restful/Gemfile +0 -5
  85. data/examples/restful/Rakefile +0 -25
  86. data/examples/restful/app.rb +0 -180
  87. data/examples/restful/webspicy/config.rb +0 -24
  88. data/examples/restful/webspicy/formaldef/todo/_one/delete.yml +0 -55
  89. data/examples/restful/webspicy/formaldef/todo/_one/get.simpler.yml +0 -46
  90. data/examples/restful/webspicy/formaldef/todo/_one/get.yml +0 -50
  91. data/examples/restful/webspicy/formaldef/todo/_one/patch.yml +0 -66
  92. data/examples/restful/webspicy/formaldef/todo/_one/put.yml +0 -65
  93. data/examples/restful/webspicy/formaldef/todo/get.yml +0 -36
  94. data/examples/restful/webspicy/formaldef/todo/options.yml +0 -32
  95. data/examples/restful/webspicy/formaldef/todo/post.csv.yml +0 -43
  96. data/examples/restful/webspicy/formaldef/todo/post.file.yml +0 -40
  97. data/examples/restful/webspicy/formaldef/todo/post.yml +0 -51
  98. data/examples/restful/webspicy/formaldef/todo/todos.csv +0 -4
  99. data/examples/restful/webspicy/rack.rb +0 -7
  100. data/examples/restful/webspicy/real.rb +0 -8
  101. data/examples/restful/webspicy/schema.fio +0 -20
  102. data/examples/restful/webspicy/support/must_be_an_admin.rb +0 -20
  103. data/examples/restful/webspicy/support/must_be_authenticated.rb +0 -48
  104. data/examples/restful/webspicy/support/todo_not_removed.rb +0 -21
  105. data/examples/restful/webspicy/support/todo_removed.rb +0 -20
  106. data/examples/single_spec/spec.yml +0 -59
  107. data/examples/website/config.rb +0 -2
  108. data/examples/website/schema.fio +0 -1
  109. data/examples/website/specification/get-http.yml +0 -30
  110. data/examples/website/specification/get-https.yml +0 -30
  111. data/lib/webspicy/checker.rb +0 -10
  112. data/lib/webspicy/mocker.rb +0 -88
  113. data/lib/webspicy/openapi/generator.rb +0 -127
  114. data/lib/webspicy/rspec/checker.rb +0 -2
  115. data/lib/webspicy/rspec/checker/rspec_checker.rb +0 -24
  116. data/lib/webspicy/rspec/support/rspec_runnable.rb +0 -27
  117. data/lib/webspicy/rspec/tester.rb +0 -4
  118. data/lib/webspicy/rspec/tester/rspec_asserter.rb +0 -121
  119. data/lib/webspicy/rspec/tester/rspec_matchers.rb +0 -114
  120. data/lib/webspicy/rspec/tester/rspec_tester.rb +0 -63
  121. data/spec/unit/mocker/test_mocker.rb +0 -32
  122. data/spec/unit/openapi/test_generator.rb +0 -28
@@ -0,0 +1,25 @@
1
+ module Webspicy
2
+ class Tester
3
+ class Reporter
4
+ class ErrorCount < Reporter
5
+
6
+ def initialize(*args, &bl)
7
+ super
8
+ @error_count = 0
9
+ end
10
+
11
+ def on_error(*args, &bl)
12
+ @error_count += 1
13
+ end
14
+ alias :spec_file_error :on_error
15
+ alias :check_failure :on_error
16
+ alias :check_error :on_error
17
+
18
+ def report
19
+ @error_count
20
+ end
21
+
22
+ end # class ErrorCount
23
+ end # class Reporter
24
+ end # class Tester
25
+ end # module Webspicy
@@ -0,0 +1,62 @@
1
+ module Webspicy
2
+ class Tester
3
+ class Reporter
4
+ class Exceptions < Reporter
5
+ include Documentation::Helpers
6
+
7
+ def initialize(*args, &bl)
8
+ super
9
+ @spec_file_errors = []
10
+ @failed_results = []
11
+ end
12
+ attr_reader :failed_results, :spec_file_errors
13
+
14
+ def spec_file_error(e)
15
+ @spec_file_errors << spec_file_error_line(spec_file, e)
16
+ end
17
+
18
+ def after_each_done
19
+ @failed_results << result unless result.success?
20
+ end
21
+
22
+ def report
23
+ report_spec_file_errors
24
+ report_failed_results
25
+ end
26
+
27
+ def report_spec_file_errors
28
+ return if spec_file_errors.empty?
29
+ io.puts
30
+ io.puts "Invalid specs:"
31
+ io.puts
32
+ spec_file_errors.each do |e|
33
+ io.puts e
34
+ end
35
+ io.puts
36
+ io.flush
37
+ end
38
+
39
+ def report_failed_results
40
+ return if failed_results.empty?
41
+ io.puts
42
+ io.puts "Exceptions:"
43
+ io.puts
44
+ failed_results.each_with_index do |result,i|
45
+ io.puts service_line(result.service, result.test_case)
46
+ result.failures.each do |(c,e)|
47
+ io.puts check_failure_line(c,e)
48
+ end
49
+ result.errors.each do |(c,e)|
50
+ io.puts check_error_line(c,e)
51
+ io.puts e.backtrace.join("\n").gsub(/^/, " ") if e.backtrace
52
+ end
53
+ io.puts
54
+ end
55
+ io.puts
56
+ io.flush
57
+ end
58
+
59
+ end # class Exceptions
60
+ end # class Reporter
61
+ end # class Tester
62
+ end # module Webspicy
@@ -0,0 +1,25 @@
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
+ io.flush
9
+ end
10
+
11
+ def spec_file_done
12
+ io.print colorize_success(".")
13
+ io.flush
14
+ end
15
+
16
+ def report
17
+ io.puts
18
+ io.puts
19
+ io.flush
20
+ end
21
+
22
+ end # class FileProgress
23
+ end # class Reporter
24
+ end # class Tester
25
+ end # module Webspicy
@@ -0,0 +1,43 @@
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
+ io.flush
32
+ end
33
+
34
+ private
35
+
36
+ def success?
37
+ @errors_count == 0
38
+ end
39
+
40
+ end # class FileSummary
41
+ end # class Reporter
42
+ end # class Tester
43
+ end # module Webspicy
@@ -0,0 +1,30 @@
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
+ io.flush
19
+ end
20
+
21
+ def report
22
+ io.puts
23
+ io.puts
24
+ io.flush
25
+ end
26
+
27
+ end # class Progress
28
+ end # class Reporter
29
+ end # class Tester
30
+ end # module Webspicy
@@ -0,0 +1,63 @@
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
+ io.flush
52
+ end
53
+
54
+ private
55
+
56
+ def success?
57
+ @errors_count == 0 && @failures_count == 0
58
+ end
59
+
60
+ end # class Summary
61
+ end # class Reporter
62
+ end # class Tester
63
+ end # module Webspicy
@@ -0,0 +1,142 @@
1
+ module Webspicy
2
+ class Tester
3
+ class Result
4
+ extend Forwardable
5
+
6
+ def initialize(tester)
7
+ @tester = tester
8
+ @scope = tester.scope
9
+ @client = tester.client
10
+ @specification = tester.specification
11
+ @service = tester.service
12
+ @test_case = tester.test_case
13
+ @invocation = tester.invocation
14
+ @assertions = []
15
+ @failures = []
16
+ @errors = []
17
+ if @invocation
18
+ check!
19
+ else
20
+ @errors << [InvocationSuceeded.new(self), tester.invocation_error]
21
+ end
22
+ end
23
+ attr_reader :tester, :scope, :client
24
+ attr_reader :specification, :service, :test_case, :invocation
25
+ attr_reader :assertions, :failures, :errors
26
+
27
+ def_delegators :@tester, *[
28
+ :config,
29
+ :reporter
30
+ ]
31
+
32
+ def self.from(tester)
33
+ new(tester)
34
+ end
35
+
36
+ def success?
37
+ failures.empty? && errors.empty?
38
+ end
39
+
40
+ def failure?
41
+ errors.empty? && !failures.empty?
42
+ end
43
+
44
+ def error?
45
+ !errors.empty?
46
+ end
47
+
48
+ def assertions_count
49
+ assertions.size
50
+ end
51
+
52
+ def failures_count
53
+ failures.size
54
+ end
55
+
56
+ def errors_count
57
+ errors.size
58
+ end
59
+
60
+ private
61
+
62
+ def check!
63
+ check_response!
64
+ check_output! if success? && test_case.example?
65
+ check_error! if success? && test_case.counterexample?
66
+ check_assertions! if success?
67
+ check_postconditions! if success? && test_case.example?
68
+ check_errconditions! if success? && test_case.counterexample?
69
+ end
70
+
71
+ private
72
+
73
+ def check_response!
74
+ check_one! Result::ResponseStatusMet
75
+ if ect = test_case.expected_content_type
76
+ check_one! Result::ResponseHeaderMet.new(self, "Content-Type", ect, :start_with)
77
+ end
78
+ test_case.expected_headers.each_pair do |k,v|
79
+ check_one! Result::ResponseHeaderMet.new(self, k, v)
80
+ end
81
+ end
82
+
83
+ def check_output!
84
+ check_one! Result::OutputSchemaMet
85
+ end
86
+
87
+ def check_error!
88
+ check_one! Result::ErrorSchemaMet
89
+ end
90
+
91
+ def check_assertions!
92
+ test_case.assert.each do |a|
93
+ check_one! Result::AssertMet.new(self, a)
94
+ end
95
+ end
96
+
97
+ def check_postconditions!
98
+ service.postconditions.each do |c|
99
+ check_one! Result::PostconditionMet.new(self, tester.bind_condition(c))
100
+ end
101
+ end
102
+
103
+ def check_errconditions!
104
+ service.errconditions.each do |c|
105
+ check_one! Result::ErrconditionMet.new(self, tester.bind_condition(c))
106
+ end
107
+ end
108
+
109
+ def check_one!(check)
110
+ if check.is_a?(Class)
111
+ check_one!(check.new(self))
112
+ else
113
+ return unless check.must?
114
+ begin
115
+ check.call
116
+ reporter.check_success(check)
117
+ rescue *PASSTHROUGH_EXCEPTIONS
118
+ raise
119
+ rescue Failure => e
120
+ self.failures << [check, e]
121
+ reporter.check_failure(check, e)
122
+ rescue Exception => e
123
+ self.errors << [check, e]
124
+ reporter.check_error(check, e)
125
+ ensure
126
+ self.assertions << check
127
+ end
128
+ end
129
+ end
130
+
131
+ end # class Result
132
+ end # class Tester
133
+ end # module Webspicy
134
+ require_relative "result/check"
135
+ require_relative "result/invocation_succeeded"
136
+ require_relative "result/response_status_met"
137
+ require_relative "result/response_header_met"
138
+ require_relative "result/output_schema_met"
139
+ require_relative "result/error_schema_met"
140
+ require_relative "result/assert_met"
141
+ require_relative "result/postcondition_met"
142
+ 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