webspicy 0.16.2 → 0.20.0

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 +5 -5
  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 +24 -0
  57. data/lib/webspicy/tester/result/invocation_succeeded.rb +13 -0
  58. data/lib/webspicy/tester/result/output_schema_met.rb +24 -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 +65 -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
@@ -7,38 +7,33 @@ module Webspicy
7
7
  end
8
8
  attr_reader :config
9
9
 
10
- def preconditions
11
- config.preconditions
12
- end
13
-
14
- def postconditions
15
- config.postconditions
16
- end
17
-
18
10
  ###
19
11
  ### Eachers -- Allow navigating the web service definitions
20
12
  ###
21
13
 
22
14
  # Yields each specification file in the current scope
23
- def each_specification_file(&bl)
24
- return enum_for(:each_specification_file) unless block_given?
25
- _each_specification_file(config, &bl)
15
+ def each_specification_file(apply_filter = true, &bl)
16
+ return enum_for(:each_specification_file, apply_filter) unless block_given?
17
+ _each_specification_file(config, apply_filter, &bl)
26
18
  end
27
19
 
28
20
  # Recursive implementation of `each_specification_file` for each
29
21
  # folder in the configuration.
30
- def _each_specification_file(config)
22
+ def _each_specification_file(config, apply_filter = true)
31
23
  folder = config.folder
32
- folder.glob("**/*.yml").select(&to_filter_proc(config.file_filter)).each do |file|
24
+ world = config.folder/"world"
25
+ fs = folder.glob("**/*.yml").reject{|f| f.to_s.start_with?(world.to_s) }
26
+ fs = fs.select(&to_filter_proc(config.file_filter)) if apply_filter
27
+ fs.each do |file|
33
28
  yield file, folder
34
29
  end
35
30
  end
36
31
  private :_each_specification_file
37
32
 
38
33
  # Yields each specification in the current scope in turn.
39
- def each_specification(&bl)
40
- return enum_for(:each_specification) unless block_given?
41
- each_specification_file do |file, folder|
34
+ def each_specification(apply_filter = true, &bl)
35
+ return enum_for(:each_specification, apply_filter) unless block_given?
36
+ each_specification_file(apply_filter) do |file, folder|
42
37
  yield Webspicy.specification(file.load, file, self)
43
38
  end
44
39
  end
@@ -76,6 +71,17 @@ module Webspicy
76
71
  each_generated_counterexamples(service, &bl)
77
72
  end
78
73
 
74
+ def find_test_case(method, url)
75
+ each_specification(false) do |spec|
76
+ next unless spec.url == url
77
+ spec.services.each do |service|
78
+ next unless service.method == method
79
+ return service.examples.first
80
+ end
81
+ end
82
+ nil
83
+ end
84
+
79
85
  ###
80
86
  ### Schemas -- For parsing input and output data schemas found in
81
87
  ### web service definitions
@@ -18,6 +18,11 @@ FileUpload =
18
18
  }
19
19
 
20
20
  Specification = .Webspicy::Specification
21
+ <info> {
22
+ name: String
23
+ url: String
24
+ services: [Service]
25
+ }
21
26
  <singleservice> {
22
27
  name :? String
23
28
  url : String
@@ -25,6 +30,7 @@ Specification = .Webspicy::Specification
25
30
  description : String
26
31
  preconditions :? [String]|String
27
32
  postconditions :? [String]|String
33
+ errconditions :? [String]|String
28
34
  input_schema : Schema
29
35
  output_schema : Schema
30
36
  error_schema : Schema
@@ -33,11 +39,6 @@ Specification = .Webspicy::Specification
33
39
  examples :? [TestCase]
34
40
  counterexamples :? [TestCase]
35
41
  }
36
- <info> {
37
- name: String
38
- url: String
39
- services: [Service]
40
- }
41
42
 
42
43
  Service =
