Skip to content

Commit

Permalink
Fix behavior of webspicy https://... and webspicy path/to/spec.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
blambeau committed Mar 14, 2021
1 parent a00dda2 commit 2554d66
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 87 deletions.
59 changes: 0 additions & 59 deletions examples/single_spec/spec.yml

This file was deleted.

60 changes: 35 additions & 25 deletions lib/webspicy/configuration/single_url.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,37 +10,47 @@ def initialize(config, url)
end
attr_reader :url

def each_specification(&bl)
def each_specification_file(*args, &bl)
return enum_for(:each_specification_file) unless block_given?
yield Path.tempfile(["specification",".yml"]).tap{|f|
f.write(specification_src)
}
end

def each_specification(*args, &bl)
return enum_for(:each_specification) unless block_given?
spec = <<~YML
yield Webspicy.specification(specification_src, nil, self)
end

def specification_src
<<~YML.tap{|s| Webspicy.debug(s) }
---
name: |-
Default specification
description: |-
Getting #{url}
url: |-
#{url}
services:
- method: |-
GET
description: |-
Getting #{url}
input_schema: |-
Any
output_schema: |-
Any
error_schema: |-
Any
examples:
- description: |-
it returns a 200
params: {}
expected:
status: 200
method: |-
GET
input_schema: |-
Any
output_schema: |-
Any
error_schema: |-
Any
examples:
- description: |-
it returns a 200
params: {}
expected:
status: 200
YML
Webspicy.debug(spec)
yield Webspicy.specification(spec, nil, self)
end

end # class SingleUrlScope
Expand Down
7 changes: 6 additions & 1 deletion lib/webspicy/configuration/single_yml_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@ def initialize(config, file)
end
attr_reader :file

def each_specification(&bl)
def each_specification_file(*args, &bl)
return enum_for(:each_specification_file) unless block_given?
yield(file)
end

def each_specification(*args, &bl)
return enum_for(:each_specification) unless block_given?
yield Webspicy.specification(file.read, nil, self)
end
Expand Down
6 changes: 4 additions & 2 deletions lib/webspicy/tester/reporter/documentation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ module Helpers
INDENT = " ".freeze

def spec_file_line(spec_file)
relative_path = Path(spec_file).relative_to(config.folder)
colorize_section(">> #{relative_path}", config)
path = Path(spec_file).expand_path
path = path.relative_to(config.folder)
path = spec_file if path.to_s.start_with?(".")
colorize_section(">> #{path}", config)
end

def spec_file_error_line(spec_file, ex)
Expand Down
1 change: 1 addition & 0 deletions spec/unit/test_configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ module Webspicy
expect(c).to be_a(Configuration)
expect(c.folder).to eq(Path.pwd)
expect(c.each_scope.to_a.size).to eql(1)
expect(c.each_scope.to_a.first.each_specification_file.to_a.size).to eql(1)
expect(c.each_scope.to_a.first.each_specification.to_a.size).to eql(1)
end

Expand Down

0 comments on commit 2554d66

Please sign in to comment.