webspicy 0.16.3 → 0.20.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (125) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +9 -3
  3. data/bin/webspicy +6 -1
  4. data/doc/1-black-box-scene.md +109 -0
  5. data/doc/2-black-box-testing.md +27 -0
  6. data/doc/3-specification-importance.md +41 -0
  7. data/doc/4-sequence-diagram.md +82 -0
  8. data/lib/webspicy.rb +18 -9
  9. data/lib/webspicy/configuration.rb +57 -8
  10. data/lib/webspicy/configuration/scope.rb +22 -16
  11. data/lib/webspicy/formaldoc.fio +7 -5
  12. data/lib/webspicy/specification.rb +10 -9
  13. data/lib/webspicy/specification/condition.rb +48 -0
  14. data/lib/webspicy/specification/err.rb +18 -0
  15. data/lib/webspicy/specification/oldies.rb +4 -0
  16. data/lib/webspicy/specification/oldies/bridge.rb +29 -0
  17. data/lib/webspicy/specification/oldies/errcondition.rb +22 -0
  18. data/lib/webspicy/specification/{postcondition.rb → oldies/postcondition.rb} +6 -0
  19. data/lib/webspicy/specification/{precondition.rb → oldies/precondition.rb} +6 -2
  20. data/lib/webspicy/specification/post.rb +20 -0
  21. data/lib/webspicy/specification/post/missing_condition_impl.rb +15 -0
  22. data/lib/webspicy/specification/post/unexpected_condition_impl.rb +15 -0
  23. data/lib/webspicy/specification/pre.rb +19 -0
  24. data/lib/webspicy/specification/{precondition → pre}/global_request_headers.rb +4 -4
  25. data/lib/webspicy/specification/{precondition → pre}/robust_to_invalid_input.rb +4 -4
  26. data/lib/webspicy/specification/service.rb +58 -24
  27. data/lib/webspicy/specification/test_case.rb +10 -17
  28. data/lib/webspicy/support.rb +32 -0
  29. data/lib/webspicy/support/data_object.rb +25 -0
  30. data/lib/webspicy/support/hooks.rb +65 -0
  31. data/lib/webspicy/support/world.rb +47 -0
  32. data/lib/webspicy/tester.rb +180 -60
  33. data/lib/webspicy/tester/asserter.rb +9 -4
  34. data/lib/webspicy/tester/assertions.rb +8 -9
  35. data/lib/webspicy/tester/client.rb +4 -50
  36. data/lib/webspicy/tester/failure.rb +6 -0
  37. data/lib/webspicy/tester/fakeses.rb +41 -0
  38. data/lib/webspicy/tester/fakeses/email.rb +38 -0
  39. data/lib/webspicy/tester/fakesmtp.rb +39 -0
  40. data/lib/webspicy/tester/fakesmtp/email.rb +27 -0
  41. data/lib/webspicy/tester/file_checker.rb +22 -0
  42. data/lib/webspicy/tester/invocation.rb +15 -196
  43. data/lib/webspicy/tester/reporter.rb +85 -0
  44. data/lib/webspicy/tester/reporter/composite.rb +38 -0
  45. data/lib/webspicy/tester/reporter/documentation.rb +74 -0
  46. data/lib/webspicy/tester/reporter/error_count.rb +25 -0
  47. data/lib/webspicy/tester/reporter/exceptions.rb +62 -0
  48. data/lib/webspicy/tester/reporter/file_progress.rb +25 -0
  49. data/lib/webspicy/tester/reporter/file_summary.rb +43 -0
  50. data/lib/webspicy/tester/reporter/progress.rb +30 -0
  51. data/lib/webspicy/tester/reporter/summary.rb +63 -0
  52. data/lib/webspicy/tester/result.rb +142 -0
  53. data/lib/webspicy/tester/result/assert_met.rb +29 -0
  54. data/lib/webspicy/tester/result/check.rb +33 -0
  55. data/lib/webspicy/tester/result/errcondition_met.rb +29 -0
  56. data/lib/webspicy/tester/result/error_schema_met.rb +25 -0
  57. data/lib/webspicy/tester/result/invocation_succeeded.rb +13 -0
  58. data/lib/webspicy/tester/result/output_schema_met.rb +25 -0
  59. data/lib/webspicy/tester/result/postcondition_met.rb +29 -0
  60. data/lib/webspicy/tester/result/response_header_met.rb +43 -0
  61. data/lib/webspicy/tester/result/response_status_met.rb +25 -0
  62. data/lib/webspicy/version.rb +2 -2
  63. data/lib/webspicy/web.rb +4 -0
  64. data/lib/webspicy/web/client.rb +15 -0
  65. data/lib/webspicy/{tester → web}/client/http_client.rb +34 -14
  66. data/lib/webspicy/{tester → web}/client/rack_test_client.rb +3 -3
  67. data/lib/webspicy/{tester → web}/client/support.rb +2 -2
  68. data/lib/webspicy/web/invocation.rb +68 -0
  69. data/lib/webspicy/web/mocker.rb +90 -0
  70. data/lib/webspicy/{mocker → web/mocker}/config.ru +3 -2
  71. data/lib/webspicy/{openapi.rb → web/openapi.rb} +0 -0
  72. data/lib/webspicy/web/openapi/generator.rb +129 -0
  73. data/spec/unit/configuration/scope/test_each_service.rb +2 -2
  74. data/spec/unit/configuration/scope/test_each_specification.rb +7 -7
  75. data/spec/unit/specification/{precondition → pre}/test_global_request_headers.rb +9 -4
  76. data/spec/unit/specification/test_condition.rb +44 -0
  77. data/spec/unit/support/hooks/test_fire_after_each.rb +53 -0
  78. data/spec/unit/{tester/client/test_around.rb → support/hooks/test_fire_around.rb} +15 -10
  79. data/spec/unit/support/hooks/test_fire_before_each.rb +53 -0
  80. data/spec/unit/support/world/fixtures/array.json +8 -0
  81. data/spec/unit/support/world/fixtures/queue.rb +1 -0
  82. data/spec/unit/support/world/fixtures/single.json +11 -0
  83. data/spec/unit/support/world/fixtures/yaml.yml +3 -0
  84. data/spec/unit/support/world/test_world.rb +56 -0
  85. data/spec/unit/test_configuration.rb +50 -1
  86. data/spec/unit/tester/fakeses/test_email.rb +40 -0
  87. data/spec/unit/tester/test_asserter.rb +198 -3
  88. data/spec/unit/tester/test_assertions.rb +8 -6
  89. data/spec/unit/web/mocker/test_mocker.rb +35 -0
  90. data/spec/unit/web/openapi/test_generator.rb +31 -0
  91. metadata +90 -67
  92. data/examples/restful/Gemfile +0 -5
  93. data/examples/restful/Gemfile.lock +0 -105
  94. data/examples/restful/Rakefile +0 -25
  95. data/examples/restful/app.rb +0 -180
  96. data/examples/restful/webspicy/config.rb +0 -23
  97. data/examples/restful/webspicy/rack.rb +0 -7
  98. data/examples/restful/webspicy/real.rb +0 -8
  99. data/examples/restful/webspicy/schema.fio +0 -20
  100. data/examples/restful/webspicy/support/must_be_an_admin.rb +0 -20
  101. data/examples/restful/webspicy/support/must_be_authenticated.rb +0 -48
  102. data/examples/restful/webspicy/support/todo_removed.rb +0 -18
  103. data/examples/restful/webspicy/todo/deleteTodo.yml +0 -52
  104. data/examples/restful/webspicy/todo/getTodo.yml +0 -50
  105. data/examples/restful/webspicy/todo/getTodoSingleServiceFormat.yml +0 -46
  106. data/examples/restful/webspicy/todo/getTodos.yml +0 -36
  107. data/examples/restful/webspicy/todo/options.yml +0 -32
  108. data/examples/restful/webspicy/todo/patchTodo.yml +0 -66
  109. data/examples/restful/webspicy/todo/postCsv.yml +0 -43
  110. data/examples/restful/webspicy/todo/postFile.yml +0 -40
  111. data/examples/restful/webspicy/todo/postTodos.yml +0 -51
  112. data/examples/restful/webspicy/todo/putTodo.yml +0 -65
  113. data/examples/restful/webspicy/todo/todos.csv +0 -4
  114. data/examples/single_spec/spec.yml +0 -59
  115. data/examples/website/config.rb +0 -2
  116. data/examples/website/schema.fio +0 -1
  117. data/examples/website/specification/get-http.yml +0 -30
  118. data/examples/website/specification/get-https.yml +0 -30
  119. data/lib/webspicy/checker.rb +0 -25
  120. data/lib/webspicy/mocker.rb +0 -88
  121. data/lib/webspicy/openapi/generator.rb +0 -127
  122. data/lib/webspicy/tester/rspec_asserter.rb +0 -108
  123. data/lib/webspicy/tester/rspec_matchers.rb +0 -104
  124. data/spec/unit/mocker/test_mocker.rb +0 -32
  125. data/spec/unit/openapi/test_generator.rb +0 -28
