-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[WIP] Test the webspicy command through webspicy cmd layer.
- Loading branch information
Showing
9 changed files
with
170 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
module Webspicy | ||
module Cmd | ||
|
||
require_relative 'cmd/specification' | ||
|
||
FORMALDOC = Finitio.system(Path.dir/("cmd/formaldoc.fio")) | ||
|
||
def specification(raw, file = nil, scope = Webspicy.default_scope) | ||
raw = YAML.load(raw) if raw.is_a?(String) | ||
Webspicy.with_scope(scope) do | ||
r = FORMALDOC["Specification"].dress(raw) | ||
r.config = scope.config | ||
r.located_at!(file) if file | ||
r | ||
end | ||
rescue Finitio::Error => ex | ||
handle_finitio_error(ex) | ||
end | ||
module_function :specification | ||
|
||
def service(raw, scope = Webspicy.default_scope) | ||
Webspicy.with_scope(scope) do | ||
FORMALDOC["Service"].dress(raw) | ||
end | ||
rescue Finitio::Error => ex | ||
handle_finitio_error(ex) | ||
end | ||
module_function :service | ||
|
||
def test_case(raw, scope = Webspicy.default_scope) | ||
Webspicy.with_scope(scope) do | ||
FORMALDOC["TestCase"].dress(raw) | ||
end | ||
rescue Finitio::Error => ex | ||
handle_finitio_error(ex) | ||
end | ||
module_function :test_case | ||
|
||
def handle_finitio_error(ex) | ||
raise ex | ||
end | ||
module_function :handle_finitio_error | ||
|
||
end # module Cmd | ||
end # module Webspicy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
@import finitio/data | ||
@import webspicy/shared | ||
|
||
Specification = .Webspicy::Cmd::Specification <singleservice> { | ||
command : String | ||
name :? String | ||
description :? String | ||
preconditions :? [String]|String | ||
postconditions :? [String]|String | ||
errconditions :? [String]|String | ||
input_schema :? Schema | ||
output_schema :? Schema | ||
error_schema :? Schema | ||
default_example :? TestCase | ||
examples :? [TestCase] | ||
counterexamples :? [TestCase] | ||
} | ||
|
||
Service = .Webspicy::Cmd::Specification::Service <info> { | ||
description :? String | ||
preconditions :? [String]|String | ||
postconditions :? [String]|String | ||
errconditions :? [String]|String | ||
input_schema :? Schema | ||
output_schema :? Schema | ||
error_schema :? Schema | ||
default_example :? TestCase | ||
examples :? [TestCase] | ||
counterexamples :? [TestCase] | ||
} | ||
|
||
TestCase = .Webspicy::Cmd::Specification::TestCase <info> { | ||
description :? String | ||
metadata :? { ...: .Object } | ||
args :? [String] | ||
assert :? { ...: .Object } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
module Webspicy | ||
module Cmd | ||
class Specification < Webspicy::Specification | ||
|
||
class << self | ||
def info(raw) | ||
new(raw) | ||
end | ||
|
||
def singleservice(raw) | ||
converted = { | ||
name: raw[:name] || "Unamed specification", | ||
command: raw[:command], | ||
services: [ | ||
Webspicy::Cmd.service(raw.reject{|k| k==:command or k==:name }, Webspicy.current_scope) | ||
] | ||
} | ||
info(converted) | ||
rescue => ex | ||
puts "Coucou: #{ex.message}" | ||
puts ex.backtrace.join("\n") | ||
raise | ||
end | ||
end | ||
|
||
def command | ||
@raw[:command] | ||
end | ||
|
||
def to_singleservice | ||
raise NotImplementedError | ||
end | ||
|
||
end # class Specification | ||
end # module Cmd | ||
end # module Webspicy | ||
require_relative 'specification/service' | ||
require_relative 'specification/test_case' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
module Webspicy | ||
module Cmd | ||
class Specification | ||
class Service < Webspicy::Specification::Service | ||
end # class Service | ||
end # class Specification | ||
end # module Web | ||
end # module Webspicy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
module Webspicy | ||
module Cmd | ||
class Specification | ||
class TestCase < Webspicy::Specification::TestCase | ||
end # class TestCase | ||
end # class Specification | ||
end # module Web | ||
end # module Webspicy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
require 'webspicy/cmd' | ||
|
||
Webspicy::Configuration.new(Path.dir) do |c| | ||
c.factory = Webspicy::Cmd | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
--- | ||
command: | ||
webspicy {options} {args} | ||
|
||
examples: | ||
|
||
- description: |- | ||
when called on a passing path | ||
args: | ||
- examples/website/get-http.yml | ||
assert: | ||
exit_code: | ||
0 | ||
stdout: |- | ||
>> specification/get-http.yml | ||
GET http://yourbackendisbroken.dev, it works | ||
v It has a 300 response status | ||
v It has a `Content-Type: text/html` response header | ||
v It has a `Location: https://yourbackendisbroken.dev/?id=1` response header | ||
v Its output meets the expected data schema | ||
1 spec file, 1 example, 0 counterexample | ||
4 assertions, 0 error, 0 failure |