rambo_ruby 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +15 -6
- data/lib/rambo/document_generator.rb +5 -3
- data/lib/rambo/raml_models/headers.rb +1 -8
- data/lib/rambo/rspec/helper_file.rb +18 -3
- data/lib/rambo/rspec/templates/rambo_helper_file_template.erb +14 -2
- data/lib/version.rb +1 -1
- data/spec/lib/rambo/document_generator_spec.rb +18 -15
- data/spec/lib/rambo/raml_models/headers_spec.rb +2 -3
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5b74a5013560eb488b270d589b8afe2c34d50710
|
4
|
+
data.tar.gz: f42894dd1bd0861c1c57f38e2ea50fc8b0ff88d5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4410761d557036a272a84ca2b3daf8c8e812f1c24409a3ef30b83f8d1d72ccfdaf24378522c652effc819356e9080c4e49df11c2f31ee4799923c7c339c28cb6
|
7
|
+
data.tar.gz: de7a7aceb527990e6e71b5b7bff8c27653cfda9190263230233bf2578ff24d59d1572432b1f2792007bbda31a5485c1032986b2b59964b7e853600c9a9fa3506
|
data/README.md
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
|
5
5
|
Rambo is a gem that generates API contract tests from API docs in [RAML](http://raml.org/). 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.
|
6
6
|
|
7
|
-
#### The current version of Rambo is 0.
|
7
|
+
#### The current version of Rambo is 0.3.1. 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
8
|
|
9
9
|
## Usage
|
10
10
|
You can install Rambo using:
|
@@ -14,7 +14,7 @@ gem install rambo_ruby
|
|
14
14
|
You can also add it to your project's Gemfile:
|
15
15
|
```ruby
|
16
16
|
group :development, :test do
|
17
|
-
gem 'rambo_ruby', '~> 0.
|
17
|
+
gem 'rambo_ruby', '~> 0.3.1'
|
18
18
|
end
|
19
19
|
```
|
20
20
|
There are three options for generating tests from Rambo: The command line tool, the rake task, and the Ruby API. In all cases, Rambo will look for a `.rambo.yml` file in the root directory of your project for configuration options. Options may also be passed in through the command line as arguments or the Ruby API as a hash. There is currently no option to pass arguments to the Rake task, but Rambo comes pre-loaded with sensible defaults, and the `.rambo.yml` file is always an option.
|
@@ -39,6 +39,12 @@ Replace `foobar.raml` with the path of the actual RAML file from which you want
|
|
39
39
|
#### Options
|
40
40
|
By default, Rambo assumes you are testing a Rails app and generates tests using the Rails Rack::Test syntax. If you are testing a non-Rails Rack app, you can use the `--no-rails` switch to use the non-Rails syntax. Rambo does not currently support non-Rack-based frameworks.
|
41
41
|
|
42
|
+
If your app uses an API token header, you can also pass in the token to be used as an option using the `-T` or `--token` flag:
|
43
|
+
```
|
44
|
+
$ rambo foobar.raml -T sometoken
|
45
|
+
```
|
46
|
+
Rambo will automatically use this value for any header whose name matches "token" or "key" (not case-sensitive).
|
47
|
+
|
42
48
|
### The Rake Task
|
43
49
|
After adding `rambo_ruby` to your Gemfile or gemspec, you will need to add the following to your Rakefile:
|
44
50
|
```ruby
|
@@ -67,13 +73,16 @@ A sample `.rambo.yml` file could look like this:
|
|
67
73
|
```yaml
|
68
74
|
raml: docs/contracts/foobar.raml
|
69
75
|
rails: false
|
76
|
+
token: foobarbaz
|
70
77
|
```
|
71
|
-
The
|
78
|
+
The three possible keys are:
|
72
79
|
- `raml` - specifies the RAML file to use to generate the tests. The default, relative
|
73
80
|
to the root of your project directory, is `doc/raml/foobar.raml`, where `foobar.raml` is the first RAML file found in the `doc/raml` directory.
|
74
81
|
- `rails` - specifies whether your app is a Rails app. The default value is `true`.
|
82
|
+
- `token` - the API key or token to be included in the security headers. This value will be
|
83
|
+
used for any header whose name matches either "token" or "key" (not case-sensitive).
|
75
84
|
|
76
|
-
If a `.rambo.yml` file is present and additional options are passed in, the option values that are passed in will override those in the `.rambo.yml` file.
|
85
|
+
If a `.rambo.yml` file is present and additional options are passed in through the command line or Ruby API, the option values that are passed in will override those in the `.rambo.yml` file.
|
77
86
|
|
78
87
|
## Default Behavior
|
79
88
|
In order to provide the best user experience to a majority of users, Rambo comes with some sensible defaults that are easily overridden in an optional `.rambo.yml` file, or by using command line flags or a Ruby option hash (see above).
|
@@ -84,9 +93,9 @@ In the present version, Rambo only generates tests from a single RAML file. If y
|
|
84
93
|
As noted above, Rambo currently supports only Rack-based apps. Since Rails is the most popular Ruby framework, it assumes your app is a Rails app unless specified otherwise. Since Rack::Test syntax differs when testing Rails and non-Rails apps, you will need to tell Rambo if your app is not a Rails app using the `--no-rails` switch on the command line, the `{ rails: false }` option hash for the Ruby API, or specifying `rails: false` in your `.rambo.yml` file.
|
85
94
|
|
86
95
|
## About the Project
|
87
|
-
I started Rambo in March of 2016 as part of my work at [Renew Financial](http://renewfinancial.com).
|
96
|
+
I started Rambo in March of 2016 as part of my work at [Renew Financial](http://renewfinancial.com). For this reason, our primary focus has been on adding the features and functionality that are most important for testing RF's back-end services. Since my contract with Renew Financial has ended, I now have more latitude to do with the project what I want, but also less time to do it.
|
88
97
|
|
89
|
-
|
98
|
+
Rambo, therefore, considers RAML 1.0 and Rails 4 the default, and support for other frameworks and for RAML 0.8 is currently 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.
|
90
99
|
|
91
100
|
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.
|
92
101
|
|
@@ -15,7 +15,7 @@ module Rambo
|
|
15
15
|
generator.generate_matcher_dir!
|
16
16
|
generator.generate_examples!
|
17
17
|
generator.generate_spec_file!
|
18
|
-
generator.generate_rambo_helper!
|
18
|
+
generator.generate_rambo_helper!(options)
|
19
19
|
generator.generate_matchers!
|
20
20
|
end
|
21
21
|
end
|
@@ -43,7 +43,9 @@ module Rambo
|
|
43
43
|
def generate_rambo_helper!
|
44
44
|
Rambo::RSpec::HelperFile.new(
|
45
45
|
template_path: File.expand_path("../rspec/templates/rambo_helper_file_template.erb", __FILE__),
|
46
|
-
file_path:
|
46
|
+
file_path: "spec/rambo_helper.rb",
|
47
|
+
raml: raml,
|
48
|
+
options: options
|
47
49
|
).generate
|
48
50
|
end
|
49
51
|
|
@@ -54,7 +56,7 @@ module Rambo
|
|
54
56
|
def generate_matchers!
|
55
57
|
Rambo::RSpec::HelperFile.new(
|
56
58
|
template_path: File.expand_path("../rspec/templates/matcher_file_template.erb", __FILE__),
|
57
|
-
file_path: "spec/support/matchers/rambo_matchers.rb"
|
59
|
+
file_path: "spec/support/matchers/rambo_matchers.rb", raml: nil
|
58
60
|
).generate
|
59
61
|
end
|
60
62
|
end
|
@@ -17,14 +17,7 @@ module Rambo
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def pretty
|
20
|
-
|
21
|
-
ending = "}"
|
22
|
-
|
23
|
-
contents = headers.to_a.map {|pair|
|
24
|
-
"\t\"#{pair.first}\" => \"#{pair.last}\"\n"
|
25
|
-
}
|
26
|
-
|
27
|
-
"#{beginning}#{contents.join("")}#{ending}"
|
20
|
+
JSON.pretty_generate(headers).gsub("\":", "\" =>")
|
28
21
|
end
|
29
22
|
end
|
30
23
|
end
|
@@ -1,18 +1,33 @@
|
|
1
|
+
require "erb"
|
2
|
+
require "raml"
|
3
|
+
require "rambo/raml_models"
|
4
|
+
require "rambo/rspec/examples"
|
5
|
+
|
1
6
|
module Rambo
|
2
7
|
module RSpec
|
3
8
|
class HelperFile
|
4
|
-
|
9
|
+
attr_reader :options
|
10
|
+
|
11
|
+
def initialize(template_path:, file_path:, raml: nil, options: nil)
|
5
12
|
@template_path = template_path
|
6
13
|
@file_path = file_path
|
14
|
+
@options = options || { rails: true }
|
15
|
+
@raml = raml ? Rambo::RamlModels::Api.new(raml) : nil
|
7
16
|
end
|
8
17
|
|
9
18
|
def generate
|
10
|
-
write_to_file(
|
19
|
+
write_to_file(render) unless file_already_exists?
|
20
|
+
end
|
21
|
+
|
22
|
+
def render
|
23
|
+
b = binding
|
24
|
+
ERB.new(template, 0, "-", "@result").result(raml.instance_eval { b })
|
25
|
+
@result
|
11
26
|
end
|
12
27
|
|
13
28
|
private
|
14
29
|
|
15
|
-
attr_reader :template_path, :file_path
|
30
|
+
attr_reader :template_path, :file_path, :raml
|
16
31
|
|
17
32
|
def file_already_exists?
|
18
33
|
File.exist?(file_path)
|
@@ -1,3 +1,15 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
1
|
+
require "<%= @options.fetch(:rails, nil) ? "rails_helper" : "spec_helper" %>"
|
2
|
+
require "rack/test"
|
3
3
|
require_relative "./support/matchers/rambo_matchers"
|
4
|
+
|
5
|
+
<% if options.fetch(:rails, nil) %>module ApiHelper
|
6
|
+
include Rack::Test::Methods
|
7
|
+
|
8
|
+
def app
|
9
|
+
Rails.application
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
RSpec.configure do |config|
|
14
|
+
config.include ApiHelper, type: :request
|
15
|
+
end<% end %>
|
data/lib/version.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
RSpec.describe Rambo::DocumentGenerator do
|
2
2
|
let(:valid_file) { File.join(SPEC_DIR_ROOT, "support/foobar.raml") }
|
3
|
-
let(:options)
|
4
|
-
|
3
|
+
let(:options) { { rails: true } }
|
4
|
+
|
5
|
+
subject { described_class.new(valid_file, options) }
|
5
6
|
|
6
7
|
before(:each) do
|
7
8
|
allow_any_instance_of(Rambo::DocumentGenerator).to receive(:extract_raml)
|
@@ -51,23 +52,25 @@ RSpec.describe Rambo::DocumentGenerator do
|
|
51
52
|
describe "#generate_spec_dir!" do
|
52
53
|
it "generates the spec/contract directory" do
|
53
54
|
expect(FileUtils).to receive(:mkdir_p).with("spec/contract/output")
|
54
|
-
|
55
|
+
subject.generate_spec_dir!
|
55
56
|
end
|
56
57
|
end
|
57
58
|
|
58
59
|
describe "#generate_rambo_helper!" do
|
60
|
+
|
59
61
|
it "generates the rambo_helper file" do
|
60
62
|
aggregate_failures do
|
61
63
|
expect_any_instance_of(Rambo::RSpec::HelperFile)
|
62
64
|
.to receive(:initialize)
|
63
|
-
.with(
|
65
|
+
.with(hash_including(
|
64
66
|
:template_path => File.join(RAMBO_ROOT, "rambo/rspec/templates/rambo_helper_file_template.erb"),
|
65
|
-
:file_path => "spec/rambo_helper.rb"
|
66
|
-
|
67
|
+
:file_path => "spec/rambo_helper.rb",
|
68
|
+
:options => { rails: true }
|
69
|
+
))
|
67
70
|
expect_any_instance_of(Rambo::RSpec::HelperFile).to receive(:generate)
|
68
71
|
end
|
69
72
|
|
70
|
-
|
73
|
+
subject.generate_rambo_helper!
|
71
74
|
end
|
72
75
|
end
|
73
76
|
|
@@ -79,14 +82,14 @@ RSpec.describe Rambo::DocumentGenerator do
|
|
79
82
|
it "generates foobar_spec.rb" do
|
80
83
|
allow_any_instance_of(Rambo::RSpec::SpecFile).to receive(:render).and_return("foo")
|
81
84
|
expect(File).to receive(:write).with("spec/contract/foobar_spec.rb", "foo")
|
82
|
-
|
85
|
+
subject.generate_spec_file!
|
83
86
|
end
|
84
87
|
end
|
85
88
|
|
86
89
|
describe "#generate_matcher_dir!" do
|
87
90
|
it "creates a spec/support/matchers directory" do
|
88
91
|
expect(FileUtils).to receive(:mkdir_p).with("spec/support/matchers")
|
89
|
-
|
92
|
+
subject.generate_matcher_dir!
|
90
93
|
end
|
91
94
|
end
|
92
95
|
|
@@ -95,21 +98,21 @@ RSpec.describe Rambo::DocumentGenerator do
|
|
95
98
|
aggregate_failures do
|
96
99
|
expect_any_instance_of(Rambo::RSpec::HelperFile)
|
97
100
|
.to receive(:initialize)
|
98
|
-
.with(
|
99
|
-
template_path
|
100
|
-
file_path
|
101
|
-
)
|
101
|
+
.with(hash_including(
|
102
|
+
:template_path => File.join(RAMBO_ROOT, "rambo/rspec/templates/matcher_file_template.erb"),
|
103
|
+
:file_path => "spec/support/matchers/rambo_matchers.rb"
|
104
|
+
))
|
102
105
|
expect_any_instance_of(Rambo::RSpec::HelperFile).to receive(:generate)
|
103
106
|
end
|
104
107
|
|
105
|
-
|
108
|
+
subject.generate_matchers!
|
106
109
|
end
|
107
110
|
end
|
108
111
|
|
109
112
|
describe "#generate_examples!" do
|
110
113
|
it "creates the directory" do
|
111
114
|
expect(FileUtils).to receive(:mkdir_p).with("spec/support/examples")
|
112
|
-
|
115
|
+
subject.generate_examples!
|
113
116
|
end
|
114
117
|
end
|
115
118
|
end
|
@@ -5,7 +5,7 @@ RSpec.describe Rambo::RamlModels::Headers do
|
|
5
5
|
|
6
6
|
describe "#pretty" do
|
7
7
|
let(:pretty) do
|
8
|
-
|
8
|
+
%Q[{\n "Content-Type" => "application/json"\n}]
|
9
9
|
end
|
10
10
|
|
11
11
|
it "makes it pretty" do
|
@@ -16,11 +16,10 @@ RSpec.describe Rambo::RamlModels::Headers do
|
|
16
16
|
let(:headers) { { "Content-Type" => "application/json", "Accept" => "application/json" } }
|
17
17
|
|
18
18
|
let(:pretty) do
|
19
|
-
|
19
|
+
%Q[{\n "Content-Type" => "application/json",\n "Accept" => "application/json"\n}]
|
20
20
|
end
|
21
21
|
|
22
22
|
it "formats the header hash" do
|
23
|
-
pending "Test fails when functionality works as expected...confusing"
|
24
23
|
expect(subject.pretty).to eql pretty
|
25
24
|
end
|
26
25
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rambo_ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dana Scheider
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-07-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -287,7 +287,7 @@ rubyforge_project:
|
|
287
287
|
rubygems_version: 2.5.1
|
288
288
|
signing_key:
|
289
289
|
specification_version: 4
|
290
|
-
summary: rambo_ruby-0.3.
|
290
|
+
summary: rambo_ruby-0.3.1
|
291
291
|
test_files:
|
292
292
|
- features/create_files.feature
|
293
293
|
- features/error_modes.feature
|