@@ -0,0 +1,85 @@
1
+ module Webspicy
2
+ class Tester
3
+ class Reporter
4
+ include Support::Colorize
5
+
6
+ def initialize(io = STDOUT)
7
+ @io = io
8
+ end
9
+ attr_reader :io
10
+
11
+ def init(tester)
12
+ @tester = tester
13
+ end
14
+ attr_reader :tester
15
+
16
+ [
17
+ :config,
18
+ :scope,
19
+ :client,
20
+ :spec_file,
21
+ :specification,
22
+ :service,
23
+ :test_case,
24
+ :invocation,
25
+ :result
26
+ ].each do |meth|
27
+ define_method(meth) do |*args, &bl|
28
+ tester.send(meth, *args, &bl)
29
+ end
30
+ end
31
+
32
+ HOOKS = [
33
+ :before_all,
34
+ :before_all_done,
35
+ :before_scope,
36
+ :scope_done,
37
+ :before_spec_file,
38
+ :spec_file_error,
39
+ :spec_file_done,
40
+ :before_specification,
41
+ :specification_done,
42
+ :before_service,
43
+ :service_done,
44
+ :before_test_case,
45
+ :test_case_done,
46
+ :before_each,
47
+ :before_each_done,
48
+ :before_instrument,
49
+ :instrument_done,
50
+ :before_invocation,
51
+ :invocation_done,
52
+ :before_assertions,
53
+ :check_success,
54
+ :check_failure,
55
+ :check_error,
56
+ :assertions_done,
57
+ :after_each,
58
+ :after_each_done,
59
+ :after_all,
60
+ :after_all_done,
61
+ :report
62
+ ]
63
+
64
+ HOOKS.each do |meth|
65
+ define_method(meth){|*args, &bl|
66
+ }
67
+ end
68
+
69
+ protected
70
+
71
+ def plural(word, count)
72
+ "%d #{word}#{count>1 ? 's' : ''}" % [count]
73
+ end
74
+
75
+ end # class Reporter
76
+ end # class Tester
77
+ end # module Webspicy
78
+ require_relative 'reporter/error_count'
79
+ require_relative 'reporter/progress'
80
+ require_relative 'reporter/summary'
81
+ require_relative 'reporter/documentation'
82
+ require_relative 'reporter/exceptions'
83
+ require_relative 'reporter/composite'
84
+ require_relative 'reporter/file_progress'
85
+ require_relative 'reporter/file_summary'
@@ -0,0 +1,38 @@
1
+ module Webspicy
2
+ class Tester
3
+ class Reporter
4
+ class Composite < Reporter
5
+
6
+ def initialize(*args, &bl)
7
+ super
8
+ @reporters = []
9
+ end
10
+
11
+ def <<(reporter)
12
+ @reporters << reporter
13
+ self
14
+ end
15
+
16
+ def init(tester)
17
+ super
18
+ @reporters.each do |r|
19
+ r.init(tester)
20
+ end
21
+ end
22
+
23
+ HOOKS.each do |meth|
24
+ define_method(meth) do |*args, &bl|
25
+ @reporters.each do |r|
26
+ r.send(meth, *args, &bl)
27
+ end
28
+ end
29
+ end
30
+
31
+ def find(kind)
32
+ @reporters.find{|r| r.is_a?(kind) }
33
+ end
34
+
35
+ end # class Composite
36
+ end # class Reporter
37
+ end # class Tester
38
+ end # module Webspicy
@@ -0,0 +1,74 @@
1
+ module Webspicy
2
+ class Tester
3
+ class Reporter
4
+ class Documentation < Reporter
5
+
6
+ module Helpers
7
+ def spec_file_error_line(spec_file, ex)
8
+ str = colorize_highlight(spec_file.to_s)
9
+ str += "\n " + colorize_error("X #{ex.message}")
10
+ if ex.root_cause && ex.root_cause != ex
11
+ str += "\n " + colorize_error("#{ex.root_cause.message}")
12
+ end
13
+ str
14
+ end
15
+
16
+ def service_line(service, test_case)
17
+ str = service.to_s + ", " + test_case.to_s
18
+ str = colorize_highlight(str)
19
+ end
20
+
21
+ def check_success_line(check)
22
+ " " + colorize_success("v") + " " + check.behavior
23
+ end
24
+
25
+ def check_failure_line(check, ex)
26
+ " " + colorize_error("F " + ex.message)
27
+ end
28
+
29
+ def check_error_line(check, ex)
30
+ " " + colorize_error("E " + ex.message)
31
+ end
32
+ end
33
+ include Helpers
34
+
35
+ def spec_file_error(e)
36
+ io.puts spec_file_error_line(spec_file, e)
37
+ io.puts
38
+ io.flush
39
+ end
40
+
41
+ def before_test_case
42
+ io.puts service_line(service, test_case)
43
+ io.flush
44
+ end
45
+
46
+ def check_success(check)
47
+ io.puts check_success_line(check)
48
+ io.flush
49
+ end
50
+
51
+ def check_failure(check, ex)
52
+ io.puts check_failure_line(check, ex)
53
+ io.flush
54
+ end
55
+
56
+ def check_error(check, ex)
57
+ io.puts check_error_line(check, ex)
58
+ io.flush
59
+ end
60
+
61
+ def test_case_done
62
+ io.puts
63
+ io.flush
64
+ end
65
+
66
+ def service_done
67
+ io.puts
68
+ io.flush
69
+ end
70
+
71
+ end # class Documentation
72
+ end # class Reporter
73
+ end # class Tester
74
+ end # module Webspicy
@@ -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