Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Test the webspicy command through webspicy cmd layer. #28

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions lib/webspicy/cmd.rb
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
37 changes: 37 additions & 0 deletions lib/webspicy/cmd/formaldoc.fio
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 }
}
38 changes: 38 additions & 0 deletions lib/webspicy/cmd/specification.rb
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}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI

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'
8 changes: 8 additions & 0 deletions lib/webspicy/cmd/specification/service.rb
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
8 changes: 8 additions & 0 deletions lib/webspicy/cmd/specification/test_case.rb
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
4 changes: 0 additions & 4 deletions lib/webspicy/specification/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,6 @@ def dress_params(params)
input_schema.dress(params)
end

def to_s
"#{method} #{specification.url}"
end

private

def compile_preconditions
Expand Down
4 changes: 4 additions & 0 deletions lib/webspicy/web/specification/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ def method
@raw[:method]
end

def to_s
"#{method} #{specification.url}"
end

end # class Service
end # class Specification
end # module Web
Expand Down
5 changes: 5 additions & 0 deletions spec/cmd/config.rb
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
25 changes: 25 additions & 0 deletions spec/cmd/formalspec/base.yml
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