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
@@ -1,5 +0,0 @@
1
- source "https://rubygems.org"
2
-
3
- gem "rake", "~> 12"
4
- gem 'sinatra', "~> 2"
5
- gem "webspicy", path: "../.."
@@ -1,105 +0,0 @@
1
- PATH
2
- remote: ../..
3
- specs:
4
- webspicy (0.16.3)
5
- colorize (~> 0.8.1)
6
- finitio (~> 0.9.0)
7
- http (>= 2)
8
- mustermann (~> 1.0)
9
- mustermann-contrib
10
- openapi3_parser (~> 0.8.2)
11
- path (~> 2.0)
12
- rack-robustness (~> 1.1, >= 1.1.0)
13
- rack-test (~> 0.6.3)
14
- rspec (~> 3.7)
15
- rspec_junit_formatter (~> 0.4.1)
16
-
17
- GEM
18
- remote: https://rubygems.org/
19
- specs:
20
- addressable (2.7.0)
21
- public_suffix (>= 2.0.2, < 5.0)
22
- citrus (3.0.2)
23
- colorize (0.8.1)
24
- commonmarker (0.21.0)
25
- ruby-enum (~> 0.5)
26
- concurrent-ruby (1.1.7)
27
- diff-lcs (1.4.4)
28
- domain_name (0.5.20190701)
29
- unf (>= 0.0.5, < 1.0.0)
30
- ffi (1.13.1)
31
- ffi-compiler (1.0.1)
32
- ffi (>= 1.0.0)
33
- rake
34
- finitio (0.9.0)
35
- citrus (>= 2.4, < 4.0)
36
- hansi (0.2.0)
37
- http (4.4.1)
38
- addressable (~> 2.3)
39
- http-cookie (~> 1.0)
40
- http-form_data (~> 2.2)
41
- http-parser (~> 1.2.0)
42
- http-cookie (1.0.3)
43
- domain_name (~> 0.5)
44
- http-form_data (2.3.0)
45
- http-parser (1.2.2)
46
- ffi-compiler
47
- i18n (1.8.5)
48
- concurrent-ruby (~> 1.0)
49
- mustermann (1.1.1)
50
- ruby2_keywords (~> 0.0.1)
51
- mustermann-contrib (1.1.1)
52
- hansi (~> 0.2.0)
53
- mustermann (= 1.1.1)
54
- openapi3_parser (0.8.2)
55
- commonmarker (~> 0.17)
56
- psych (~> 3.1)
57
- path (2.0.1)
58
- psych (3.2.1)
59
- public_suffix (4.0.6)
60
- rack (2.2.3)
61
- rack-protection (2.1.0)
62
- rack
63
- rack-robustness (1.1.0)
64
- rack-test (0.6.3)
65
- rack (>= 1.0)
66
- rake (12.3.3)
67
- rspec (3.10.0)
68
- rspec-core (~> 3.10.0)
69
- rspec-expectations (~> 3.10.0)
70
- rspec-mocks (~> 3.10.0)
71
- rspec-core (3.10.0)
72
- rspec-support (~> 3.10.0)
73
- rspec-expectations (3.10.0)
74
- diff-lcs (>= 1.2.0, < 2.0)
75
- rspec-support (~> 3.10.0)
76
- rspec-mocks (3.10.0)
77
- diff-lcs (>= 1.2.0, < 2.0)
78
- rspec-support (~> 3.10.0)
79
- rspec-support (3.10.0)
80
- rspec_junit_formatter (0.4.1)
81
- rspec-core (>= 2, < 4, != 2.12.0)
82
- ruby-enum (0.8.0)
83
- i18n
84
- ruby2_keywords (0.0.2)
85
- sinatra (2.1.0)
86
- mustermann (~> 1.0)
87
- rack (~> 2.2)
88
- rack-protection (= 2.1.0)
89
- tilt (~> 2.0)
90
- tilt (2.0.10)
91
- unf (0.1.4)
92
- unf_ext
93
- unf_ext (0.0.7.7)
94
-
95
- PLATFORMS
96
- ruby
97
- x86_64-darwin-15
98
-
99
- DEPENDENCIES
100
- rake (~> 12)
101
- sinatra (~> 2)
102
- webspicy!
103
-
104
- BUNDLED WITH
105
- 2.2.1
@@ -1,25 +0,0 @@
1
- $LOAD_PATH.unshift File.expand_path("..", __FILE__)
2
- require 'app'
3
-
4
- desc "Checks all .yml definition files"
5
- task :check do
6
- Webspicy::Checker.new(Path.dir/'webspicy').call
7
- end
8
-
9
- namespace :test do
10
- desc "Run all tests directly on Sinatra application using rack/test"
11
- task :rack do
12
- Webspicy::Tester.new(Path.dir/'webspicy/rack.rb').call
13
- end
14
-
15
- desc "Runs all tests on the real web server (must be launched previously)"
16
- task :real do
17
- Webspicy::Tester.new(Path.dir/'webspicy/real.rb').call
18
- end
19
- end
20
-
21
- desc "Runs all checks and tests"
22
- task :test => :check
23
- task :test => :"test:rack"
24
-
25
- task :default => :test
@@ -1,180 +0,0 @@
1
- require 'webspicy'
2
- require 'sinatra'
3
- require 'json'
4
- require 'path'
5
- require 'finitio'
6
- require 'rack/robustness'
7
- require 'csv'
8
-
9
- SCHEMA = Finitio::DEFAULT_SYSTEM.parse (Path.dir/('webspicy/schema.fio')).read
10
-
11
- TODOLIST = [
12
- {
13
- id: 1,
14
- description: "Refactor the framework"
15
- },
16
- {
17
- id: 2,
18
- description: "Write documentation"
19
- }
20
- ]
21
-
22
- disable :show_exceptions
23
- enable :raise_errors
24
-
25
- set :todolist, TODOLIST.dup
26
-
27
- set(:auth) do |role|
28
- condition do
29
- token = env['HTTP_AUTHORIZATION']
30
- case token
31
- when NilClass
32
- halt [
33
- 401,
34
- {'Content-Type' => 'application/json'},
35
- [{ error: "Please log in first" }.to_json]
36
- ]
37
- when "Bearer #{role}"
38
- true
39
- else
40
- halt [
41
- 401,
42
- {'Content-Type' => 'application/json'},
43
- [{ error: "#{role.capitalize} required" }.to_json]
44
- ]
45
- end
46
- end
47
- end
48
-
49
- use Rack::Robustness do |g|
50
- g.no_catch_all
51
- g.status 400
52
- g.content_type 'application/json'
53
- g.body{|ex| { error: ex.message }.to_json }
54
- g.on(Finitio::TypeError)
55
- end
56
-
57
- options '*' do
58
- status 204
59
- ""
60
- end
61
-
62
- post '/reset' do
63
- settings.todolist = TODOLIST.dup
64
- status 200
65
- ""
66
- end
67
-
68
- get '/todo/' do
69
- raise unless request.env['HTTP_ACCEPT'] == 'application/json'
70
- content_type :json
71
- settings.todolist.to_json
72
- end
73
-
74
- post '/todo/', :auth => :user do
75
- content_type :json
76
- case todos = loaded_body
77
- when Array
78
- n = 0
79
- todos.each do |todo|
80
- settings.todolist << todo
81
- n += 1
82
- end
83
- status 201
84
- { count: n }.to_json
85
- when Hash
86
- todo = SCHEMA["Todo"].dress(todos)
87
- if settings.todolist.find{|t| t[:id] == todo[:id] }
88
- status 409
89
- {error: "Identifier already in use"}.to_json
90
- else
91
- settings.todolist << todo
92
- status 201
93
- todo.to_json
94
- end
95
- end
96
- end
97
-
98
- get '/todo/:id' do |id|
99
- raise unless request.env['HTTP_ACCEPT'] == 'application/json'
100
- content_type :json
101
- todo = settings.todolist.find{|todo| todo[:id] == Integer(id) }
102
- if todo.nil?
103
- status 404
104
- {error: "No such todo"}.to_json
105
- else
106
- todo.to_json
107
- end
108
- end
109
-
110
- patch '/todo/:id', :auth => :user do |id|
111
- content_type :json
112
- todo = settings.todolist.find{|todo| todo[:id] == Integer(id) }
113
- if todo.nil?
114
- status 404
115
- {error: "No such todo"}.to_json
116
- else
117
- patch = SCHEMA["TodoPatch"].dress(loaded_body.merge("id" => Integer(id)))
118
- patched = todo.merge(patch)
119
- settings.todolist = settings.todolist.reject{|todo| todo[:id] == Integer(id) }
120
- settings.todolist << patched
121
- patched.to_json
122
- end
123
- end
124
-
125
- put '/todo/:id', :auth => :user do |id|
126
- content_type :json
127
- todo = settings.todolist.find{|todo| todo[:id] == Integer(id) }
128
- if todo.nil?
129
- status 404
130
- {error: "No such todo"}.to_json
131
- else
132
- put = SCHEMA["TodoPut"].dress(loaded_body.merge(id: Integer(id)))
133
- updated = todo.merge(put)
134
- settings.todolist = settings.todolist.reject{|todo| todo[:id] == Integer(id) }
135
- settings.todolist << updated
136
- updated.to_json
137
- end
138
- end
139
-
140
- delete '/todo/:id', :auth => :admin do |id|
141
- content_type :json
142
- todo = settings.todolist.find{|todo| todo[:id] == Integer(id) }
143
- if todo.nil?
144
- status 404
145
- {error: "No such todo"}.to_json
146
- else
147
- settings.todolist = settings.todolist.reject{|todo| todo[:id] == Integer(id) }
148
- status 204
149
- content_type "text/plain"
150
- end
151
- end
152
-
153
- ###
154
-
155
- def loaded_body
156
- case ctype = request.content_type
157
- when /json/
158
- JSON.load(request.body.read)
159
- when /csv/
160
- csv = ::CSV.new(request.body.read, :headers => true, :header_converters => :symbol)
161
- csv.map {|row| row.to_hash }
162
- when /multipart\/form-data/
163
- file_body params[:file]
164
- else
165
- halt [415,{},["Unsupported content type: `#{ctype}`"]]
166
- end
167
- end
168
-
169
- def file_body(file)
170
- ctype = Path(file[:filename] || file["filename"]).extname
171
- ctype = (file[:type] || file["type"]) if ctype.nil? or ctype.empty?
172
- case ctype
173
- when /csv/
174
- str = file[:tempfile].read
175
- csv = ::CSV.new(str, :headers => true, :header_converters => :symbol)
176
- csv.map {|row| row.to_hash }
177
- else
178
- halt [415,{},["Unsupported content type: `#{ctype}`\n#{file.inspect}"]]
179
- end
180
- end
@@ -1,23 +0,0 @@
1
- def webspicy_config(&bl)
2
- Webspicy::Configuration.new(Path.dir) do |c|
3
-
4
- c.precondition MustBeAuthenticated
5
- c.precondition MustBeAnAdmin
6
-
7
- c.precondition Webspicy::Specification::Precondition::GlobalRequestHeaders.new({
8
- 'Accept' => 'application/json'
9
- }){|service| service.method == "GET" }
10
-
11
- c.precondition Webspicy::Specification::Precondition::RobustToInvalidInput.new
12
-
13
- c.postcondition TodoRemoved
14
-
15
- c.instrument do |tc, client|
16
- role = tc.metadata[:role]
17
- tc.headers['Authorization'] = "Bearer #{role}" if role
18
- end
19
-
20
- bl.call(c) if bl
21
- end
22
- end
23
- webspicy_config
@@ -1,7 +0,0 @@
1
- require_relative 'config'
2
- webspicy_config do |c|
3
- c.client = Webspicy::Tester::RackTestClient.for(::Sinatra::Application)
4
- c.before_each do |_,client|
5
- client.api.post "/reset"
6
- end
7
- end
@@ -1,8 +0,0 @@
1
- require_relative 'config'
2
- webspicy_config do |c|
3
- c.host = "http://127.0.0.1:4567"
4
- c.client = Webspicy::Tester::HttpClient
5
- c.before_each do |_,client|
6
- client.api.post "http://127.0.0.1:4567/reset"
7
- end
8
- end
@@ -1,20 +0,0 @@
1
- @import webspicy/scalars
2
-
3
- Todo = {
4
- id : Integer
5
- description : String
6
- }
7
-
8
- TodoPatch = {
9
- id : Integer
10
- description :? String
11
- }
12
-
13
- TodoPut = {
14
- id : Integer
15
- description : String
16
- }
17
-
18
- ErrorSchema = {
19
- error: String
20
- }
@@ -1,20 +0,0 @@
1
- require_relative 'must_be_authenticated'
2
- class MustBeAnAdmin < MustBeAuthenticated
3
- include Webspicy::Precondition
4
-
5
- def self.match(service, pre)
6
- MustBeAnAdmin.new(:admin) if pre =~ /Must be an admin/
7
- end
8
-
9
- def counterexamples(service)
10
- examples = super
11
- examples << counterexample(
12
- "When authenticated as a normal user",
13
- "user",
14
- "Admin required",
15
- 401
16
- )
17
- examples
18
- end
19
-
20
- end
@@ -1,48 +0,0 @@
1
- class MustBeAuthenticated
2
- include Webspicy::Precondition
3
-
4
- def initialize(role = :user)
5
- @role = role
6
- end
7
- attr_reader :role
8
-
9
- def self.match(service, pre)
10
- MustBeAuthenticated.new if pre =~ /Must be authenticated/
11
- end
12
-
13
- def instrument(test_case, client)
14
- return if test_case.metadata.has_key?(:role)
15
- return if test_case.description =~ /When not authenticated at all/
16
- test_case.metadata[:role] = role
17
- end
18
-
19
- def counterexamples(service)
20
- examples = super
21
- examples << counterexample(
22
- "When not authenticated at all",
23
- "~",
24
- "Please log in first",
25
- 401
26
- )
27
- examples
28
- end
29
-
30
- def counterexample(description, role, expected, status = 401)
31
- YAML.load <<-YML.gsub(/^\s+[#][ ]/, "")
32
- # description: |-
33
- # #{description} (#{self.class.name} PRE)
34
- # params:
35
- # id: 1
36
- # dress_params:
37
- # false
38
- # metadata:
39
- # role: #{role}
40
- # expected:
41
- # content_type: application/json
42
- # status: #{status}
43
- # assert:
44
- # - "pathFD('', error: '#{expected}')"
45
- YML
46
- end
47
-
48
- end