backdrop 0.0.8 → 0.0.9
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 +4 -4
- data/.gitignore +9 -0
- data/.rspec +1 -0
- data/.rubocop.yml +5 -0
- data/.rvmrc +1 -0
- data/.travis.yml +9 -0
- data/Gemfile +10 -0
- data/README.md +40 -0
- data/Rakefile +1 -0
- data/backdrop.gemspec +16 -0
- data/config.ru +2 -0
- data/lib/backdrop/api_builder.rb +19 -0
- data/lib/backdrop/app.rb +17 -0
- data/lib/backdrop/extractor.rb +24 -0
- data/lib/backdrop/rake_task.rb +14 -0
- data/lib/backdrop/runner.rb +20 -0
- data/lib/backdrop/version.rb +3 -0
- data/lib/backdrop.rb +0 -3
- data/lib/tasks/default.rake +8 -0
- data/lib/tasks/rubocop.rake +3 -0
- data/spec/backdrop/api_builder_spec.rb +33 -0
- data/spec/backdrop/extractor_spec.rb +62 -0
- data/spec/backdrop/runner_spec.rb +32 -0
- data/spec/integration/backdrop_spec.rb +39 -0
- data/spec/spec_helper.rb +7 -0
- metadata +24 -2
- data/lib/tasks/backdrop.rake +0 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a475e27a7d3fc87705af139f517a6e00ed727e9f
|
4
|
+
data.tar.gz: 6ec0698f911273e27b9075256a54e2b572f16ce2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b2aad5ee00d310efbd1f987aa1f9a8dbd5057248e6ae11c43c138eb894e1e56b8b1e68d20d297951803e440f89c3cba330253a212298406ff53d7aaf462ced7d
|
7
|
+
data.tar.gz: 046999fe5ae52cdc7a5ba1bf300e326c5a2f3e1576dcde5f05cdad7f6a8aac1245a355555e8f6d1769ae93bdefe8c6619e583cb998d3de5e249a3cd5c847e4f3
|
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/.rubocop.yml
ADDED
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm use --create ruby-2.1.2@backdrop
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
Backdrop [](https://codeclimate.com/github/tpbowden/Backdrop) [](http://badge.fury.io/rb/backdrop) [](https://travis-ci.org/tpbowden/Backdrop) [](https://gemnasium.com/tpbowden/Backdrop)
|
2
|
+
========
|
3
|
+
|
4
|
+
Detects all APIs required and generates stubs based on RAD documentation
|
5
|
+
|
6
|
+
Installation
|
7
|
+
------------
|
8
|
+
|
9
|
+
Gemfile
|
10
|
+
|
11
|
+
gem 'backdrop'
|
12
|
+
|
13
|
+
config/routes.rb
|
14
|
+
|
15
|
+
mount Backdrop::App => '/backdrop'
|
16
|
+
|
17
|
+
Ensure your APIs are generating JSON docs
|
18
|
+
|
19
|
+
RspecApiDocumentation.configure do |config|
|
20
|
+
config.format = :json
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
Generating Stubs
|
25
|
+
----------------
|
26
|
+
|
27
|
+
Create a rake task with an array of paths to your API projects
|
28
|
+
|
29
|
+
lib/tasks/backdrop.rake
|
30
|
+
|
31
|
+
require 'backdrop/rake_task'
|
32
|
+
|
33
|
+
Backdrop::RakeTask.new('output_directory', ['/paths/to/projects'])
|
34
|
+
|
35
|
+
Call `rake backdrop` to create all RAD APIs in the specified output directory
|
36
|
+
|
37
|
+
Dependencies
|
38
|
+
============
|
39
|
+
|
40
|
+
* Ruby >= 2.0.0
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
Dir.glob('lib/tasks/*.rake').each { |task| import task }
|
data/backdrop.gemspec
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
$LOAD_PATH.push File.expand_path('../lib', __FILE__)
|
2
|
+
require 'backdrop/version'
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = 'backdrop'
|
6
|
+
s.version = Backdrop::VERSION
|
7
|
+
s.date = '2014-09-16'
|
8
|
+
s.summary = 'Fixture generation using RAD'
|
9
|
+
s.description = 'Fixture generation using RAD'
|
10
|
+
s.authors = ['Tom Bowden', 'Richard Vickerstaff', 'Adam Whittingham']
|
11
|
+
s.files = `git ls-files`.split($/)
|
12
|
+
s.homepage = 'http://github.com/tpbowden/backdrop'
|
13
|
+
s.license = 'MIT'
|
14
|
+
s.add_dependency 'sinatra', '~> 1.4'
|
15
|
+
s.add_dependency 'rake', '~> 10.1'
|
16
|
+
end
|
data/config.ru
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
module Backdrop
|
4
|
+
class ApiBuilder
|
5
|
+
def initialize(output_dir)
|
6
|
+
@output_dir = output_dir
|
7
|
+
end
|
8
|
+
|
9
|
+
def build_get(project, data)
|
10
|
+
file = data['route']
|
11
|
+
response = data['requests'].first['response_body']
|
12
|
+
path = File.dirname(file)
|
13
|
+
filename = File.basename(file)
|
14
|
+
filepath = File.join(@output_dir, project, path)
|
15
|
+
FileUtils.mkdir_p filepath
|
16
|
+
File.write("#{File.join(filepath, filename)}.json", response)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/backdrop/app.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'sinatra/base'
|
2
|
+
|
3
|
+
module Backdrop
|
4
|
+
class App < Sinatra::Base
|
5
|
+
files = Dir['fixtures/**/*']
|
6
|
+
|
7
|
+
files.each do |file|
|
8
|
+
route = file.gsub 'fixtures', ''
|
9
|
+
route = route.gsub '.json', ''
|
10
|
+
|
11
|
+
get "#{route}" do
|
12
|
+
content_type :json
|
13
|
+
File.read File.expand_path(file)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'backdrop/api_builder'
|
3
|
+
|
4
|
+
module Backdrop
|
5
|
+
class Extractor
|
6
|
+
def project_name(path)
|
7
|
+
path.gsub('/workspace', '').match(/\/(\w+)$/).captures.first
|
8
|
+
end
|
9
|
+
|
10
|
+
def load_docs(project_path)
|
11
|
+
docs_dir = File.join(File.expand_path(project_path), 'doc/api')
|
12
|
+
Dir["#{docs_dir}/**/*.json"]
|
13
|
+
.reject { |filename| filename =~ /index\.json$/ }
|
14
|
+
end
|
15
|
+
|
16
|
+
def build_apis(project, rad_json, output_dir)
|
17
|
+
builder = Backdrop::ApiBuilder.new output_dir
|
18
|
+
rad_json.each do |json_file|
|
19
|
+
json = JSON.parse File.read(json_file)
|
20
|
+
builder.build_get(project, json) if json['http_method'] == 'GET'
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'rake/tasklib'
|
3
|
+
require 'backdrop/runner'
|
4
|
+
|
5
|
+
module Backdrop
|
6
|
+
class RakeTask < Rake::TaskLib
|
7
|
+
def initialize(output_dir, projects)
|
8
|
+
desc 'Run backdrop'
|
9
|
+
task :backdrop do
|
10
|
+
Backdrop::Runner.new(output_dir, projects).run
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'backdrop/extractor'
|
2
|
+
|
3
|
+
module Backdrop
|
4
|
+
class Runner
|
5
|
+
def initialize(output_dir, projects)
|
6
|
+
@projects = projects
|
7
|
+
@output_dir = output_dir
|
8
|
+
end
|
9
|
+
|
10
|
+
def run
|
11
|
+
FileUtils.rm_rf @output_dir
|
12
|
+
extractor = Backdrop::Extractor.new
|
13
|
+
@projects.each do |project_path|
|
14
|
+
project_name = extractor.project_name(project_path)
|
15
|
+
json_to_emulate = extractor.load_docs(project_path)
|
16
|
+
extractor.build_apis project_name, json_to_emulate, @output_dir
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/lib/backdrop.rb
CHANGED
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'backdrop/api_builder'
|
3
|
+
require 'tmpdir'
|
4
|
+
|
5
|
+
describe Backdrop::ApiBuilder do
|
6
|
+
before do
|
7
|
+
@output_dir = Dir.mktmpdir('output')
|
8
|
+
end
|
9
|
+
|
10
|
+
after do
|
11
|
+
FileUtils.remove_entry_secure @output_dir
|
12
|
+
end
|
13
|
+
|
14
|
+
let(:subject) { Backdrop::ApiBuilder.new(@output_dir) }
|
15
|
+
describe '#build_get' do
|
16
|
+
|
17
|
+
let(:sample_api) do
|
18
|
+
{ 'http_method' => 'GET',
|
19
|
+
'route' => '/project/request',
|
20
|
+
'requests' => [{
|
21
|
+
'response_body' => '{"Hello":"World"}'
|
22
|
+
}] }
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'creates a json file for each request/response pair' do
|
26
|
+
subject.build_get 'project', sample_api
|
27
|
+
output = File.read(
|
28
|
+
"#{File.join(@output_dir, 'project', sample_api['route'])}.json"
|
29
|
+
)
|
30
|
+
expect(output).to eq '{"Hello":"World"}'
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'backdrop/extractor'
|
3
|
+
require 'backdrop/api_builder'
|
4
|
+
require 'tmpdir'
|
5
|
+
require 'tempfile'
|
6
|
+
|
7
|
+
describe Backdrop::Extractor do
|
8
|
+
|
9
|
+
describe '#project_name' do
|
10
|
+
context 'when running a normal project' do
|
11
|
+
let(:file_path) { '/files/projects/name' }
|
12
|
+
|
13
|
+
it 'works out the project name based on its path' do
|
14
|
+
expect(subject.project_name(file_path)).to eq 'name'
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
context 'when running a project on Jenkins' do
|
19
|
+
let(:file_path) { '/files/projects/jenkins_project/workspace' }
|
20
|
+
it 'strips workspace/ from the path (for Jenkins builds)' do
|
21
|
+
expect(subject.project_name(file_path)).to eq 'jenkins_project'
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe '#build_apis' do
|
27
|
+
let(:api_builder) { double :api_builder }
|
28
|
+
let(:json) { { 'http_method' => 'GET' } }
|
29
|
+
before do
|
30
|
+
allow(Backdrop::ApiBuilder).to receive(:new).with('output')
|
31
|
+
.and_return api_builder
|
32
|
+
@json_file = Tempfile.new 'file.json'
|
33
|
+
@json_file.write(JSON.generate json)
|
34
|
+
@json_file.rewind
|
35
|
+
end
|
36
|
+
context 'when the request is a GET' do
|
37
|
+
it 'creates an API for each get request' do
|
38
|
+
expect(api_builder).to receive(:build_get).with('project', json)
|
39
|
+
subject.build_apis 'project', [@json_file.path], 'output'
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe '#load_docs' do
|
45
|
+
before do
|
46
|
+
@dir = Dir.mktmpdir
|
47
|
+
FileUtils.mkdir_p("#{@dir}/doc/api")
|
48
|
+
File.write("#{@dir}/doc/api/index.json", '{"hello":"world"}')
|
49
|
+
File.write("#{@dir}/doc/api/api.json", '{"json":"api"}')
|
50
|
+
end
|
51
|
+
|
52
|
+
after do
|
53
|
+
FileUtils.remove_entry_secure @dir
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'loads the files but excludes the index.json' do
|
57
|
+
expect(subject.load_docs(@dir)).to match_array([
|
58
|
+
"#{@dir}/doc/api/api.json"
|
59
|
+
])
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'backdrop/extractor'
|
3
|
+
require 'backdrop/runner'
|
4
|
+
|
5
|
+
describe Backdrop::Runner do
|
6
|
+
|
7
|
+
let(:output_dir) { '/fixtures' }
|
8
|
+
let(:project_paths) { ['/project/path'] }
|
9
|
+
let(:project_name) { 'path' }
|
10
|
+
let(:rad_docs) { ['file.json'] }
|
11
|
+
let(:subject) { Backdrop::Runner.new(output_dir, project_paths) }
|
12
|
+
|
13
|
+
describe '#run' do
|
14
|
+
let(:extractor) do
|
15
|
+
double :extractor, project_name: project_name, load_docs: rad_docs
|
16
|
+
end
|
17
|
+
let(:builder) { double :builder }
|
18
|
+
|
19
|
+
before do
|
20
|
+
allow(Backdrop::Extractor).to receive(:new).and_return extractor
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'works out the project name' do
|
24
|
+
expect(extractor).to receive(:build_apis).with(
|
25
|
+
project_name,
|
26
|
+
rad_docs,
|
27
|
+
output_dir
|
28
|
+
)
|
29
|
+
subject.run
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'backdrop/runner'
|
3
|
+
require 'tmpdir'
|
4
|
+
|
5
|
+
describe 'Backdrop' do
|
6
|
+
|
7
|
+
describe 'running backdrop with an out directory and API project' do
|
8
|
+
let!(:test_dir) { Dir.mktmpdir }
|
9
|
+
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') }
|
12
|
+
let(:rad_output) do
|
13
|
+
{ 'http_method' => 'GET',
|
14
|
+
'route' => '/resource/request',
|
15
|
+
'requests' => [{
|
16
|
+
'response_body' => '{"Hello":"World"}'
|
17
|
+
}] }
|
18
|
+
end
|
19
|
+
|
20
|
+
before do
|
21
|
+
FileUtils.mkdir_p(File.join(project_path, 'doc/api/resource'))
|
22
|
+
File.write(
|
23
|
+
File.join(project_path, '/doc/api/request.json'),
|
24
|
+
JSON.generate(rad_output)
|
25
|
+
)
|
26
|
+
end
|
27
|
+
|
28
|
+
after do
|
29
|
+
FileUtils.remove_entry_secure test_dir
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'creates the APIs in the target directory' do
|
33
|
+
subject.run
|
34
|
+
out = (File.read(File.join(output_path, 'project/resource/request.json')))
|
35
|
+
expect(out).to eq '{"Hello":"World"}'
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
data/spec/spec_helper.rb
ADDED
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.0.
|
4
|
+
version: 0.0.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tom Bowden
|
@@ -46,8 +46,30 @@ executables: []
|
|
46
46
|
extensions: []
|
47
47
|
extra_rdoc_files: []
|
48
48
|
files:
|
49
|
+
- ".gitignore"
|
50
|
+
- ".rspec"
|
51
|
+
- ".rubocop.yml"
|
52
|
+
- ".rvmrc"
|
53
|
+
- ".travis.yml"
|
54
|
+
- Gemfile
|
55
|
+
- README.md
|
56
|
+
- Rakefile
|
57
|
+
- backdrop.gemspec
|
58
|
+
- config.ru
|
49
59
|
- lib/backdrop.rb
|
50
|
-
- lib/
|
60
|
+
- lib/backdrop/api_builder.rb
|
61
|
+
- lib/backdrop/app.rb
|
62
|
+
- lib/backdrop/extractor.rb
|
63
|
+
- lib/backdrop/rake_task.rb
|
64
|
+
- lib/backdrop/runner.rb
|
65
|
+
- lib/backdrop/version.rb
|
66
|
+
- lib/tasks/default.rake
|
67
|
+
- lib/tasks/rubocop.rake
|
68
|
+
- spec/backdrop/api_builder_spec.rb
|
69
|
+
- spec/backdrop/extractor_spec.rb
|
70
|
+
- spec/backdrop/runner_spec.rb
|
71
|
+
- spec/integration/backdrop_spec.rb
|
72
|
+
- spec/spec_helper.rb
|
51
73
|
homepage: http://github.com/tpbowden/backdrop
|
52
74
|
licenses:
|
53
75
|
- MIT
|
data/lib/tasks/backdrop.rake
DELETED