backdrop 0.2.5 → 0.3.0
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/.gitignore +1 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +1 -1
- data/Gemfile +2 -1
- data/README.md +1 -1
- data/Rakefile +1 -0
- data/backdrop.gemspec +6 -4
- data/lib/backdrop.rb +9 -7
- data/lib/backdrop/api_builder.rb +29 -0
- data/lib/backdrop/app.rb +5 -22
- data/lib/backdrop/configuration.rb +0 -28
- data/lib/backdrop/version.rb +1 -1
- data/lib/tasks/default.rake +3 -5
- data/spec/backdrop/api_builder_spec.rb +26 -0
- data/spec/backdrop/configuration_spec.rb +0 -57
- data/spec/backdrop_spec.rb +18 -6
- data/spec/factories/example_factory.rb +8 -0
- data/spec/integration/backdrop_end_to_end_spec.rb +34 -0
- data/spec/spec_helper.rb +4 -0
- metadata +18 -26
- data/config.ru +0 -3
- data/lib/backdrop/builders/builder.rb +0 -13
- data/lib/backdrop/builders/get.rb +0 -15
- data/lib/backdrop/builders/put.rb +0 -16
- data/lib/backdrop/extractor.rb +0 -27
- data/lib/backdrop/rake_task.rb +0 -14
- data/lib/backdrop/runner.rb +0 -18
- data/spec/backdrop/builders/builder_spec.rb +0 -59
- data/spec/backdrop/builders/get_spec.rb +0 -49
- data/spec/backdrop/builders/put_spec.rb +0 -54
- data/spec/backdrop/extractor_spec.rb +0 -81
- data/spec/backdrop/runner_spec.rb +0 -31
- data/spec/integration/backdrop_spec.rb +0 -73
checksums.yaml
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
---
|
|
2
2
|
!binary "U0hBMQ==":
|
|
3
3
|
metadata.gz: !binary |-
|
|
4
|
-
|
|
4
|
+
M2MzZjUzNDNkMmVhNGUxMTlhNDAyNzYwOGJlZjVlMzk1N2M5MTQ0NQ==
|
|
5
5
|
data.tar.gz: !binary |-
|
|
6
|
-
|
|
6
|
+
YmViMmI4NTBiZGYxM2U0NGJmMzkwZDBkZmM0NWFkZTgwZTU4MGQxZg==
|
|
7
7
|
SHA512:
|
|
8
8
|
metadata.gz: !binary |-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
OTAxMDAwODMzZDVmNDFjMmVlYmU1ZmEwNThjYjdhM2MwZWNiNWU5MGJkZjk2
|
|
10
|
+
MWE4NGU5YmI1NDE4OWIwMThjZTgxZGI5OWZkZTI1MzM1M2EwNmFkYjNmNWJm
|
|
11
|
+
MzRiMTYzZDhhNDIwZDhhODYwZWJiMDZkOTc4MzIzYWNlNmJlNTU=
|
|
12
12
|
data.tar.gz: !binary |-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
MDAxYmMxM2MzYmYwOTIwNDY3ZWY4NmQ4YWJkZGYwYjk5N2MyYzhhNWVkODUx
|
|
14
|
+
YjJkN2U1MzEzYTMyMzkxYmUwZjQ2YzhjYmYxM2Y5MjU4ZGRlNGQ3OGE0Yjk0
|
|
15
|
+
MTJkYmFjZDNlOWMzYTg4NjVmYWI4M2M1ZDc1MGFhMWUxYjc1ZWE=
|
data/.gitignore
CHANGED
data/.ruby-gemset
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
backdrop
|
data/.ruby-version
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
2.1.4
|
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
data/Rakefile
CHANGED
data/backdrop.gemspec
CHANGED
|
@@ -5,14 +5,16 @@ Gem::Specification.new do |s|
|
|
|
5
5
|
s.name = 'backdrop'
|
|
6
6
|
s.version = Backdrop::VERSION
|
|
7
7
|
s.date = '2014-09-16'
|
|
8
|
-
s.summary = 'Fixture generation
|
|
9
|
-
s.description = '
|
|
10
|
-
|
|
8
|
+
s.summary = 'JSON Fixture generation'
|
|
9
|
+
s.description = 'Create and host fixture generation based on simple ruby
|
|
10
|
+
objects for use in local integration testing against
|
|
11
|
+
multiple remote APIs'
|
|
12
|
+
s.authors = ['Tom Bowden']
|
|
11
13
|
s.files = `git ls-files`.split($RS)
|
|
12
14
|
s.email = 'tom.b1992@gmail.com'
|
|
13
15
|
s.homepage = 'http://github.com/tpbowden/backdrop'
|
|
14
16
|
s.license = 'MIT'
|
|
15
17
|
s.required_ruby_version = '>= 2.0.0'
|
|
16
|
-
s.add_dependency 'sinatra', '~> 1.4'
|
|
17
18
|
s.add_dependency 'rake', '~> 10.1'
|
|
19
|
+
s.add_dependency 'sinatra', '~> 1.4'
|
|
18
20
|
end
|
data/lib/backdrop.rb
CHANGED
|
@@ -1,11 +1,5 @@
|
|
|
1
|
-
require 'sinatra/base'
|
|
2
|
-
require 'backdrop/version'
|
|
3
1
|
require 'backdrop/configuration'
|
|
4
|
-
require 'backdrop/
|
|
5
|
-
require 'backdrop/extractor'
|
|
6
|
-
require 'backdrop/builders/builder'
|
|
7
|
-
require 'backdrop/builders/get'
|
|
8
|
-
require 'backdrop/builders/put'
|
|
2
|
+
require 'backdrop/api_builder'
|
|
9
3
|
require 'backdrop/app'
|
|
10
4
|
|
|
11
5
|
module Backdrop
|
|
@@ -20,4 +14,12 @@ module Backdrop
|
|
|
20
14
|
def self.configure
|
|
21
15
|
yield(configuration) if block_given?
|
|
22
16
|
end
|
|
17
|
+
|
|
18
|
+
def self.load(input)
|
|
19
|
+
APIBuilder.new.build input
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def self.clear
|
|
23
|
+
Backdrop::App.reset!
|
|
24
|
+
end
|
|
23
25
|
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
require 'backdrop/app'
|
|
2
|
+
|
|
3
|
+
module Backdrop
|
|
4
|
+
class APIBuilder
|
|
5
|
+
def build(input)
|
|
6
|
+
if input.respond_to?(:map)
|
|
7
|
+
build_array(input)
|
|
8
|
+
else
|
|
9
|
+
build_single(input)
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
private
|
|
14
|
+
|
|
15
|
+
def build_array(input)
|
|
16
|
+
url = nil
|
|
17
|
+
formatted_data = input.map do |record|
|
|
18
|
+
url = record.delete_field 'backdrop_url'
|
|
19
|
+
record.to_h
|
|
20
|
+
end
|
|
21
|
+
Backdrop::App.load_api(url, JSON.generate(formatted_data))
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def build_single(input)
|
|
25
|
+
url = input.delete_field('backdrop_url')
|
|
26
|
+
Backdrop::App.load_api(url, JSON.generate(input.to_h))
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
data/lib/backdrop/app.rb
CHANGED
|
@@ -1,27 +1,10 @@
|
|
|
1
|
+
require 'sinatra'
|
|
2
|
+
|
|
1
3
|
module Backdrop
|
|
2
4
|
class App < Sinatra::Base
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
super app
|
|
7
|
-
self.class.build_routes
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
def self.build_routes
|
|
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)
|
|
17
|
-
end
|
|
18
|
-
end
|
|
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.route(self, file)
|
|
5
|
+
def self.load_api(url, data)
|
|
6
|
+
get url do
|
|
7
|
+
data
|
|
25
8
|
end
|
|
26
9
|
end
|
|
27
10
|
end
|
|
@@ -1,32 +1,4 @@
|
|
|
1
1
|
module Backdrop
|
|
2
2
|
class Configuration
|
|
3
|
-
attr_accessor :output_dir
|
|
4
|
-
attr_accessor :projects
|
|
5
|
-
attr_reader :http
|
|
6
|
-
|
|
7
|
-
def initialize
|
|
8
|
-
@output_dir = './fixtures'
|
|
9
|
-
@projects = []
|
|
10
|
-
@http = Http.new
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
class Http
|
|
14
|
-
attr_accessor :get
|
|
15
|
-
attr_accessor :put
|
|
16
|
-
attr_reader :http_methods
|
|
17
|
-
|
|
18
|
-
def initialize
|
|
19
|
-
@get = Backdrop::Builders::Get
|
|
20
|
-
@put = Backdrop::Builders::Put
|
|
21
|
-
@http_methods = [:get, :put]
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
def method_missing(method, arg)
|
|
25
|
-
http_method = method.to_s.gsub('=', '')
|
|
26
|
-
self.class.__send__(:attr_accessor, http_method)
|
|
27
|
-
send(method, arg)
|
|
28
|
-
@http_methods << (http_method.to_sym)
|
|
29
|
-
end
|
|
30
|
-
end
|
|
31
3
|
end
|
|
32
4
|
end
|
data/lib/backdrop/version.rb
CHANGED
data/lib/tasks/default.rake
CHANGED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
require 'backdrop/api_builder'
|
|
3
|
+
|
|
4
|
+
describe Backdrop::APIBuilder do
|
|
5
|
+
describe '#build' do
|
|
6
|
+
let(:url) { '/some/location' }
|
|
7
|
+
|
|
8
|
+
context 'when the input is a single item' do
|
|
9
|
+
let(:sample_input) { build :example, backdrop_url: url }
|
|
10
|
+
let(:json) { '{"some":"data"}' }
|
|
11
|
+
it 'tells the server to load the API' do
|
|
12
|
+
expect(Backdrop::App).to receive(:load_api).with url, json
|
|
13
|
+
subject.build sample_input
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
context 'when the input is an array of items' do
|
|
18
|
+
let(:sample_input) { build_list :example, 2, backdrop_url: url }
|
|
19
|
+
let(:json) { '[{"some":"data"},{"some":"data"}]' }
|
|
20
|
+
it 'tells the server to load the API array' do
|
|
21
|
+
expect(Backdrop::App).to receive(:load_api).with url, json
|
|
22
|
+
subject.build sample_input
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
@@ -3,61 +3,4 @@ require 'backdrop'
|
|
|
3
3
|
|
|
4
4
|
describe Backdrop::Configuration do
|
|
5
5
|
|
|
6
|
-
describe '#output_dir' do
|
|
7
|
-
it 'defaults to ./fixtures' do
|
|
8
|
-
expect(subject.output_dir).to eq './fixtures'
|
|
9
|
-
end
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
describe '#output_dir=' do
|
|
13
|
-
it 'can be configured' do
|
|
14
|
-
subject.output_dir = 'somewhere'
|
|
15
|
-
expect(subject.output_dir).to eq 'somewhere'
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
describe '#projects' do
|
|
20
|
-
it 'defaults to empty array' do
|
|
21
|
-
expect(subject.projects).to eq []
|
|
22
|
-
end
|
|
23
|
-
it 'can be configured' do
|
|
24
|
-
subject.projects = [1, 2]
|
|
25
|
-
expect(subject.projects).to eq [1, 2]
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
describe '#http' do
|
|
30
|
-
it 'allows the assignment of any method' do
|
|
31
|
-
expect(subject.http).to be_a Backdrop::Configuration::Http
|
|
32
|
-
end
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
describe Backdrop::Configuration::Http do
|
|
36
|
-
describe '#http_methods' do
|
|
37
|
-
it 'defaults the HTTP methods to the ones with defaults' do
|
|
38
|
-
expect(subject.http_methods).to eq [:get, :put]
|
|
39
|
-
end
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
describe '#METHOD' do
|
|
43
|
-
|
|
44
|
-
it 'allows anything to be set' do
|
|
45
|
-
subject.something = 'hello'
|
|
46
|
-
expect(subject.something).to eq 'hello'
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
it 'adds new methods to the http_methods array' do
|
|
50
|
-
subject.val = 'something'
|
|
51
|
-
expect(subject.http_methods).to include(:val)
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
it 'sets get to be a GET builder' do
|
|
55
|
-
expect(subject.get).to eq Backdrop::Builders::Get
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
it 'sets put to be the PUT builder' do
|
|
59
|
-
expect(subject.put).to eq Backdrop::Builders::Put
|
|
60
|
-
end
|
|
61
|
-
end
|
|
62
|
-
end
|
|
63
6
|
end
|
data/spec/backdrop_spec.rb
CHANGED
|
@@ -20,14 +20,26 @@ describe Backdrop do
|
|
|
20
20
|
end
|
|
21
21
|
|
|
22
22
|
describe '.reset' do
|
|
23
|
-
|
|
24
|
-
Backdrop.configure do |config|
|
|
25
|
-
config.output_dir = 'somewhere'
|
|
26
|
-
end
|
|
27
|
-
end
|
|
23
|
+
let!(:subject) { Backdrop.configuration }
|
|
28
24
|
it 'resets all configuration' do
|
|
29
25
|
Backdrop.reset
|
|
30
|
-
expect(Backdrop.configuration
|
|
26
|
+
expect(Backdrop.configuration).to_not eq subject
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
describe '.load' do
|
|
31
|
+
let(:input) { %w('some', 'data') }
|
|
32
|
+
it 'delegates to the Backdrop API Builder' do
|
|
33
|
+
expect(Backdrop::APIBuilder)
|
|
34
|
+
.to receive_message_chain('new.build').with input
|
|
35
|
+
described_class.load input
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
describe '.clear' do
|
|
40
|
+
it 'clears all routes from the web server' do
|
|
41
|
+
expect(Backdrop::App).to receive(:reset!)
|
|
42
|
+
Backdrop.clear
|
|
31
43
|
end
|
|
32
44
|
end
|
|
33
45
|
end
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
require 'rack/test'
|
|
3
|
+
require 'backdrop'
|
|
4
|
+
|
|
5
|
+
describe Backdrop do
|
|
6
|
+
include Rack::Test::Methods
|
|
7
|
+
|
|
8
|
+
def app
|
|
9
|
+
Backdrop::App
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
before do
|
|
13
|
+
Backdrop.clear
|
|
14
|
+
Backdrop.load sample_factory_data
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
context 'when it is a single object' do
|
|
18
|
+
let(:sample_factory_data) { build :example }
|
|
19
|
+
|
|
20
|
+
it 'builds an API based on factory girl data' do
|
|
21
|
+
get '/example/data'
|
|
22
|
+
expect(last_response.body).to eq '{"some":"data"}'
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
context 'when it is an array of objects' do
|
|
27
|
+
let(:sample_factory_data) { build_list :example, 2 }
|
|
28
|
+
|
|
29
|
+
it 'builds an API based on the array of factory girl data' do
|
|
30
|
+
get '/example/data'
|
|
31
|
+
expect(last_response.body).to eq '[{"some":"data"},{"some":"data"}]'
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
data/spec/spec_helper.rb
CHANGED
|
@@ -22,9 +22,13 @@ SimpleCov.start do
|
|
|
22
22
|
add_filter 'spec'
|
|
23
23
|
end
|
|
24
24
|
|
|
25
|
+
require 'factory_girl'
|
|
26
|
+
FactoryGirl.find_definitions
|
|
27
|
+
|
|
25
28
|
RSpec.configure do |config|
|
|
26
29
|
|
|
27
30
|
config.default_formatter = 'doc' if config.files_to_run.one?
|
|
31
|
+
config.include FactoryGirl::Syntax::Methods
|
|
28
32
|
|
|
29
33
|
config.order = :random
|
|
30
34
|
|
metadata
CHANGED
|
@@ -1,46 +1,46 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: backdrop
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.3.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Tom Bowden
|
|
8
|
-
- Richard Vickerstaff
|
|
9
|
-
- Adam Whittingham
|
|
10
8
|
autorequire:
|
|
11
9
|
bindir: bin
|
|
12
10
|
cert_chain: []
|
|
13
11
|
date: 2014-09-16 00:00:00.000000000 Z
|
|
14
12
|
dependencies:
|
|
15
13
|
- !ruby/object:Gem::Dependency
|
|
16
|
-
name:
|
|
14
|
+
name: rake
|
|
17
15
|
requirement: !ruby/object:Gem::Requirement
|
|
18
16
|
requirements:
|
|
19
17
|
- - ~>
|
|
20
18
|
- !ruby/object:Gem::Version
|
|
21
|
-
version: '1
|
|
19
|
+
version: '10.1'
|
|
22
20
|
type: :runtime
|
|
23
21
|
prerelease: false
|
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
|
25
23
|
requirements:
|
|
26
24
|
- - ~>
|
|
27
25
|
- !ruby/object:Gem::Version
|
|
28
|
-
version: '1
|
|
26
|
+
version: '10.1'
|
|
29
27
|
- !ruby/object:Gem::Dependency
|
|
30
|
-
name:
|
|
28
|
+
name: sinatra
|
|
31
29
|
requirement: !ruby/object:Gem::Requirement
|
|
32
30
|
requirements:
|
|
33
31
|
- - ~>
|
|
34
32
|
- !ruby/object:Gem::Version
|
|
35
|
-
version: '
|
|
33
|
+
version: '1.4'
|
|
36
34
|
type: :runtime
|
|
37
35
|
prerelease: false
|
|
38
36
|
version_requirements: !ruby/object:Gem::Requirement
|
|
39
37
|
requirements:
|
|
40
38
|
- - ~>
|
|
41
39
|
- !ruby/object:Gem::Version
|
|
42
|
-
version: '
|
|
43
|
-
description:
|
|
40
|
+
version: '1.4'
|
|
41
|
+
description: ! "Create and host fixture generation based on simple ruby\n objects
|
|
42
|
+
for use in local integration testing against\n multiple remote
|
|
43
|
+
APIs"
|
|
44
44
|
email: tom.b1992@gmail.com
|
|
45
45
|
executables: []
|
|
46
46
|
extensions: []
|
|
@@ -49,33 +49,25 @@ files:
|
|
|
49
49
|
- .gitignore
|
|
50
50
|
- .rspec
|
|
51
51
|
- .rubocop.yml
|
|
52
|
-
- .
|
|
52
|
+
- .ruby-gemset
|
|
53
|
+
- .ruby-version
|
|
53
54
|
- .travis.yml
|
|
54
55
|
- Gemfile
|
|
55
56
|
- README.md
|
|
56
57
|
- Rakefile
|
|
57
58
|
- backdrop.gemspec
|
|
58
|
-
- config.ru
|
|
59
59
|
- lib/backdrop.rb
|
|
60
|
+
- lib/backdrop/api_builder.rb
|
|
60
61
|
- lib/backdrop/app.rb
|
|
61
|
-
- lib/backdrop/builders/builder.rb
|
|
62
|
-
- lib/backdrop/builders/get.rb
|
|
63
|
-
- lib/backdrop/builders/put.rb
|
|
64
62
|
- lib/backdrop/configuration.rb
|
|
65
|
-
- lib/backdrop/extractor.rb
|
|
66
|
-
- lib/backdrop/rake_task.rb
|
|
67
|
-
- lib/backdrop/runner.rb
|
|
68
63
|
- lib/backdrop/version.rb
|
|
69
64
|
- lib/tasks/default.rake
|
|
70
65
|
- lib/tasks/rubocop.rake
|
|
71
|
-
- spec/backdrop/
|
|
72
|
-
- spec/backdrop/builders/get_spec.rb
|
|
73
|
-
- spec/backdrop/builders/put_spec.rb
|
|
66
|
+
- spec/backdrop/api_builder_spec.rb
|
|
74
67
|
- spec/backdrop/configuration_spec.rb
|
|
75
|
-
- spec/backdrop/extractor_spec.rb
|
|
76
|
-
- spec/backdrop/runner_spec.rb
|
|
77
68
|
- spec/backdrop_spec.rb
|
|
78
|
-
- spec/
|
|
69
|
+
- spec/factories/example_factory.rb
|
|
70
|
+
- spec/integration/backdrop_end_to_end_spec.rb
|
|
79
71
|
- spec/spec_helper.rb
|
|
80
72
|
homepage: http://github.com/tpbowden/backdrop
|
|
81
73
|
licenses:
|
|
@@ -97,8 +89,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
97
89
|
version: '0'
|
|
98
90
|
requirements: []
|
|
99
91
|
rubyforge_project:
|
|
100
|
-
rubygems_version: 2.4.
|
|
92
|
+
rubygems_version: 2.4.2
|
|
101
93
|
signing_key:
|
|
102
94
|
specification_version: 4
|
|
103
|
-
summary: Fixture generation
|
|
95
|
+
summary: JSON Fixture generation
|
|
104
96
|
test_files: []
|
data/config.ru
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
module Backdrop
|
|
2
|
-
class Builder
|
|
3
|
-
def build_response(output, project, data, response)
|
|
4
|
-
file = data['requests'].first['request_path'].split('?')[0]
|
|
5
|
-
method = data['http_method'].downcase
|
|
6
|
-
path = File.dirname file
|
|
7
|
-
filename = File.basename file
|
|
8
|
-
filepath = File.join(output, project, path)
|
|
9
|
-
FileUtils.mkdir_p filepath
|
|
10
|
-
File.write("#{File.join(filepath, filename)}.#{method}", response)
|
|
11
|
-
end
|
|
12
|
-
end
|
|
13
|
-
end
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
module Backdrop
|
|
2
|
-
module Builders
|
|
3
|
-
class Get < Builder
|
|
4
|
-
def route(app, file)
|
|
5
|
-
app.content_type :json
|
|
6
|
-
File.read File.expand_path(file)
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
def build(output, project, data)
|
|
10
|
-
response = data['requests'].first['response_body']
|
|
11
|
-
build_response(output, project, data, response)
|
|
12
|
-
end
|
|
13
|
-
end
|
|
14
|
-
end
|
|
15
|
-
end
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
module Backdrop
|
|
2
|
-
module Builders
|
|
3
|
-
class Put < Builder
|
|
4
|
-
def route(app, file)
|
|
5
|
-
app.content_type :json
|
|
6
|
-
code = File.read File.expand_path(file)
|
|
7
|
-
app.status code.to_i
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
def build(output, project, data)
|
|
11
|
-
response = data['requests'].first['response_status']
|
|
12
|
-
build_response(output, project, data, response)
|
|
13
|
-
end
|
|
14
|
-
end
|
|
15
|
-
end
|
|
16
|
-
end
|
data/lib/backdrop/extractor.rb
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
require 'json'
|
|
2
|
-
|
|
3
|
-
module Backdrop
|
|
4
|
-
class Extractor
|
|
5
|
-
def project_name(path)
|
|
6
|
-
path.gsub('/workspace', '').match(/\/(\w+)$/).captures.first
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
def load_docs(project_path)
|
|
10
|
-
docs_dir = File.join(File.expand_path(project_path), 'doc/api')
|
|
11
|
-
Dir["#{docs_dir}/**/*.json"]
|
|
12
|
-
.reject { |filename| filename =~ /index\.json$/ }
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
def build_apis(project, rad_json, output_dir)
|
|
16
|
-
rad_json.each do |json_file|
|
|
17
|
-
json = JSON.parse File.read(json_file)
|
|
18
|
-
method = json['http_method'].downcase.to_sym
|
|
19
|
-
supported_methods = Backdrop.configuration.http.http_methods
|
|
20
|
-
if supported_methods.include? method
|
|
21
|
-
builder = Backdrop.configuration.http.send(method)
|
|
22
|
-
builder.new.build output_dir, project, json
|
|
23
|
-
end
|
|
24
|
-
end
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
end
|
data/lib/backdrop/rake_task.rb
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
require 'rake'
|
|
2
|
-
require 'rake/tasklib'
|
|
3
|
-
require 'backdrop'
|
|
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
|
data/lib/backdrop/runner.rb
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
module Backdrop
|
|
2
|
-
class Runner
|
|
3
|
-
def initialize(output_dir, projects)
|
|
4
|
-
@projects = projects
|
|
5
|
-
@output_dir = output_dir
|
|
6
|
-
end
|
|
7
|
-
|
|
8
|
-
def run
|
|
9
|
-
FileUtils.rm_rf @output_dir
|
|
10
|
-
extractor = Backdrop::Extractor.new
|
|
11
|
-
@projects.each do |project_path|
|
|
12
|
-
project_name = extractor.project_name(project_path)
|
|
13
|
-
json_to_emulate = extractor.load_docs(project_path)
|
|
14
|
-
extractor.build_apis project_name, json_to_emulate, @output_dir
|
|
15
|
-
end
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
end
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
require 'backdrop'
|
|
3
|
-
|
|
4
|
-
describe Backdrop::Builder do
|
|
5
|
-
describe '#build_response' do
|
|
6
|
-
|
|
7
|
-
before do
|
|
8
|
-
@output_dir = Dir.mktmpdir('output')
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
after do
|
|
12
|
-
FileUtils.remove_entry_secure @output_dir
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
context 'when the path has no query params' do
|
|
16
|
-
|
|
17
|
-
let(:sample_data) do
|
|
18
|
-
{ 'http_method' => 'GET',
|
|
19
|
-
'route' => '/project/:property',
|
|
20
|
-
'requests' => [{
|
|
21
|
-
'request_path' => '/resource/get_request',
|
|
22
|
-
'response_body' => '{"Hello":"World"}'
|
|
23
|
-
}] }
|
|
24
|
-
end
|
|
25
|
-
let(:project) { 'project' }
|
|
26
|
-
let(:response) { 'some response' }
|
|
27
|
-
|
|
28
|
-
it 'creates the response file with given input' do
|
|
29
|
-
subject.build_response(@output_dir, project, sample_data, response)
|
|
30
|
-
output = File.read(
|
|
31
|
-
"#{File.join(@output_dir, 'project', '/resource/get_request')}.get"
|
|
32
|
-
)
|
|
33
|
-
expect(output).to eq response
|
|
34
|
-
end
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
context 'when the path has query params' do
|
|
38
|
-
|
|
39
|
-
let(:sample_data) do
|
|
40
|
-
{ 'http_method' => 'GET',
|
|
41
|
-
'route' => '/project/:property',
|
|
42
|
-
'requests' => [{
|
|
43
|
-
'request_path' => '/resource/get_request?query=something',
|
|
44
|
-
'response_body' => '{"Hello":"World"}'
|
|
45
|
-
}] }
|
|
46
|
-
end
|
|
47
|
-
let(:project) { 'project' }
|
|
48
|
-
let(:response) { 'some response' }
|
|
49
|
-
|
|
50
|
-
it 'creates the response file, stripping the query params' do
|
|
51
|
-
subject.build_response(@output_dir, project, sample_data, response)
|
|
52
|
-
output = File.read(
|
|
53
|
-
"#{File.join(@output_dir, 'project', '/resource/get_request')}.get"
|
|
54
|
-
)
|
|
55
|
-
expect(output).to eq response
|
|
56
|
-
end
|
|
57
|
-
end
|
|
58
|
-
end
|
|
59
|
-
end
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
require 'backdrop'
|
|
2
|
-
describe Backdrop::Builders::Get do
|
|
3
|
-
describe '#route' 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.route 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.route app, file).to eq 'Hello World'
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
describe '#build' do
|
|
24
|
-
before do
|
|
25
|
-
@output_dir = Dir.mktmpdir('output')
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
after do
|
|
29
|
-
FileUtils.remove_entry_secure @output_dir
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
let(:data) do
|
|
33
|
-
{ 'http_method' => 'GET',
|
|
34
|
-
'route' => '/project/:property',
|
|
35
|
-
'requests' => [{
|
|
36
|
-
'request_path' => '/resource/request',
|
|
37
|
-
'response_body' => '{"Hello":"World"}'
|
|
38
|
-
}] }
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
it 'creates a file for each request' do
|
|
42
|
-
subject.build @output_dir, 'project', data
|
|
43
|
-
output = File.read(
|
|
44
|
-
"#{File.join(@output_dir, 'project', 'resource/request')}.get"
|
|
45
|
-
)
|
|
46
|
-
expect(output).to eq '{"Hello":"World"}'
|
|
47
|
-
end
|
|
48
|
-
end
|
|
49
|
-
end
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
require 'backdrop'
|
|
3
|
-
|
|
4
|
-
describe Backdrop::Builders::Put do
|
|
5
|
-
describe '#route' 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.route 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.route app, file
|
|
22
|
-
expect(app).to have_received(:status).with 200
|
|
23
|
-
end
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
describe '#build' do
|
|
27
|
-
|
|
28
|
-
before do
|
|
29
|
-
@output_dir = Dir.mktmpdir('output')
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
after do
|
|
33
|
-
FileUtils.remove_entry_secure @output_dir
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
let(:data) do
|
|
37
|
-
{ 'http_method' => 'PUT',
|
|
38
|
-
'route' => '/project/:property',
|
|
39
|
-
'requests' => [{
|
|
40
|
-
'request_path' => '/resource/request',
|
|
41
|
-
'response_body' => '{"Hello":"World"}',
|
|
42
|
-
'response_status' => 201
|
|
43
|
-
}] }
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
it 'creates a file with the status for each request' do
|
|
47
|
-
subject.build @output_dir, 'project', data
|
|
48
|
-
output = File.read(
|
|
49
|
-
"#{File.join(@output_dir, 'project', '/resource/request')}.put"
|
|
50
|
-
)
|
|
51
|
-
expect(output).to eq '201'
|
|
52
|
-
end
|
|
53
|
-
end
|
|
54
|
-
end
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
require 'backdrop'
|
|
3
|
-
require 'tmpdir'
|
|
4
|
-
require 'tempfile'
|
|
5
|
-
|
|
6
|
-
describe Backdrop::Extractor do
|
|
7
|
-
|
|
8
|
-
describe '#project_name' do
|
|
9
|
-
context 'when running a normal project' do
|
|
10
|
-
let(:file_path) { '/files/projects/name' }
|
|
11
|
-
|
|
12
|
-
it 'works out the project name based on its path' do
|
|
13
|
-
expect(subject.project_name(file_path)).to eq 'name'
|
|
14
|
-
end
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
context 'when running a project on Jenkins' do
|
|
18
|
-
let(:file_path) { '/files/projects/jenkins_project/workspace' }
|
|
19
|
-
it 'strips workspace/ from the path (for Jenkins builds)' do
|
|
20
|
-
expect(subject.project_name(file_path)).to eq 'jenkins_project'
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
describe '#build_apis' do
|
|
26
|
-
let(:builder) { double :builder }
|
|
27
|
-
|
|
28
|
-
context 'when the method is defined' do
|
|
29
|
-
let(:json) { { 'http_method' => 'GET' } }
|
|
30
|
-
|
|
31
|
-
before do
|
|
32
|
-
allow(Backdrop::Builders::Get).to receive(:new)
|
|
33
|
-
.and_return builder
|
|
34
|
-
@json_file = Tempfile.new 'file.json'
|
|
35
|
-
@json_file.write(JSON.generate json)
|
|
36
|
-
@json_file.rewind
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
it 'creates an API for each request' do
|
|
40
|
-
expect(builder).to receive(:build).with('output', 'project', json)
|
|
41
|
-
subject.build_apis 'project', [@json_file.path], 'output'
|
|
42
|
-
end
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
context 'when the method is not defined' do
|
|
46
|
-
let(:json) { { 'http_method' => 'SOMETHING' } }
|
|
47
|
-
|
|
48
|
-
before do
|
|
49
|
-
allow(Backdrop::Builders::Get).to receive(:new)
|
|
50
|
-
.and_return 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 request' do
|
|
57
|
-
expect(builder).to_not receive(:build)
|
|
58
|
-
subject.build_apis 'project', [@json_file.path], 'output'
|
|
59
|
-
end
|
|
60
|
-
end
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
describe '#load_docs' do
|
|
64
|
-
before do
|
|
65
|
-
@dir = Dir.mktmpdir
|
|
66
|
-
FileUtils.mkdir_p("#{@dir}/doc/api")
|
|
67
|
-
File.write("#{@dir}/doc/api/index.json", '{"hello":"world"}')
|
|
68
|
-
File.write("#{@dir}/doc/api/api.json", '{"json":"api"}')
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
after do
|
|
72
|
-
FileUtils.remove_entry_secure @dir
|
|
73
|
-
end
|
|
74
|
-
|
|
75
|
-
it 'loads the files but excludes the index.json' do
|
|
76
|
-
expect(subject.load_docs(@dir)).to match_array([
|
|
77
|
-
"#{@dir}/doc/api/api.json"
|
|
78
|
-
])
|
|
79
|
-
end
|
|
80
|
-
end
|
|
81
|
-
end
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
require 'backdrop'
|
|
3
|
-
|
|
4
|
-
describe Backdrop::Runner do
|
|
5
|
-
|
|
6
|
-
let(:output_dir) { '/fixtures' }
|
|
7
|
-
let(:project_paths) { ['/project/path'] }
|
|
8
|
-
let(:project_name) { 'path' }
|
|
9
|
-
let(:rad_docs) { ['file.json'] }
|
|
10
|
-
let(:subject) { Backdrop::Runner.new(output_dir, project_paths) }
|
|
11
|
-
|
|
12
|
-
describe '#run' do
|
|
13
|
-
let(:extractor) do
|
|
14
|
-
double :extractor, project_name: project_name, load_docs: rad_docs
|
|
15
|
-
end
|
|
16
|
-
let(:builder) { double :builder }
|
|
17
|
-
|
|
18
|
-
before do
|
|
19
|
-
allow(Backdrop::Extractor).to receive(:new).and_return extractor
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
it 'works out the project name' do
|
|
23
|
-
expect(extractor).to receive(:build_apis).with(
|
|
24
|
-
project_name,
|
|
25
|
-
rad_docs,
|
|
26
|
-
output_dir
|
|
27
|
-
)
|
|
28
|
-
subject.run
|
|
29
|
-
end
|
|
30
|
-
end
|
|
31
|
-
end
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
require 'backdrop'
|
|
3
|
-
require 'tmpdir'
|
|
4
|
-
require 'rack/test'
|
|
5
|
-
|
|
6
|
-
describe 'Backdrop' do
|
|
7
|
-
include Rack::Test::Methods
|
|
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
|
|
16
|
-
let(:subject) { Backdrop::Runner.new(output_path, [project_path]) }
|
|
17
|
-
let(:output_path) { File.join(@test_dir, 'output') }
|
|
18
|
-
let(:project_path) { File.join(@test_dir, 'project') }
|
|
19
|
-
|
|
20
|
-
def app
|
|
21
|
-
Backdrop.configure do |config|
|
|
22
|
-
config.output_dir = output_path
|
|
23
|
-
end
|
|
24
|
-
Backdrop::App
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
describe 'running with an out directory and API project' do
|
|
28
|
-
let(:put_output) do
|
|
29
|
-
{ 'http_method' => 'PUT',
|
|
30
|
-
'route' => 'resource/:property',
|
|
31
|
-
'requests' => [{
|
|
32
|
-
'response_body' => nil,
|
|
33
|
-
'request_path' => '/resource/put_request',
|
|
34
|
-
'response_status' => 201
|
|
35
|
-
}] }
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
let(:get_output) do
|
|
39
|
-
{ 'http_method' => 'GET',
|
|
40
|
-
'route' => '/resource/:property',
|
|
41
|
-
'requests' => [{
|
|
42
|
-
'request_path' => '/resource/get_request',
|
|
43
|
-
'response_body' => '{"Hello":"World"}'
|
|
44
|
-
}] }
|
|
45
|
-
end
|
|
46
|
-
before do
|
|
47
|
-
FileUtils.mkdir_p(File.join(project_path, 'doc/api/resource'))
|
|
48
|
-
File.write(
|
|
49
|
-
File.join(project_path, '/doc/api/put_request.json'),
|
|
50
|
-
JSON.generate(put_output)
|
|
51
|
-
)
|
|
52
|
-
File.write(
|
|
53
|
-
File.join(project_path, '/doc/api/get_request.json'),
|
|
54
|
-
JSON.generate(get_output)
|
|
55
|
-
)
|
|
56
|
-
subject.run
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
context 'when the method is PUT' do
|
|
60
|
-
it 'responds with the correct status' do
|
|
61
|
-
put '/project/resource/put_request'
|
|
62
|
-
expect(last_response.status).to eq 201
|
|
63
|
-
end
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
context 'when the method is GET' do
|
|
67
|
-
it 'responds with the response body' do
|
|
68
|
-
get '/project/resource/get_request'
|
|
69
|
-
expect(last_response.body).to eq '{"Hello":"World"}'
|
|
70
|
-
end
|
|
71
|
-
end
|
|
72
|
-
end
|
|
73
|
-
end
|