backdrop 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +8 -8
- data/Gemfile +1 -0
- data/config.ru +1 -1
- data/lib/backdrop/api_builder.rb +11 -1
- data/lib/backdrop/app.rb +15 -9
- data/lib/backdrop/builders/get.rb +10 -0
- data/lib/backdrop/builders/put.rb +11 -0
- data/lib/backdrop/extractor.rb +1 -0
- data/lib/backdrop/version.rb +1 -1
- data/lib/backdrop.rb +2 -0
- data/spec/backdrop/api_builder_spec.rb +22 -1
- data/spec/backdrop/builders/get_spec.rb +22 -0
- data/spec/backdrop/builders/put_spec.rb +25 -0
- data/spec/backdrop/extractor_spec.rb +28 -8
- data/spec/integration/backdrop_spec.rb +40 -17
- data/spec/spec_helper.rb +18 -0
- metadata +5 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MWYxYjlkNWEyM2JiNzJlY2EzODA3NWViYTQ0MTE5MDhmNGVmMmZmMw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ODRjNGZmNmEyOTEzYWFmZTliYmIyZWU3YjdiNjZhY2YzM2EzZWJmOA==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
Njc4NmFkZGU2ZTIyMWZlYWQxMDVmYTY4ODliZjlhNjMwY2M3OGQ1NDAyYjYx
|
10
|
+
NmM3Zjc0ZDNjNTEyODE4NGJiOWVjNDkxNDkwNTJmMDg4Y2Q2ODY5ZWY2M2Fj
|
11
|
+
YTA1MGRhOGE0YjhiNWJkZWJhNGUxZDkyOTAxYmM4ODNlMThmYWU=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MTRhNDhkZDY5MmVjYWRkZjI4ZWIyYmQ3MDIzMmM1NjY4ZjVkMjBmZGRlOGUy
|
14
|
+
NDRlOTlkOTY5ZDBmMzRhYjZhOTBmNWY0NTRlNDBkOTJlMDVjNTE1OWNiNjk1
|
15
|
+
YTNjM2M2OWExMjM1NDM1YTU1MjI0MjViN2Q0OGQwZWUyOGM1NjE=
|
data/Gemfile
CHANGED
data/config.ru
CHANGED
data/lib/backdrop/api_builder.rb
CHANGED
@@ -13,7 +13,17 @@ module Backdrop
|
|
13
13
|
filename = File.basename(file)
|
14
14
|
filepath = File.join(@output_dir, project, path)
|
15
15
|
FileUtils.mkdir_p filepath
|
16
|
-
File.write("#{File.join(filepath, filename)}.
|
16
|
+
File.write("#{File.join(filepath, filename)}.get", response)
|
17
|
+
end
|
18
|
+
|
19
|
+
def build_put(project, data)
|
20
|
+
file = data['route']
|
21
|
+
response = data['requests'].first['response_status']
|
22
|
+
path = File.dirname(file)
|
23
|
+
filename = File.basename(file)
|
24
|
+
filepath = File.join(@output_dir, project, path)
|
25
|
+
FileUtils.mkdir_p filepath
|
26
|
+
File.write("#{File.join(filepath, filename)}.put", response)
|
17
27
|
end
|
18
28
|
end
|
19
29
|
end
|
data/lib/backdrop/app.rb
CHANGED
@@ -1,22 +1,28 @@
|
|
1
1
|
module Backdrop
|
2
2
|
class App < Sinatra::Base
|
3
|
+
SUPPORTED_HTTP_METHODS = [:get, :put]
|
4
|
+
|
3
5
|
def initialize(app = nil)
|
4
6
|
super app
|
5
7
|
self.class.build_routes
|
6
8
|
end
|
7
9
|
|
8
10
|
def self.build_routes
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
get route do
|
16
|
-
content_type :json
|
17
|
-
File.read File.expand_path(file)
|
11
|
+
SUPPORTED_HTTP_METHODS.each do |method|
|
12
|
+
files = Dir["#{Backdrop.configuration.output_dir}/**/*.#{method}"]
|
13
|
+
files.each do |file|
|
14
|
+
route = file.gsub Backdrop.configuration.output_dir, ''
|
15
|
+
route = route.gsub ".#{method}", ''
|
16
|
+
build_route(method, route, file)
|
18
17
|
end
|
19
18
|
end
|
20
19
|
end
|
20
|
+
|
21
|
+
def self.build_route(method, route, file)
|
22
|
+
send(method, route) do
|
23
|
+
builder = Backdrop::Builders.const_get(method.to_s.capitalize).new
|
24
|
+
builder.build(self, file)
|
25
|
+
end
|
26
|
+
end
|
21
27
|
end
|
22
28
|
end
|
data/lib/backdrop/extractor.rb
CHANGED
data/lib/backdrop/version.rb
CHANGED
data/lib/backdrop.rb
CHANGED
@@ -25,9 +25,30 @@ describe Backdrop::ApiBuilder do
|
|
25
25
|
it 'creates a json file for each request/response pair' do
|
26
26
|
subject.build_get 'project', sample_api
|
27
27
|
output = File.read(
|
28
|
-
"#{File.join(@output_dir, 'project', sample_api['route'])}.
|
28
|
+
"#{File.join(@output_dir, 'project', sample_api['route'])}.get"
|
29
29
|
)
|
30
30
|
expect(output).to eq '{"Hello":"World"}'
|
31
31
|
end
|
32
32
|
end
|
33
|
+
|
34
|
+
describe '#build_put' do
|
35
|
+
|
36
|
+
let(:sample_api) do
|
37
|
+
{ 'http_method' => 'PUT',
|
38
|
+
'route' => '/project/request',
|
39
|
+
'requests' => [{
|
40
|
+
'response_body' => nil,
|
41
|
+
'response_status' => 201
|
42
|
+
}] }
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'creates a json file for each request/response pair' do
|
46
|
+
subject.build_put 'project', sample_api
|
47
|
+
output = File.read(
|
48
|
+
"#{File.join(@output_dir, 'project', sample_api['route'])}.put"
|
49
|
+
)
|
50
|
+
expect(output).to eq '201'
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
33
54
|
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'backdrop'
|
2
|
+
describe Backdrop::Builders::Get do
|
3
|
+
describe '#build' do
|
4
|
+
let(:app) { double :app }
|
5
|
+
let(:file) { Tempfile.new 'file' }
|
6
|
+
|
7
|
+
before do
|
8
|
+
file.write('Hello World')
|
9
|
+
file.rewind
|
10
|
+
allow(app).to receive(:content_type).with(:json)
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'sets the content type to json' do
|
14
|
+
subject.build app, file
|
15
|
+
expect(app).to have_received(:content_type).with :json
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'returns the contents of the file' do
|
19
|
+
expect(subject.build app, file).to eq 'Hello World'
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'backdrop'
|
3
|
+
|
4
|
+
describe Backdrop::Builders::Put do
|
5
|
+
describe '#build' do
|
6
|
+
let(:app) { double :app }
|
7
|
+
let(:file) { Tempfile.new 'file' }
|
8
|
+
|
9
|
+
before do
|
10
|
+
file.write(200)
|
11
|
+
file.rewind
|
12
|
+
allow(app).to receive(:content_type).with(:json)
|
13
|
+
allow(app).to receive(:status).with 200
|
14
|
+
end
|
15
|
+
it 'sets the content type to json' do
|
16
|
+
subject.build app, file
|
17
|
+
expect(app).to have_received(:content_type).with(:json)
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'sets the status code to the contents of file' do
|
21
|
+
subject.build app, file
|
22
|
+
expect(app).to have_received(:status).with 200
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -24,20 +24,40 @@ describe Backdrop::Extractor do
|
|
24
24
|
|
25
25
|
describe '#build_apis' do
|
26
26
|
let(:api_builder) { double :api_builder }
|
27
|
-
|
28
|
-
before do
|
29
|
-
allow(Backdrop::ApiBuilder).to receive(:new).with('output')
|
30
|
-
.and_return api_builder
|
31
|
-
@json_file = Tempfile.new 'file.json'
|
32
|
-
@json_file.write(JSON.generate json)
|
33
|
-
@json_file.rewind
|
34
|
-
end
|
27
|
+
|
35
28
|
context 'when the request is a GET' do
|
29
|
+
let(:json) { { 'http_method' => 'GET' } }
|
30
|
+
|
31
|
+
before do
|
32
|
+
allow(Backdrop::ApiBuilder).to receive(:new).with('output')
|
33
|
+
.and_return api_builder
|
34
|
+
@json_file = Tempfile.new 'file.json'
|
35
|
+
@json_file.write(JSON.generate json)
|
36
|
+
@json_file.rewind
|
37
|
+
end
|
38
|
+
|
36
39
|
it 'creates an API for each get request' do
|
37
40
|
expect(api_builder).to receive(:build_get).with('project', json)
|
38
41
|
subject.build_apis 'project', [@json_file.path], 'output'
|
39
42
|
end
|
40
43
|
end
|
44
|
+
|
45
|
+
context 'when the request is a PUT' do
|
46
|
+
let(:json) { { 'http_method' => 'PUT' } }
|
47
|
+
|
48
|
+
before do
|
49
|
+
allow(Backdrop::ApiBuilder).to receive(:new).with('output')
|
50
|
+
.and_return api_builder
|
51
|
+
@json_file = Tempfile.new 'file.json'
|
52
|
+
@json_file.write(JSON.generate json)
|
53
|
+
@json_file.rewind
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'creates an API for each post request' do
|
57
|
+
expect(api_builder).to receive(:build_put).with('project', json)
|
58
|
+
subject.build_apis 'project', [@json_file.path], 'output'
|
59
|
+
end
|
60
|
+
end
|
41
61
|
end
|
42
62
|
|
43
63
|
describe '#load_docs' do
|
@@ -3,46 +3,69 @@ require 'backdrop'
|
|
3
3
|
require 'tmpdir'
|
4
4
|
require 'rack/test'
|
5
5
|
|
6
|
-
describe 'Backdrop' do
|
6
|
+
describe 'Backdrop POST' do
|
7
7
|
include Rack::Test::Methods
|
8
|
-
|
8
|
+
|
9
|
+
before(:all) do
|
10
|
+
@test_dir = Dir.mktmpdir
|
11
|
+
end
|
12
|
+
|
13
|
+
after(:all) do
|
14
|
+
FileUtils.remove_entry_secure @test_dir
|
15
|
+
end
|
9
16
|
let(:subject) { Backdrop::Runner.new(output_path, [project_path]) }
|
10
|
-
let(:output_path) { File.join(test_dir, 'output') }
|
11
|
-
let(:project_path) { File.join(test_dir, 'project') }
|
17
|
+
let(:output_path) { File.join(@test_dir, 'output') }
|
18
|
+
let(:project_path) { File.join(@test_dir, 'project') }
|
12
19
|
|
13
20
|
def app
|
14
21
|
Backdrop.configure do |config|
|
15
|
-
config.output_dir =
|
22
|
+
config.output_dir = output_path
|
16
23
|
end
|
17
24
|
Backdrop::App
|
18
25
|
end
|
19
26
|
|
20
|
-
describe 'running
|
21
|
-
let(:
|
27
|
+
describe 'running with an out directory and API project' do
|
28
|
+
let(:put_output) do
|
29
|
+
{ 'http_method' => 'PUT',
|
30
|
+
'route' => 'resource/put_request',
|
31
|
+
'requests' => [{
|
32
|
+
'response_body' => nil,
|
33
|
+
'response_status' => 201
|
34
|
+
}] }
|
35
|
+
end
|
36
|
+
|
37
|
+
let(:get_output) do
|
22
38
|
{ 'http_method' => 'GET',
|
23
|
-
'route' => '/resource/
|
39
|
+
'route' => '/resource/get_request',
|
24
40
|
'requests' => [{
|
25
41
|
'response_body' => '{"Hello":"World"}'
|
26
42
|
}] }
|
27
43
|
end
|
28
|
-
|
29
44
|
before do
|
30
45
|
FileUtils.mkdir_p(File.join(project_path, 'doc/api/resource'))
|
31
46
|
File.write(
|
32
|
-
File.join(project_path, '/doc/api/
|
33
|
-
JSON.generate(
|
47
|
+
File.join(project_path, '/doc/api/put_request.json'),
|
48
|
+
JSON.generate(put_output)
|
49
|
+
)
|
50
|
+
File.write(
|
51
|
+
File.join(project_path, '/doc/api/get_request.json'),
|
52
|
+
JSON.generate(get_output)
|
34
53
|
)
|
35
54
|
subject.run
|
36
55
|
end
|
37
56
|
|
38
|
-
|
39
|
-
|
57
|
+
context 'when the method is PUT' do
|
58
|
+
it 'responds with the correct status' do
|
59
|
+
put '/project/resource/put_request'
|
60
|
+
expect(last_response.status).to eq 201
|
61
|
+
end
|
40
62
|
end
|
41
63
|
|
42
|
-
|
43
|
-
|
44
|
-
|
64
|
+
context 'when the method is GET' do
|
65
|
+
it 'responds with the response body' do
|
66
|
+
get '/project/resource/get_request'
|
67
|
+
expect(last_response.body).to eq '{"Hello":"World"}'
|
68
|
+
end
|
45
69
|
end
|
46
70
|
end
|
47
|
-
|
48
71
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -21,3 +21,21 @@ SimpleCov.start do
|
|
21
21
|
add_filter 'vendor'
|
22
22
|
add_filter 'spec'
|
23
23
|
end
|
24
|
+
|
25
|
+
RSpec.configure do |config|
|
26
|
+
|
27
|
+
config.default_formatter = 'doc' if config.files_to_run.one?
|
28
|
+
|
29
|
+
config.order = :random
|
30
|
+
|
31
|
+
Kernel.srand config.seed
|
32
|
+
|
33
|
+
config.expect_with :rspec do |expectations|
|
34
|
+
expectations.syntax = :expect
|
35
|
+
end
|
36
|
+
|
37
|
+
config.mock_with :rspec do |mocks|
|
38
|
+
mocks.syntax = :expect
|
39
|
+
mocks.verify_partial_doubles = true
|
40
|
+
end
|
41
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: backdrop
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tom Bowden
|
@@ -59,6 +59,8 @@ files:
|
|
59
59
|
- lib/backdrop.rb
|
60
60
|
- lib/backdrop/api_builder.rb
|
61
61
|
- lib/backdrop/app.rb
|
62
|
+
- lib/backdrop/builders/get.rb
|
63
|
+
- lib/backdrop/builders/put.rb
|
62
64
|
- lib/backdrop/configuration.rb
|
63
65
|
- lib/backdrop/extractor.rb
|
64
66
|
- lib/backdrop/rake_task.rb
|
@@ -67,6 +69,8 @@ files:
|
|
67
69
|
- lib/tasks/default.rake
|
68
70
|
- lib/tasks/rubocop.rake
|
69
71
|
- spec/backdrop/api_builder_spec.rb
|
72
|
+
- spec/backdrop/builders/get_spec.rb
|
73
|
+
- spec/backdrop/builders/put_spec.rb
|
70
74
|
- spec/backdrop/configuration_spec.rb
|
71
75
|
- spec/backdrop/extractor_spec.rb
|
72
76
|
- spec/backdrop/runner_spec.rb
|