rambo_ruby 0.1.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 +7 -0
- data/.rspec +2 -0
- data/.simplecov +7 -0
- data/.travis.yml +17 -0
- data/Gemfile +5 -0
- data/ISSUE_TEMPLATE.md +45 -0
- data/LICENSE +21 -0
- data/README.md +50 -0
- data/Rakefile +10 -0
- data/assets/logo.txt +5 -0
- data/bin/rambo +23 -0
- data/features/create_files.feature +16 -0
- data/features/error_modes.feature +13 -0
- data/features/generate_post_specs.feature +10 -0
- data/features/generate_simple_api_specs.feature +13 -0
- data/features/modify_spec_helper.feature +4 -0
- data/features/step_definitions/file_steps.rb +25 -0
- data/features/support/cucumber_helper.rb +13 -0
- data/features/support/env.rb +8 -0
- data/features/support/examples/json/basic_raml_with_example_response.json +16 -0
- data/features/support/examples/json/basic_raml_with_post_route_response.json +15 -0
- data/features/support/examples/json/basic_raml_with_schema_response.json +10 -0
- data/features/support/examples/raml/basic_raml_with_example.raml +30 -0
- data/features/support/examples/raml/basic_raml_with_post_route.raml +43 -0
- data/features/support/examples/raml/basic_raml_with_schema.raml +24 -0
- data/features/support/examples/raml/empty_raml.raml +5 -0
- data/features/support/examples/raml/multiple_routes.raml +15 -0
- data/features/support/examples/raml/post_with_request_headers.raml +45 -0
- data/features/support/examples/rspec/empty_spec.rb.example +5 -0
- data/features/support/examples/rspec/simple_spec_file_with_example.rb.example +31 -0
- data/features/support/examples/rspec/simple_spec_file_with_post_route.rb.example +35 -0
- data/features/support/examples/rspec/simple_spec_file_with_schema.rb.example +31 -0
- data/features/support/examples/rspec/spec_file_with_request_headers.rb.example +52 -0
- data/features/support/examples/rspec/spec_helper_json_added.rb.example +11 -0
- data/features/support/examples/rspec/spec_helper_only_json.rb.example +10 -0
- data/features/support/examples/rspec/spec_helper_only_rack_test.rb.example +9 -0
- data/features/support/examples/rspec/spec_helper_rack_test_added.rb.example +10 -0
- data/features/support/foobar.raml +30 -0
- data/lib/cli.rb +65 -0
- data/lib/document_generator.rb +49 -0
- data/lib/raml_models/api.rb +19 -0
- data/lib/raml_models/body.rb +33 -0
- data/lib/raml_models/headers.rb +21 -0
- data/lib/raml_models/method.rb +37 -0
- data/lib/raml_models/resource.rb +22 -0
- data/lib/raml_models/response.rb +19 -0
- data/lib/raml_models.rb +1 -0
- data/lib/rspec/example_group.rb +53 -0
- data/lib/rspec/examples.rb +32 -0
- data/lib/rspec/helper_file.rb +30 -0
- data/lib/rspec/spec_file.rb +31 -0
- data/lib/rspec/templates/example_group_template.erb +39 -0
- data/lib/rspec/templates/matcher_file_template.erb +8 -0
- data/lib/rspec/templates/rambo_helper_file_template.erb +3 -0
- data/lib/rspec/templates/spec_file_template.erb +15 -0
- data/lib/rspec.rb +1 -0
- data/lib/version.rb +9 -0
- data/rambo_ruby.gemspec +38 -0
- data/spec/lib/cli_spec.rb +71 -0
- data/spec/lib/document_generator_spec.rb +74 -0
- data/spec/lib/raml_models/api_spec.rb +23 -0
- data/spec/lib/raml_models/body_spec.rb +32 -0
- data/spec/lib/raml_models/headers_spec.rb +17 -0
- data/spec/lib/raml_models/method_spec.rb +32 -0
- data/spec/lib/raml_models/resource_spec.rb +30 -0
- data/spec/lib/raml_models/response_spec.rb +20 -0
- data/spec/lib/rspec/example_group_spec.rb +87 -0
- data/spec/lib/rspec/examples_spec.rb +38 -0
- data/spec/lib/rspec/helper_file_spec.rb +18 -0
- data/spec/lib/rspec/spec_file_spec.rb +58 -0
- data/spec/spec_helper.rb +26 -0
- data/spec/support/basic_raml_with_post_route.raml +43 -0
- data/spec/support/foo.raml +43 -0
- data/spec/support/foobar.raml +30 -0
- data/spec/support/foobar.yml +3 -0
- data/spec/support/multiple_resources.raml +56 -0
- data/spec/support/post_with_request_headers.raml +45 -0
- metadata +321 -0
@@ -0,0 +1,52 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
RSpec.describe "e-BookMobile API", type: :request do
|
4
|
+
|
5
|
+
describe "/authors" do
|
6
|
+
let(:route) { "/authors" }
|
7
|
+
|
8
|
+
describe "POST" do
|
9
|
+
let(:headers) do
|
10
|
+
{
|
11
|
+
"Content-Type" => "application/json"
|
12
|
+
}
|
13
|
+
end
|
14
|
+
|
15
|
+
let(:request_body) do
|
16
|
+
{
|
17
|
+
"first_name" => "asgaakh",
|
18
|
+
"last_name" => "sjdhhgu",
|
19
|
+
"year_of_birth" => 3333
|
20
|
+
}.to_json
|
21
|
+
end
|
22
|
+
|
23
|
+
let(:response_body) do
|
24
|
+
{
|
25
|
+
"author" => {
|
26
|
+
"id" => 1,
|
27
|
+
"first_name" => "asgaakh",
|
28
|
+
"last_name" => "sjdhhgu",
|
29
|
+
"year_of_birth" => 3333
|
30
|
+
}
|
31
|
+
}.to_json
|
32
|
+
end
|
33
|
+
|
34
|
+
let(:output_file) do
|
35
|
+
"spec/contract/output/authors_get_response.json"
|
36
|
+
end
|
37
|
+
|
38
|
+
it "retrieve a list of authors" do
|
39
|
+
get route
|
40
|
+
|
41
|
+
File.open(output_file, "w+") {|file| file.puts JSON.pretty_generate(JSON.parse(response.body)) }
|
42
|
+
|
43
|
+
expect(response.body).to eql response_body
|
44
|
+
end
|
45
|
+
|
46
|
+
it "returns status 200" do
|
47
|
+
get route
|
48
|
+
expect(response.status).to eql 200
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require "rspec"
|
2
|
+
require "rspec/core"
|
3
|
+
require "rspec/matchers"
|
4
|
+
require "rspec/expectations"
|
5
|
+
require "raml-rb"
|
6
|
+
require "rack/test"
|
7
|
+
require "json"
|
8
|
+
|
9
|
+
path = File.expand_path('../../lib', __FILE__)
|
10
|
+
|
11
|
+
Dir.foreach(path) {|f| require f if f.match(/.*\.rb\z/) }
|
@@ -0,0 +1,30 @@
|
|
1
|
+
#%RAML 0.8
|
2
|
+
---
|
3
|
+
title: e-BookMobile API
|
4
|
+
baseUri: http://api.e-bookmobile.com/{version}
|
5
|
+
version: v1
|
6
|
+
|
7
|
+
/authors:
|
8
|
+
get:
|
9
|
+
description: Retrieve a list of authors
|
10
|
+
responses:
|
11
|
+
200:
|
12
|
+
body:
|
13
|
+
application/json:
|
14
|
+
example: |
|
15
|
+
{
|
16
|
+
"data": [
|
17
|
+
{
|
18
|
+
"id": 1,
|
19
|
+
"first_name": "Hermann",
|
20
|
+
"last_name": "Hesse"
|
21
|
+
},
|
22
|
+
{
|
23
|
+
"id": 2,
|
24
|
+
"first_name": "Charles",
|
25
|
+
"last_name": "Dickens"
|
26
|
+
}
|
27
|
+
],
|
28
|
+
"success": true,
|
29
|
+
"status": 200
|
30
|
+
}
|
data/lib/cli.rb
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
require "colorize"
|
2
|
+
require "document_generator"
|
3
|
+
|
4
|
+
module Rambo
|
5
|
+
class CLI
|
6
|
+
def initialize(raml_file=nil, opts={}, stdout=STDOUT, stderr=STDERR)
|
7
|
+
@stdout = stdout
|
8
|
+
@stderr = stderr
|
9
|
+
@file = raml_file
|
10
|
+
@options = opts
|
11
|
+
|
12
|
+
validate!
|
13
|
+
|
14
|
+
@generator = Rambo::DocumentGenerator.new(file, options)
|
15
|
+
end
|
16
|
+
|
17
|
+
def run!
|
18
|
+
print_logo
|
19
|
+
generator.generate_spec_dir!
|
20
|
+
generator.generate_rambo_helper!
|
21
|
+
generator.generate_matcher_dir!
|
22
|
+
generator.generate_examples!
|
23
|
+
generator.generate_matchers!
|
24
|
+
|
25
|
+
stdout.puts("Generating contract tests...")
|
26
|
+
sleep 0.4
|
27
|
+
|
28
|
+
begin
|
29
|
+
generator.generate_spec_file!
|
30
|
+
stdout.puts("Done!".green)
|
31
|
+
rescue NoMethodError => e
|
32
|
+
stderr.puts("Error: #{e.message}".red)
|
33
|
+
stderr.puts "\t#{e.backtrace.join("\n\t")}"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def validate!
|
38
|
+
exit_for_missing_file unless file
|
39
|
+
exit_for_invalid_file_format unless file.match(/\.raml$/)
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
attr_accessor :file, :stdout, :stderr, :generator, :options
|
45
|
+
|
46
|
+
def print_logo
|
47
|
+
stdout.puts logo.colorize(color: String.colors.sample)
|
48
|
+
sleep 0.4
|
49
|
+
end
|
50
|
+
|
51
|
+
def exit_for_missing_file
|
52
|
+
stdout.puts "USAGE: rambo [FILE]"
|
53
|
+
exit 1
|
54
|
+
end
|
55
|
+
|
56
|
+
def exit_for_invalid_file_format
|
57
|
+
stdout.puts "Unsupported file format. Please choose a RAML file."
|
58
|
+
exit 1
|
59
|
+
end
|
60
|
+
|
61
|
+
def logo
|
62
|
+
File.read(File.expand_path("../../assets/logo.txt", __FILE__))
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require "fileutils"
|
2
|
+
require "raml-rb"
|
3
|
+
|
4
|
+
require "rspec/spec_file"
|
5
|
+
require "rspec/helper_file"
|
6
|
+
|
7
|
+
module Rambo
|
8
|
+
class DocumentGenerator
|
9
|
+
attr_accessor :file, :raml, :options
|
10
|
+
|
11
|
+
def initialize(file, options={})
|
12
|
+
@file = file
|
13
|
+
@raml = Raml::Parser.parse_file(file)
|
14
|
+
@options = options
|
15
|
+
end
|
16
|
+
|
17
|
+
def generate_spec_dir!
|
18
|
+
FileUtils.mkdir_p("spec/contract/output")
|
19
|
+
end
|
20
|
+
|
21
|
+
def generate_examples!
|
22
|
+
FileUtils.mkdir_p("spec/support/examples")
|
23
|
+
end
|
24
|
+
|
25
|
+
def generate_spec_file!
|
26
|
+
spec_file_name = file.match(/[^\/]*\.raml$/).to_s.gsub(/\.raml$/, "_spec.rb")
|
27
|
+
contents = Rambo::RSpec::SpecFile.new(raml, options).render
|
28
|
+
File.write("spec/contract/#{spec_file_name}", contents)
|
29
|
+
end
|
30
|
+
|
31
|
+
def generate_rambo_helper!
|
32
|
+
Rambo::RSpec::HelperFile.new(
|
33
|
+
template_path: File.expand_path("../rspec/templates/rambo_helper_file_template.erb", __FILE__),
|
34
|
+
file_path: "spec/rambo_helper.rb"
|
35
|
+
).generate
|
36
|
+
end
|
37
|
+
|
38
|
+
def generate_matcher_dir!
|
39
|
+
FileUtils.mkdir_p("spec/support/matchers")
|
40
|
+
end
|
41
|
+
|
42
|
+
def generate_matchers!
|
43
|
+
Rambo::RSpec::HelperFile.new(
|
44
|
+
template_path: File.expand_path("../rspec/templates/matcher_file_template.erb", __FILE__),
|
45
|
+
file_path: "spec/support/matchers/rambo_matchers.rb"
|
46
|
+
).generate
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Rambo
|
2
|
+
module RamlModels
|
3
|
+
class Api
|
4
|
+
attr_reader :schema
|
5
|
+
|
6
|
+
def initialize(parsed_raml)
|
7
|
+
@schema = parsed_raml
|
8
|
+
end
|
9
|
+
|
10
|
+
def resources
|
11
|
+
@resources ||= schema.resources.map {|resource| Rambo::RamlModels::Resource.new(resource) }
|
12
|
+
end
|
13
|
+
|
14
|
+
def title
|
15
|
+
@title ||= schema.title
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require "json_test_data"
|
2
|
+
|
3
|
+
module Rambo
|
4
|
+
module RamlModels
|
5
|
+
class Body
|
6
|
+
|
7
|
+
attr_reader :body, :type
|
8
|
+
|
9
|
+
def initialize(raml)
|
10
|
+
@body = raml
|
11
|
+
end
|
12
|
+
|
13
|
+
def content_type
|
14
|
+
body.content_type
|
15
|
+
end
|
16
|
+
|
17
|
+
def example
|
18
|
+
@example ||= body.example || generate_from_schema || {}.to_json
|
19
|
+
end
|
20
|
+
|
21
|
+
def schema
|
22
|
+
@schema ||= body.schema
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def generate_from_schema
|
28
|
+
return nil unless body.schema
|
29
|
+
JSON.pretty_generate(JsonTestData.generate!(body.schema, ruby: true))
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Rambo
|
2
|
+
module RamlModels
|
3
|
+
class Headers
|
4
|
+
attr_accessor :headers
|
5
|
+
|
6
|
+
def initialize(headers)
|
7
|
+
@headers = headers
|
8
|
+
end
|
9
|
+
|
10
|
+
def pretty
|
11
|
+
beginning, ending = "{\n", "}"
|
12
|
+
|
13
|
+
contents = headers.map {|key, value|
|
14
|
+
"\t\"#{key}\" => \"#{value}\"\n"
|
15
|
+
}
|
16
|
+
|
17
|
+
"#{beginning}#{contents.join}#{ending}"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module Rambo
|
2
|
+
module RamlModels
|
3
|
+
class Method
|
4
|
+
attr_reader :schema
|
5
|
+
|
6
|
+
def initialize(raml_method)
|
7
|
+
@schema = raml_method
|
8
|
+
end
|
9
|
+
|
10
|
+
def method
|
11
|
+
schema.method
|
12
|
+
end
|
13
|
+
|
14
|
+
def request_body
|
15
|
+
Rambo::RamlModels::Body.new(schema.bodies.first) if has_request_body?
|
16
|
+
end
|
17
|
+
|
18
|
+
def description
|
19
|
+
@description ||= schema.description
|
20
|
+
end
|
21
|
+
|
22
|
+
def headers
|
23
|
+
@headers ||= Rambo::RamlModels::Headers.new(schema.headers) if schema.headers
|
24
|
+
end
|
25
|
+
|
26
|
+
def responses
|
27
|
+
@responses ||= schema.responses.map {|resp| Rambo::RamlModels::Response.new(resp) }
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def has_request_body?
|
33
|
+
!!schema.bodies.first
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Rambo
|
2
|
+
module RamlModels
|
3
|
+
class Resource
|
4
|
+
|
5
|
+
attr_reader :schema
|
6
|
+
|
7
|
+
def initialize(raml_resource)
|
8
|
+
@schema = raml_resource
|
9
|
+
end
|
10
|
+
|
11
|
+
def uri_partial
|
12
|
+
schema.uri_partial
|
13
|
+
end
|
14
|
+
|
15
|
+
alias_method :to_s, :uri_partial
|
16
|
+
|
17
|
+
def http_methods
|
18
|
+
@http_methods ||= schema.methods.map {|method| Rambo::RamlModels::Method.new(method) }
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Rambo
|
2
|
+
module RamlModels
|
3
|
+
class Response
|
4
|
+
attr_reader :schema
|
5
|
+
|
6
|
+
def initialize(raml)
|
7
|
+
@schema = raml
|
8
|
+
end
|
9
|
+
|
10
|
+
def status_code
|
11
|
+
schema.code
|
12
|
+
end
|
13
|
+
|
14
|
+
def bodies
|
15
|
+
@bodies ||= schema.bodies.map {|body| Rambo::RamlModels::Body.new(body) }
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/raml_models.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
Dir["#{File.dirname(__FILE__)}/raml_models/**/*.rb"].each {|file| require file }
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module Rambo
|
2
|
+
module RSpec
|
3
|
+
class ExampleGroup
|
4
|
+
|
5
|
+
TEMPLATE_PATH = File.expand_path("../templates/example_group_template.erb", __FILE__)
|
6
|
+
|
7
|
+
attr_reader :resource
|
8
|
+
|
9
|
+
def initialize(resource, options={})
|
10
|
+
@resource = resource
|
11
|
+
@options = options
|
12
|
+
end
|
13
|
+
|
14
|
+
def template
|
15
|
+
@template ||= File.read(TEMPLATE_PATH)
|
16
|
+
end
|
17
|
+
|
18
|
+
def create_fixture_files
|
19
|
+
resource.http_methods.each do |method|
|
20
|
+
if method.request_body
|
21
|
+
path = File.expand_path("spec/support/examples/#{@resource.to_s.gsub(/\//, "")}_#{method.method}_request_body.json")
|
22
|
+
File.write(path, method.request_body.example)
|
23
|
+
end
|
24
|
+
|
25
|
+
method.responses.each do |resp|
|
26
|
+
resp.bodies.each do |body|
|
27
|
+
path = body.schema ? response_schema_fixture_path(method) : response_body_fixture_path(method)
|
28
|
+
contents = body.schema ? body.schema : body.example
|
29
|
+
File.write(path, contents)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def render
|
36
|
+
create_fixture_files
|
37
|
+
b = binding
|
38
|
+
ERB.new(template, 0, "-", "@result").result(resource.instance_eval { b })
|
39
|
+
@result
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def response_schema_fixture_path(method)
|
45
|
+
File.expand_path("spec/support/examples/#{@resource.to_s.gsub(/\//, "")}_#{method.method}_response_schema.json")
|
46
|
+
end
|
47
|
+
|
48
|
+
def response_body_fixture_path(method)
|
49
|
+
File.expand_path("spec/support/examples/#{@resource.to_s.gsub(/\//, "")}_#{method.method}_response_body.json")
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require "rspec/example_group"
|
2
|
+
|
3
|
+
module Rambo
|
4
|
+
module RSpec
|
5
|
+
class Examples
|
6
|
+
attr_reader :raml, :resources, :examples, :options
|
7
|
+
|
8
|
+
def initialize(raml, options={})
|
9
|
+
@raml = raml
|
10
|
+
@options = options
|
11
|
+
end
|
12
|
+
|
13
|
+
def compose
|
14
|
+
return '' unless examples
|
15
|
+
|
16
|
+
examples.join("\n\n")
|
17
|
+
end
|
18
|
+
|
19
|
+
def resources
|
20
|
+
@resources ||= raml.resources
|
21
|
+
end
|
22
|
+
|
23
|
+
def example_groups
|
24
|
+
@example_groups ||= resources.map {|r| ExampleGroup.new(r, options) }
|
25
|
+
end
|
26
|
+
|
27
|
+
def generate!
|
28
|
+
@examples = example_groups.map(&:render)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Rambo
|
2
|
+
module RSpec
|
3
|
+
class HelperFile
|
4
|
+
def initialize(template_path:, file_path:)
|
5
|
+
@template_path = template_path
|
6
|
+
@file_path = file_path
|
7
|
+
end
|
8
|
+
|
9
|
+
def generate
|
10
|
+
write_to_file(template) unless file_already_exists?
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
attr_reader :template_path, :file_path
|
16
|
+
|
17
|
+
def file_already_exists?
|
18
|
+
File.exist?(file_path)
|
19
|
+
end
|
20
|
+
|
21
|
+
def write_to_file(template)
|
22
|
+
File.write(file_path, template)
|
23
|
+
end
|
24
|
+
|
25
|
+
def template
|
26
|
+
@template ||= File.read(template_path)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'erb'
|
2
|
+
require 'raml'
|
3
|
+
|
4
|
+
require "rspec/examples"
|
5
|
+
require "raml_models"
|
6
|
+
|
7
|
+
module Rambo
|
8
|
+
module RSpec
|
9
|
+
class SpecFile
|
10
|
+
attr_reader :raml, :examples, :options
|
11
|
+
|
12
|
+
TEMPLATE_PATH = File.expand_path('../templates/spec_file_template.erb', __FILE__)
|
13
|
+
|
14
|
+
def initialize(raml, options={})
|
15
|
+
@raml = Rambo::RamlModels::Api.new(raml)
|
16
|
+
@options = options
|
17
|
+
@examples = Examples.new(@raml, @options)
|
18
|
+
end
|
19
|
+
|
20
|
+
def template
|
21
|
+
@template ||= File.read(TEMPLATE_PATH)
|
22
|
+
end
|
23
|
+
|
24
|
+
def render
|
25
|
+
b = binding
|
26
|
+
ERB.new(template, 0, "-", "@result").result(raml.instance_eval { b })
|
27
|
+
@result
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
describe "<%= @resource.to_s %>" do
|
2
|
+
let(:route) { "<%= @resource.to_s %>" }
|
3
|
+
<%- @resource.http_methods.each do |method| %>
|
4
|
+
describe "<%= method.method.upcase %>" do
|
5
|
+
<% if method.headers %>let(:headers) do <% headers = method.headers.pretty.split("\n")[1..-2] %>
|
6
|
+
{
|
7
|
+
<%= headers.join(",\n ") %>
|
8
|
+
}
|
9
|
+
end<% end %><% if method.request_body %>
|
10
|
+
|
11
|
+
let(:request_body) do
|
12
|
+
File.read("<%= "spec/support/examples/#{@resource.to_s.gsub("/", "")}_#{method.method}_request_body.json" %>")
|
13
|
+
end<% end %><% if has_schema = method.responses.first.bodies.first.schema %>
|
14
|
+
|
15
|
+
let(:response_schema) do
|
16
|
+
File.read("<%= "spec/support/examples/#{@resource.to_s.gsub("/", "")}_#{method.method}_response_schema.json" %>")
|
17
|
+
end<% else %>
|
18
|
+
let(:response_body) do<% body = method.responses.first.bodies.first.example.split("\n") %>
|
19
|
+
File.read("<%= "spec/support/examples/#{@resource.to_s.gsub("/", "")}_#{method.method}_response_body.json" %>")
|
20
|
+
end<% end %>
|
21
|
+
|
22
|
+
let(:output_file) do
|
23
|
+
"<%= "spec/contract/output/#{@resource.to_s.gsub("/", "")}_#{method.method}_response.json" %>"
|
24
|
+
end
|
25
|
+
<% resp_method = @options[:rails] ? "response" : "last_response" %>
|
26
|
+
it "<%= method.description && method.description.downcase || "#{method.method}s the resource" %>" do
|
27
|
+
<%= method.method %> route<% if method.request_body %>, request_body<% end %><% if method.headers %>, headers<% end %>
|
28
|
+
|
29
|
+
File.open(output_file, "w+") {|file| file.puts JSON.pretty_generate(JSON.parse(<%= resp_method %>.body)) }
|
30
|
+
|
31
|
+
expect(<%= resp_method %>.body).to <%= has_schema ? "match_schema response_schema" : "eql response_body" %>
|
32
|
+
end
|
33
|
+
|
34
|
+
it "returns status <%= method.responses.first.status_code %>" do
|
35
|
+
<%= method.method %> route<% if method.request_body %>, request_body<% end %><% if method.headers %>, headers<% end %>
|
36
|
+
expect(<%= resp_method %>.status).to eql <%= method.responses.first.status_code %>
|
37
|
+
end
|
38
|
+
end<%- end %>
|
39
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require "rambo_helper"
|
2
|
+
|
3
|
+
RSpec.describe "<%= @raml.title %>", type: :request do
|
4
|
+
|
5
|
+
# Delete output files from previous test run prior to running tests again
|
6
|
+
before(:all) do
|
7
|
+
Dir.foreach("spec/contract/output") do |file|
|
8
|
+
next unless file.match(/\.json$/)
|
9
|
+
|
10
|
+
File.delete(File.join("spec/contract/output", file))
|
11
|
+
end
|
12
|
+
end
|
13
|
+
<%- if @examples.generate! && @examples.compose.size > 0 %>
|
14
|
+
<%= @examples.compose.chomp %><%- end %>
|
15
|
+
end
|
data/lib/rspec.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
Dir["#{File.dirname(__FILE__)}/rspec/**/*.rb"].each {|file| require file }
|
data/lib/version.rb
ADDED
data/rambo_ruby.gemspec
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = "rambo_ruby"
|
8
|
+
s.version = Rambo.version
|
9
|
+
s.authors = ["Dana Scheider"]
|
10
|
+
s.description = "RAML in, RSpec out"
|
11
|
+
s.summary = "rambo_ruby-#{s.version}"
|
12
|
+
s.email = "dana.scheider@gmail.com"
|
13
|
+
s.license = "MIT"
|
14
|
+
s.platform = Gem::Platform::RUBY
|
15
|
+
s.required_ruby_version = ">= 2.1.0"
|
16
|
+
|
17
|
+
s.add_dependency "rspec", "~> 3.4"
|
18
|
+
s.add_dependency "raml-rb", "~> 0.0.6"
|
19
|
+
s.add_dependency "rack-test", "~> 0.6"
|
20
|
+
s.add_dependency "colorize", "~> 0.7"
|
21
|
+
s.add_dependency "json_test_data", "~> 1.0"
|
22
|
+
s.add_dependency "json-schema", "~> 2.6"
|
23
|
+
|
24
|
+
s.add_development_dependency "cucumber", "~> 2.1"
|
25
|
+
s.add_development_dependency "json", "~> 1.7"
|
26
|
+
s.add_development_dependency "rake", "~> 11.0"
|
27
|
+
s.add_development_dependency "coveralls", "~> 0.7"
|
28
|
+
s.add_development_dependency "aruba", "~> 0.13"
|
29
|
+
|
30
|
+
s.executables = "rambo"
|
31
|
+
s.default_executable = "rambo"
|
32
|
+
|
33
|
+
s.rubygems_version = ">= 1.6.1"
|
34
|
+
s.files = `git ls-files`.split("\n").reject {|path| path =~ /\.gitignore$/ }
|
35
|
+
s.test_files = `git ls-files -- {spec,features}/*`.split("\n")
|
36
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
37
|
+
s.require_path = "lib"
|
38
|
+
end
|