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
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 181b7e230121fc0dd07a1577c7dd39697ab18409
|
4
|
+
data.tar.gz: 399cbdee63d18ff87611250c0f0b9e8d9ecdf4d9
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 61746a4c0f25f15a25cfe25588045506040fb2dcff720ae38d7f322802227b196dec5fed092eae158877d99e8e62f794acba20fe8e05f11fa9df43a35a2b8635
|
7
|
+
data.tar.gz: e254055accaecd97a45e116fbd9e9522484e8b6aeae75244da60fa076afc9594d1f65dbd23911a6eed82d1142e30d0cf876f19fe82d0909f66dbe57157d9c906
|
data/.rspec
ADDED
data/.simplecov
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/ISSUE_TEMPLATE.md
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
## Summary
|
2
|
+
|
3
|
+
<!-- This sections are meant as guidance for you. If some doesn't fit, skip them. In general: Please provide as much information as you can to help us solving your problem -->
|
4
|
+
|
5
|
+
<!--- Provide a general summary of the issue in the Title above -->
|
6
|
+
|
7
|
+
## Expected Behavior
|
8
|
+
|
9
|
+
<!--- If you're describing a bug, tell us what should happen -->
|
10
|
+
<!--- If you're suggesting a change/improvement, tell us how it should work -->
|
11
|
+
|
12
|
+
## Current Behavior
|
13
|
+
|
14
|
+
<!--- If describing a bug, tell us what happens instead of the expected behavior -->
|
15
|
+
<!--- If suggesting a change/improvement, explain the difference from current behavior -->
|
16
|
+
|
17
|
+
<!--- If you have got some output place it in the code block below. Otherwise remove it. -->
|
18
|
+
~~~
|
19
|
+
~~~
|
20
|
+
|
21
|
+
## Possible Solution
|
22
|
+
|
23
|
+
<!--- Not obligatory, but suggest a fix/reason for the bug, -->
|
24
|
+
<!--- or ideas how to implement the addition or change -->
|
25
|
+
|
26
|
+
## Steps to Reproduce (for bugs)
|
27
|
+
|
28
|
+
<!--- Provide a link to a live example, or an unambiguous set of steps to -->
|
29
|
+
<!--- reproduce this bug. Include code to reproduce, if relevant -->
|
30
|
+
1.
|
31
|
+
2.
|
32
|
+
3.
|
33
|
+
4.
|
34
|
+
|
35
|
+
## Context
|
36
|
+
|
37
|
+
<!--- How has this issue affected you? What are you trying to accomplish? -->
|
38
|
+
<!--- Providing context helps us come up with a solution that is most useful in the real world -->
|
39
|
+
|
40
|
+
## Your Environment
|
41
|
+
|
42
|
+
<!--- Include as many relevant details about the environment you experienced the bug in -->
|
43
|
+
* Version used:
|
44
|
+
* Operating System and version:
|
45
|
+
* Link to your project:
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Dana Scheider
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
# Rambo
|
2
|
+
[](https://travis-ci.org/danascheider/rambo) [](https://codeclimate.com/github/danascheider/rambo) [](https://gemnasium.com/github.com/danascheider/rambo)
|
3
|
+
[](https://coveralls.io/github/danascheider/rambo?branch=master)
|
4
|
+
|
5
|
+
Rambo is a gem that generates API contract tests from API docs in [RAML](http://raml.org/).
|
6
|
+
|
7
|
+
#### The current version of Rambo is 0.1.0. It is highly unstable and has a limited feature set. Use at your own risk and please file issue reports if they come up!
|
8
|
+
|
9
|
+
## Usage
|
10
|
+
You can install Rambo using:
|
11
|
+
```ruby
|
12
|
+
gem install rambo_ruby
|
13
|
+
```
|
14
|
+
You can also add it to your project's Gemfile: <
|
15
|
+
```ruby
|
16
|
+
group :development, :test do
|
17
|
+
gem 'rambo_ruby', '~> 0.0.1'
|
18
|
+
end
|
19
|
+
```
|
20
|
+
To run Rambo, from the root directory of your project, run:
|
21
|
+
```
|
22
|
+
$ rambo foobar.raml
|
23
|
+
```
|
24
|
+
Rambo will create `spec/contract` directory and a `spec/rambo_helper.rb` file if they don't exist, and will create a `spec/contract/foobar_spec.rb` file. The latter will overwrite any existing spec file by the same name. This is intentional behavior and will not change in future versions.
|
25
|
+
|
26
|
+
To run the RSpec examples Rambo generates, you will need to have `require`s in your `spec_helper.rb` or `rambo_helper.rb` file:
|
27
|
+
|
28
|
+
- `require "rack/test"`
|
29
|
+
- `require "json"`
|
30
|
+
- `require "json-schema"`
|
31
|
+
|
32
|
+
Rambo is being developed to test APIs complying with standard REST practices. Mileage may vary with other architectures, but I'm happy to consider pull requests.
|
33
|
+
|
34
|
+
## About the Project
|
35
|
+
I started Rambo in March of 2016 as part of my work at [Renew Financial](http://renewfinancial.com). RF has since put a second full-time engineer on the project. For this reason, our primary focus is on adding the features and functionality that are most important for testing RF's back-end services. One of these services, Repaymnt Estimatr, forms the basis for the Rambo MVP.
|
36
|
+
|
37
|
+
Although the Repaymnt Estimatr repo is private, the key technical considerations here are that it is built with Rails 4 and documented using RAML 1.0. Rambo, therefore, considers these the default, and support for other frameworks and for RAML 0.8 is incidental and lower priority. We would be delighted to merge pull requests adding such support, as long as they don't adversely affect the features we need most.
|
38
|
+
|
39
|
+
Although development of Rambo is largely supported by Renew Financial, we have every intention of keeping the tool open source and to continue expanding and updating its functionality.
|
40
|
+
|
41
|
+
## Contributing
|
42
|
+
Rambo is a new project and any contributions are much appreciated. All pull requests should include comprehensive test coverage and, where appropriate, documentation. If you're not sure where to get started, contact me [through Github](https://github.com/danascheider) and I'll be glad to chat.
|
43
|
+
|
44
|
+
Additional information for contributors is available in the wiki. Beginning or first-time contributors are welcome and encouraged!
|
45
|
+
|
46
|
+
## More Information
|
47
|
+
* [RAML homepage](https://raml.org)
|
48
|
+
* [Roy Fielding's dissertation](https://www.ics.uci.edu/~fielding/pubs/dissertation/fielding_dissertation.pdf) describing Representational State Transfer (REST) architecture
|
49
|
+
* [RESTful Web Services](http://www.crummy.com/writing/RESTful-Web-Services/RESTful_Web_Services.pdf), by Leonard Richardson & Sam Ruby
|
50
|
+
* [Toby Clemson](http://martinfowler.com/articles/microservice-testing/) on testing microservices
|
data/Rakefile
ADDED
data/assets/logo.txt
ADDED
data/bin/rambo
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
lib = File.expand_path("../../lib", __FILE__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
|
6
|
+
require "fileutils"
|
7
|
+
require "cli"
|
8
|
+
require "optparse"
|
9
|
+
|
10
|
+
filename = ARGV[0] ? File.expand_path(ARGV[0], FileUtils.pwd) : nil
|
11
|
+
|
12
|
+
options = {}
|
13
|
+
|
14
|
+
OptionParser.new do |opts|
|
15
|
+
opts.banner = "Usage: rambo [FILE] [OPTIONS]"
|
16
|
+
|
17
|
+
options[:rails] = true
|
18
|
+
opts.on("--no-rails", "Generate tests for a non-Rails API") do |v|
|
19
|
+
options[:rails] = false
|
20
|
+
end
|
21
|
+
end.parse!
|
22
|
+
|
23
|
+
Rambo::CLI.new(filename, options, STDOUT).run!
|
@@ -0,0 +1,16 @@
|
|
1
|
+
Feature: Create specs from RAML
|
2
|
+
|
3
|
+
The example files can be found in features/support/examples
|
4
|
+
|
5
|
+
Scenario: Generate specs from a simple RAML file
|
6
|
+
Given a file named "foo.raml" like "empty_raml.raml"
|
7
|
+
When I run `rambo foo.raml`
|
8
|
+
Then the directory "spec/contract" should exist
|
9
|
+
And the file "spec/contract/foo_spec.rb" should exist
|
10
|
+
And the file "spec/rambo_helper.rb" should exist
|
11
|
+
And the file "spec/rambo_helper.rb" should contain:
|
12
|
+
"""
|
13
|
+
require "spec_helper"
|
14
|
+
"""
|
15
|
+
And the file "spec/contract/foo_spec.rb" should be like "empty_spec.rb.example"
|
16
|
+
And the exit status should be 0
|
@@ -0,0 +1,13 @@
|
|
1
|
+
Feature: Error handling
|
2
|
+
|
3
|
+
Scenario: No filename is given
|
4
|
+
When I run `rambo`
|
5
|
+
Then it should fail with "USAGE: rambo [FILE]"
|
6
|
+
|
7
|
+
Scenario: File given is not a RAML file
|
8
|
+
Given a file "foobar.yml" with:
|
9
|
+
"""
|
10
|
+
foo: bar
|
11
|
+
"""
|
12
|
+
When I run `rambo foobar.yml`
|
13
|
+
Then it should fail with "Unsupported file format. Please choose a RAML file."
|
@@ -0,0 +1,10 @@
|
|
1
|
+
Feature: Generate POST specs
|
2
|
+
Scenario: Simple POST route
|
3
|
+
Given a file named "foo.raml" like "basic_raml_with_post_route.raml"
|
4
|
+
When I run `rambo foo.raml`
|
5
|
+
Then the file "spec/contract/foo_spec.rb" should be like "simple_spec_file_with_post_route.rb.example"
|
6
|
+
|
7
|
+
Scenario: POST route with headers
|
8
|
+
Given a file named "foo.raml" like "post_with_request_headers.raml"
|
9
|
+
When I run `rambo foo.raml`
|
10
|
+
Then the file "spec/contract/foo_spec.rb" should be like "spec_file_with_request_headers.rb.example"
|
@@ -0,0 +1,13 @@
|
|
1
|
+
Feature: Generate simple API specs
|
2
|
+
|
3
|
+
Scenario: Route with example
|
4
|
+
Given a file named "foo.raml" like "basic_raml_with_example.raml"
|
5
|
+
When I run `rambo foo.raml`
|
6
|
+
Then the file "spec/contract/foo_spec.rb" should be like "simple_spec_file_with_example.rb.example"
|
7
|
+
And the file "spec/support/examples/authors_response_body.json" should be like "basic_raml_with_example_response.json"
|
8
|
+
|
9
|
+
Scenario: Route with schema
|
10
|
+
Given a file named "foo.raml" like "basic_raml_with_schema.raml"
|
11
|
+
When I run `rambo foo.raml`
|
12
|
+
Then the file "spec/contract/foo_spec.rb" should be like "simple_spec_file_with_schema.rb.example"
|
13
|
+
And the file "spec/support/examples/authors_response_schema.json" should be like "basic_raml_with_schema_response.json"
|
@@ -0,0 +1,25 @@
|
|
1
|
+
Given(/^a file named "([^"]*)" like "([^"]*)"$/) do |file, example|
|
2
|
+
text = read_example(example)
|
3
|
+
step %(a file named "#{file}" with:), text
|
4
|
+
end
|
5
|
+
|
6
|
+
Given(/^a spec_helper\.rb file that requires rack\/test but not JSON$/) do
|
7
|
+
step 'a file named "spec/rambo_helper.rb" like "spec_helper_only_rack_test.rb.example"'
|
8
|
+
end
|
9
|
+
|
10
|
+
Given(/^a spec_helper\.rb file that requires JSON but not rack\/test$/) do
|
11
|
+
step 'a file named "spec/rambo_helper.rb" like "spec_helper_only_json.rb.example"'
|
12
|
+
end
|
13
|
+
|
14
|
+
Given(/a spec_helper.rb file that requires both JSON and rack\/test$/) do
|
15
|
+
step 'a file named "spec/rambo_helper.rb" like "good_spec_helper.rb.example"'
|
16
|
+
end
|
17
|
+
|
18
|
+
Then(/^the file "([^"]*)" should be like "([^"]*)"$/) do |file, example|
|
19
|
+
text = read_example(example)
|
20
|
+
step %(a file "#{file}" should contain:), text
|
21
|
+
end
|
22
|
+
|
23
|
+
Then(/^the file "([^"]*)" should require "([^"]*)"$/) do |file, mod|
|
24
|
+
steps %Q{the file "#{file}" should match /require "#{mod}"/}
|
25
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module CucumberHelper
|
2
|
+
def read_example(example)
|
3
|
+
possible_paths = [
|
4
|
+
File.expand_path("../examples/raml/#{example}", __FILE__),
|
5
|
+
File.expand_path("../examples/rspec/#{example}", __FILE__),
|
6
|
+
File.expand_path("../examples/rspec/#{example}", __FILE__)
|
7
|
+
]
|
8
|
+
|
9
|
+
possible_paths.each do |path|
|
10
|
+
return File.read(path) rescue next
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
{
|
2
|
+
"$schema": "http://json-schema.org/draft-04/schema#",
|
3
|
+
"description": "schema for a list of authors",
|
4
|
+
"type": "object",
|
5
|
+
"properties": {
|
6
|
+
"author": {
|
7
|
+
"type": "object",
|
8
|
+
"properties": {
|
9
|
+
"id": { "type": "integer" },
|
10
|
+
"first_name": { "type": "string" },
|
11
|
+
"last_name": { "type": "string" }
|
12
|
+
}
|
13
|
+
}
|
14
|
+
}
|
15
|
+
}
|
@@ -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
|
+
}
|
@@ -0,0 +1,43 @@
|
|
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
|
+
post:
|
9
|
+
description: Retrieve a list of authors
|
10
|
+
body:
|
11
|
+
application/json:
|
12
|
+
schema: |
|
13
|
+
{
|
14
|
+
"$schema": "http://json-schema.org/draft-04/schema#",
|
15
|
+
"description": "schema to create an author",
|
16
|
+
"type": "object",
|
17
|
+
"required": [ "first_name", "last_name" ],
|
18
|
+
"properties": {
|
19
|
+
"first_name": { "type": "string" },
|
20
|
+
"last_name": { "type": "string" },
|
21
|
+
"year_of_birth": { "type": "integer" }
|
22
|
+
}
|
23
|
+
}
|
24
|
+
responses:
|
25
|
+
200:
|
26
|
+
body:
|
27
|
+
application/json:
|
28
|
+
schema: |
|
29
|
+
{
|
30
|
+
"$schema": "http://json-schema.org/draft-04/schema#",
|
31
|
+
"description": "schema for a list of authors",
|
32
|
+
"type": "object",
|
33
|
+
"properties": {
|
34
|
+
"author": {
|
35
|
+
"type": "object",
|
36
|
+
"properties": {
|
37
|
+
"id": { "type": "integer" },
|
38
|
+
"first_name": { "type": "string" },
|
39
|
+
"last_name": { "type": "string" }
|
40
|
+
}
|
41
|
+
}
|
42
|
+
}
|
43
|
+
}
|
@@ -0,0 +1,24 @@
|
|
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
|
+
schema: |
|
15
|
+
{
|
16
|
+
"$schema": "http://json-schema.org/draft-04/schema#",
|
17
|
+
"description": "schema for a list of authors",
|
18
|
+
"type": "object",
|
19
|
+
"properties": {
|
20
|
+
"data": {
|
21
|
+
"type": "number"
|
22
|
+
}
|
23
|
+
}
|
24
|
+
}
|
@@ -0,0 +1,15 @@
|
|
1
|
+
#% RAML 0.8
|
2
|
+
---
|
3
|
+
title: e-Bookmobile API
|
4
|
+
baseUri: http://api.ebookmobile.com/{version}
|
5
|
+
version: v1
|
6
|
+
|
7
|
+
/authors:
|
8
|
+
get:
|
9
|
+
description: Retrieve a list of authors
|
10
|
+
responses:
|
11
|
+
201:
|
12
|
+
post:
|
13
|
+
description: Add an author to the database
|
14
|
+
responses:
|
15
|
+
204:
|
@@ -0,0 +1,45 @@
|
|
1
|
+
#%RAML 1.0
|
2
|
+
---
|
3
|
+
title: e-BookMobile API
|
4
|
+
baseUri: http://api.e-bookmobile.com/{version}
|
5
|
+
version: v1
|
6
|
+
|
7
|
+
/authors:
|
8
|
+
post:
|
9
|
+
description: Retrieve a list of authors
|
10
|
+
headers:
|
11
|
+
Content-Type: application/json
|
12
|
+
body:
|
13
|
+
application/json:
|
14
|
+
schema: |
|
15
|
+
{
|
16
|
+
"$schema": "http://json-schema.org/draft-04/schema#",
|
17
|
+
"description": "schema to create an author",
|
18
|
+
"type": "object",
|
19
|
+
"required": [ "first_name", "last_name" ],
|
20
|
+
"properties": {
|
21
|
+
"first_name": { "type": "string" },
|
22
|
+
"last_name": { "type": "string" },
|
23
|
+
"year_of_birth": { "type": "integer" }
|
24
|
+
}
|
25
|
+
}
|
26
|
+
responses:
|
27
|
+
200:
|
28
|
+
body:
|
29
|
+
application/json:
|
30
|
+
schema: |
|
31
|
+
{
|
32
|
+
"$schema": "http://json-schema.org/draft-04/schema#",
|
33
|
+
"description": "schema for a list of authors",
|
34
|
+
"type": "object",
|
35
|
+
"properties": {
|
36
|
+
"author": {
|
37
|
+
"type": "object",
|
38
|
+
"properties": {
|
39
|
+
"id": { "type": "integer" },
|
40
|
+
"first_name": { "type": "string" },
|
41
|
+
"last_name": { "type": "string" }
|
42
|
+
}
|
43
|
+
}
|
44
|
+
}
|
45
|
+
}
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require "rambo_helper"
|
2
|
+
|
3
|
+
RSpec.describe "e-BookMobile API", type: :request do
|
4
|
+
|
5
|
+
describe "/authors" do
|
6
|
+
let(:route) { "/authors" }
|
7
|
+
|
8
|
+
describe "GET" do
|
9
|
+
let(:response_body) do
|
10
|
+
File.read("spec/support/examples/authors_get_response_body.json")
|
11
|
+
end
|
12
|
+
|
13
|
+
let(:output_file) do
|
14
|
+
"spec/contract/output/authors_get_response.json"
|
15
|
+
end
|
16
|
+
|
17
|
+
it "retrieve a list of authors" do
|
18
|
+
get route
|
19
|
+
|
20
|
+
File.open(output_file, "w+") {|file| file.puts JSON.pretty_generate(JSON.parse(response.body)) }
|
21
|
+
|
22
|
+
expect(response.body).to eql response_body
|
23
|
+
end
|
24
|
+
|
25
|
+
it "returns status 200" do
|
26
|
+
get route
|
27
|
+
expect(response.status).to eql 200
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,35 @@
|
|
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(:request_body) do
|
10
|
+
File.read("spec/support/examples/authors_post_request_body.json")
|
11
|
+
end
|
12
|
+
|
13
|
+
let(:response_schema) do
|
14
|
+
File.read("spec/support/examples/authors_post_response_schema.json")
|
15
|
+
end
|
16
|
+
|
17
|
+
let(:output_file) do
|
18
|
+
"spec/contract/output/authors_post_response.json"
|
19
|
+
end
|
20
|
+
|
21
|
+
it "retrieve a list of authors" do
|
22
|
+
get route
|
23
|
+
|
24
|
+
File.open(output_file, "w+") {|file| file.puts(JSON.pretty_generate(JSON.parse(response.body))) }
|
25
|
+
|
26
|
+
expect(response.body).to eql response_body
|
27
|
+
end
|
28
|
+
|
29
|
+
it "returns status 200" do
|
30
|
+
get route
|
31
|
+
expect(response.status).to eql 200
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require "rambo_helper"
|
2
|
+
|
3
|
+
RSpec.describe "e-BookMobile API", type: :request do
|
4
|
+
|
5
|
+
describe "/authors" do
|
6
|
+
let(:route) { "/authors" }
|
7
|
+
|
8
|
+
describe "GET" do
|
9
|
+
let(:response_schema) do
|
10
|
+
File.read("spec/support/examples/authors_response_schema.json")
|
11
|
+
end
|
12
|
+
|
13
|
+
let(:output_file) do
|
14
|
+
"spec/contract/output/authors_get_response.json"
|
15
|
+
end
|
16
|
+
|
17
|
+
it "retrieve a list of authors" do
|
18
|
+
get route
|
19
|
+
|
20
|
+
File.open(output_file, "w+") {|file| file.puts JSON.pretty_generate(JSON.parse(response.body)) }
|
21
|
+
|
22
|
+
expect(response.body).to match_schema response_schema
|
23
|
+
end
|
24
|
+
|
25
|
+
it "returns status 200" do
|
26
|
+
get route
|
27
|
+
expect(response.status).to eql 200
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|