43
44
  .Webspicy::Specification::Service <info> {
@@ -45,6 +46,7 @@ Service =
45
46
  description : String
46
47
  preconditions :? [String]|String
47
48
  postconditions :? [String]|String
49
+ errconditions :? [String]|String
48
50
  input_schema : Schema
49
51
  output_schema : Schema
50
52
  error_schema : Schema
@@ -1,11 +1,13 @@
1
1
  module Webspicy
2
2
  class Specification
3
+ include Support::DataObject
3
4
 
4
5
  def initialize(raw, location = nil)
5
- @raw = raw
6
+ super(raw)
6
7
  @location = location
7
8
  bind_services
8
9
  end
10
+ attr_accessor :config
9
11
  attr_reader :location
10
12
 
11
13
  def self.info(raw)
@@ -46,7 +48,7 @@ module Webspicy
46
48
  end
47
49
 
48
50
  def services
49
- @raw[:services]
51
+ @raw[:services] || []
50
52
  end
51
53
 
52
54
  def url_placeholders
@@ -62,10 +64,6 @@ module Webspicy
62
64
  [ url, rest ]
63
65
  end
64
66
 
65
- def to_info
66
- @raw
67
- end
68
-
69
67
  def to_singleservice
70
68
  raise NotImplementedError
71
69
  end
@@ -87,7 +85,7 @@ module Webspicy
87
85
  end
88
86
 
89
87
  def bind_services
90
- (@raw[:services] ||= []).each do |s|
88
+ services.each do |s|
91
89
  s.specification = self
92
90
  end
93
91
  end
@@ -95,7 +93,10 @@ module Webspicy
95
93
  end # class Specification
96
94
  end # module Webspicy
97
95
  require_relative 'specification/service'
98
- require_relative 'specification/precondition'
99
- require_relative 'specification/postcondition'
96
+ require_relative 'specification/condition'
97
+ require_relative 'specification/pre'
98
+ require_relative 'specification/post'
99
+ require_relative 'specification/err'
100
+ require_relative 'specification/oldies'
100
101
  require_relative 'specification/test_case'
101
102
  require_relative 'specification/file_upload'
@@ -0,0 +1,48 @@
1
+ module Webspicy
2
+ class Specification
3
+ module Condition
4
+ extend Forwardable
5
+
6
+ MATCH_ALL = "__all__"
7
+
8
+ attr_accessor :matching_description
9
+
10
+ # Given a service and a condition, returns a Pre instance of there is a
11
+ # match, nil otherwise.
12
+ def self.match(service, condition)
13
+ end
14
+
15
+ # Bind the condition instance to a current tester.
16
+ def bind(tester)
17
+ @tester = tester
18
+ self
19
+ end
20
+ attr_reader :tester
21
+
22
+ def_delegators :@tester, *[
23
+ :config, :scope, :client,
24
+ :specification, :spec_file,
25
+ :service, :test_case,
26
+ :invocation, :result,
27
+ :reporter
28
+ ]
29
+
30
+ def sooner_or_later(*args, &bl)
31
+ Webspicy::Support.sooner_or_later(*args, &bl)
32
+ end
33
+
34
+ def fail!(msg)
35
+ raise Tester::Failure, msg
36
+ end
37
+
38
+ def to_s
39
+ if matching_description == MATCH_ALL
40
+ self.class.name
41
+ else
42
+ matching_description
43
+ end
44
+ end
45
+
46
+ end # module Condition
47
+ end # class Specification
48
+ end # module Webspicy
@@ -0,0 +1,18 @@
1
+ module Webspicy
2
+ class Specification
3
+ module Err
4
+ include Condition
5
+
6
+ # Instrument the current test_case so as to prepare for errcondition
7
+ # check later
8
+ def instrument
9
+ end
10
+
11
+ # Check that the errcondition is met on last invocation & result
12
+ # of an counterexample
13
+ def check!
14
+ end
15
+
16
+ end # module Err
17
+ end # module Specification
18
+ end # module Webspicy
@@ -0,0 +1,4 @@
1
+ require_relative 'oldies/precondition'
2
+ require_relative 'oldies/postcondition'
3
+ require_relative 'oldies/errcondition'
4
+ require_relative 'oldies/bridge'
@@ -0,0 +1,29 @@
1
+ module Webspicy
2
+ class Specification
3
+ module Oldies
4
+ class Bridge
5
+ include Condition
6
+
7
+ def initialize(target)
8
+ @target = target
9
+ end
10
+ attr_reader :target
11
+
12
+ def instrument
13
+ target.instrument(test_case, client)
14
+ end
15
+
16
+ def check!
17
+ target.check(invocation)
18
+ end
19
+
20
+ def to_s
21
+ "#{target} (backward compatibility bridge)"
22
+ end
23
+
24
+ end # class Bridge
25
+ end # module Errcondition
26
+ end # module Specification
27
+ Precondition = Specification::Precondition
28
+ Postcondition = Specification::Postcondition
29
+ end # module Webspicy
@@ -0,0 +1,22 @@
1
+ module Webspicy
2
+ class Specification
3
+ # Deprecated, use Err instead
4
+ module Errcondition
5
+ include Condition
6
+
7
+ def bind(tester)
8
+ Oldies::Bridge.new(self).bind(tester)
9
+ end
10
+
11
+ def self.match(service, descr)
12
+ end
13
+
14
+ def instrument(test_case, client)
15
+ end
16
+
17
+ def check(invocation)
18
+ end
19
+
20
+ end # module Errcondition
21
+ end # module Specification
22
+ end # module Webspicy
@@ -1,6 +1,12 @@
1
1
  module Webspicy
2
2
  class Specification
3
+ # Deprecated, use Post instead
3
4
  module Postcondition
5
+ include Condition
6
+
7
+ def bind(tester)
8
+ Oldies::Bridge.new(self).bind(tester)
9
+ end
4
10
 
5
11
  def self.match(service, descr)
6
12
  end
@@ -1,6 +1,12 @@
1
1
  module Webspicy
2
2
  class Specification
3
+ # Deprecated, use Pre instead
3
4
  module Precondition
5
+ include Condition
6
+
7
+ def bind(tester)
8
+ Oldies::Bridge.new(self).bind(tester)
9
+ end
4
10
 
5
11
  def self.match(service, pre)
6
12
  end
@@ -15,5 +21,3 @@ module Webspicy
15
21
  end # module Precondition
16
22
  end # class Specification
17
23
  end # module Webspicy
18
- require_relative 'precondition/global_request_headers'
19
- require_relative 'precondition/robust_to_invalid_input'
@@ -0,0 +1,20 @@
1
+ module Webspicy
2
+ class Specification
3
+ module Post
4
+ include Condition
5
+
6
+ # Instrument the current test_case so as to prepare for postcondition
7
+ # check later
8
+ def instrument
9
+ end
10
+
11
+ # Check that the postcondition is met on last invocation & result
12
+ # of an example
13
+ def check!
14
+ end
15
+
16
+ end # module Post
17
+ end # module Specification
18
+ end # module Webspicy
19
+ require_relative "post/missing_condition_impl"
20
+ require_relative "post/unexpected_condition_impl"
@@ -0,0 +1,15 @@
1
+ module Webspicy
2
+ class Specification
3
+ module Postcondition
4
+ class MissingConditionImpl
5
+ include Post
6
+
7
+ def check
8
+ msg = matching_description.gsub(/\(x\)/, "<!>")
9
+ raise "#{msg} (not instrumented)"
10
+ end
11
+
12
+ end # class MissingConditionImpl
13
+ end # module Postcondition
14
+ end # class Specification
15
+ end # module Webspicy
@@ -0,0 +1,15 @@
1
+ module Webspicy
2
+ class Specification
3
+ module Postcondition
4
+ class UnexpectedConditionImpl
5
+ include Post
6
+
7
+ def check
8
+ msg = matching_description.gsub(/\( \)/, "<x>")
9
+ raise "#{msg} (is instrumented)"
10
+ end
11
+
12
+ end # class UnexpectedConditionImpl
13
+ end # module Postcondition
14
+ end # class Specification
15
+ end # module Webspicy
@@ -0,0 +1,19 @@
1
+ module Webspicy
2
+ class Specification
3
+ module Pre
4
+ include Condition
5
+
6
+ # Instrument the current test_case so as to meet the precondition
7
+ def instrument
8
+ end
9
+
10
+ # Provide counterexamples of this precondition for a given service.
11
+ def counterexamples(service)
12
+ []
13
+ end
14
+
15
+ end # module Pre
16
+ end # class Specification
17
+ end # module Webspicy
18
+ require_relative 'pre/global_request_headers'
19
+ require_relative 'pre/robust_to_invalid_input'
@@ -1,8 +1,8 @@
1
1
  module Webspicy
2
2
  class Specification
3
- module Precondition
3
+ module Pre
4
4
  class GlobalRequestHeaders
5
- include Precondition
5
+ include Pre
6
6
 
7
7
  DEFAULT_OPTIONS = {}
8
8
 
@@ -22,7 +22,7 @@ module Webspicy
22
22
  end
23
23
  end
24
24
 
25
- def instrument(test_case, client)
25
+ def instrument
26
26
  extra = headers.reject{|k|
27
27
  test_case.headers.has_key?(k)
28
28
  }
@@ -30,6 +30,6 @@ module Webspicy
30
30
  end
31
31
 
32
32
  end # class GlobalRequestHeaders
33
- end # module Precondition
33
+ end # module Pre
34
34
  end # class Specification
35
35
  end # module Webspicy
@@ -1,8 +1,8 @@
1
1
  module Webspicy
2
2
  class Specification
3
- module Precondition
3
+ module Pre
4
4
  class RobustToInvalidInput
5
- include Precondition
5
+ include Pre
6
6
 
7
7
  def self.match(service, pre)
8
8
  self.new
@@ -40,7 +40,7 @@ module Webspicy
40
40
  def empty_input_counterexamples(service, first)
41
41
  placeholders = service.specification.url_placeholders
42
42
  empty_input = first.params.reject{|k| !placeholders.include?(k) }
43
- if !empty_input.empty? && invalid_input?(service, empty_input)
43
+ if invalid_input?(service, empty_input)
44
44
  [first.mutate({
45
45
  :description => "it is robust to an invalid empty input (RobustToInvalidInput)",
46
46
  :dress_params => false,
@@ -49,7 +49,7 @@ module Webspicy
49
49
  status: Support::StatusRange.str("4xx")
50
50
  },
51
51
  :assert => []
52
- })]
52
+ })]
53
53
  else
54
54
  []
55
55
  end
@@ -63,6 +63,6 @@ module Webspicy
63
63
  end
64
64
 
65
65
  end # class RobustToInvalidInput
66
- end # module Precondition
66
+ end # module Pre
67
67
  end # class Specification
68
68
  end # module Webspicy