rambo_ruby 0.5.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 06856629cc151adf7fcea55093eb86430cd8984b
4
- data.tar.gz: 250d9f949fa560c42568b758947ab05009c6f7a7
3
+ metadata.gz: ee4fdbe74465d4823e09b8cd7861e8f251b1d2e2
4
+ data.tar.gz: 730738e5726b1674529c8da1b319d78272354d06
5
5
  SHA512:
6
- metadata.gz: b54485d848d063d80ad55b7444f900296db4cda09f2e4f250bdfa0ae80a4cdb5e43f158bb9879915a634a860402fca3344c05001fe12860e8a17210cb42934bf
7
- data.tar.gz: a008371469187b544c0c7e045a78da41c6821e59bf7fee5c83c2ce0e47a4182267f834d8194cb1462eedd21d9d31054b5a173650f07cceea4094ff6d6bedf2a1
6
+ metadata.gz: d8e41a3b323913fc4a513d928bd192b6735bf7beb2b0c3dbb0b9c64fde3e46990e843ef86df279250446df68161555d8dde18c532f79208d2da162fc33619a5c
7
+ data.tar.gz: d1dec7fda7fc463ca23937d8e5c9fa23ef790e11d7222842a04dbef92a1ae04090dd0a079b45de6d8610b11e6d9c93d183a6a07048cba1f7deb576b5e9a768ba
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.5.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!
7
+ #### The current version of Rambo is 0.6.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
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.5'
17
+ gem 'rambo_ruby', '~> 0.6'
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.
@@ -37,7 +37,7 @@ $ rambo foobar.raml
37
37
  Replace `foobar.raml` with the path of the actual RAML file from which you want to generate tests.
38
38
 
39
39
  #### Options
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.
40
+ By default, Rambo assumes you are testing a Rails app and generates tests using syntax that will work for Rails apps. If you are testing a non-Rails app, you can use the `--framework` flag to indicate a `sinatra:classic`, `sinatra:modular`, or `grape` app. If you are using a different framework, please open an issue to let us know which, or submit a PR adding support for the framework you are using.
41
41
 
42
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
43
  ```
@@ -64,7 +64,7 @@ require "rambo"
64
64
 
65
65
  Rambo.generate_contract_tests!(File.expand_path("doc/foobar.raml"), {})
66
66
  ```
67
- You can pass any options in as a hash. Currently, the only supported option is `"rails"`, which can be set to `true` or `false`, with `true` being the default value. Set `"rails"` to `false` if your app is built with a different Rack-based framework. Currently, Non-Rack-based frameworks are not supported, but pull requests are welcome if your use case requires such support.
67
+ You can pass any options in as a hash. Currently, the available options are `:framework` and `:token`. Valid values for the `:framework` option are `:grape`, `:"sinatra:classic"`, `:"sinatra:modular"`, and `:rails`, with `:rails` being the default. The `:token` option takes an API token as a string.
68
68
 
69
69
  ## The .rambo.yml File
70
70
  By default, Rambo will always check for a `.rambo.yml` file in the root directory of your projects and load options from there. If there is no `.rambo.yml` file, default values will be used (see below).
@@ -72,13 +72,14 @@ By default, Rambo will always check for a `.rambo.yml` file in the root director
72
72
  A sample `.rambo.yml` file could look like this:
73
73
  ```yaml
74
74
  raml: docs/contracts/foobar.raml
75
- rails: false
75
+ framework: sinatra:modular
76
76
  token: foobarbaz
77
77
  ```
78
78
  The three possible keys are:
79
79
  - `raml` - specifies the RAML file to use to generate the tests. The default, relative
80
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.
81
- - `rails` - specifies whether your app is a Rails app. The default value is `true`.
81
+ - `framework` - specifies the framework you are using. The default value is `rails`; other available
82
+ frameworks are `sinatra:classic`, `sinatra:modular`, and `grape`.
82
83
  - `token` - the API key or token to be included in the security headers. This value will be
83
84
  used for any header whose name matches either "token" or "key" (not case-sensitive).
84
85
 
@@ -90,15 +91,16 @@ In order to provide the best user experience to a majority of users, Rambo comes
90
91
  ### RAML File
91
92
  In the present version, Rambo only generates tests from a single RAML file. If you're using the command line tool, the name of this file is passed in as an argument. If you're not using the command line tool and don't specify by another means (Ruby hash, `.rambo.yml` file) which RAML file to use, Rambo will look in `your_project/doc/raml` and use the first RAML file it finds.
92
93
 
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.
94
+ As noted above, Rambo currently supports only Rails, Sinatra, and Grape 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 `--framework` flag on the command line, the `:framework` option for the Ruby API, or specifying `framework: <framework>` in your `.rambo.yml` file.
95
+
96
+ ## Using Rambo with Grape or Sinatra
97
+ Rambo is able to generate tests for apps written in Rails, Grape, or Sinatra. However, it has one important limitation when working with non-Rails frameworks. Specifically, Rambo does not support multiple subclasses of `Sinatra::Base`, `Sinatra::Application`, or `Grape::API`. In order to identify the class of your app (which is required to configure Rack::Test), the Rambo-generated test configuration will use the first subclass of one of these classes that it finds. There is currently no option to override this behavior. (If you are building a classic Sinatra app instead of the modular type, `Sinatra::Application` will be used.)
94
98
 
95
99
  ## About the Project
96
100
  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.
97
101
 
98
102
  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.
99
103
 
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.
101
-
102
104
  ## Contributing
103
105
  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.
104
106
 
data/bin/rambo CHANGED
@@ -14,9 +14,9 @@ options = {}
14
14
  OptionParser.new do |opts|
15
15
  opts.banner = "Usage: rambo [FILE] [OPTIONS]"
16
16
 
17
- options[:rails] = true
18
- opts.on("--no-rails", "Generate tests for a non-Rails API") do |v|
19
- options[:rails] = false
17
+ options[:framework] = :rails
18
+ opts.on("--framework=FRAMEWORK", "Choose rails (default), sinatra:classic, sinatra:modular, or grape") do |v|
19
+ options[:framework] = v.to_sym
20
20
  end
21
21
  opts.on("--token=TOKEN", "-T=TOKEN", "Specify an API token") do |v|
22
22
  options[:token] = v
data/lib/rambo.rb CHANGED
@@ -8,9 +8,9 @@ module Rambo
8
8
  attr_reader :options, :file
9
9
 
10
10
  def generate_contract_tests!(file: nil, options: {})
11
- @options = yaml_options.merge(options)
12
- @options[:rails] = true unless @options.fetch(:rails, nil) == false
13
- @file = file || @options.delete(:raml) || raml_file
11
+ @options = yaml_options.merge(options)
12
+ @options[:framework] = :rails if @options.fetch(:framework, nil).nil?
13
+ @file = file || @options.delete(:raml) || raml_file
14
14
 
15
15
  DocumentGenerator.generate!(@file, @options)
16
16
  end
@@ -20,13 +20,15 @@ module Rambo
20
20
  def yaml_options
21
21
  opts = YAML.load(File.read(File.join(FileUtils.pwd, ".rambo.yml"))).symbolize_keys
22
22
 
23
+ opts[:framework] = opts[:framework].to_sym if opts[:framework]
24
+
23
25
  if opts && opts.fetch(:raml, nil)
24
26
  opts[:raml] = File.join(FileUtils.pwd, opts.fetch(:raml))
25
27
  end
26
28
 
27
29
  opts || {}
28
30
  rescue
29
- { rails: true }
31
+ { framework: :rails }
30
32
  end
31
33
 
32
34
  # TODO: Permit use of multiple RAML files, since right now this only takes
@@ -8,7 +8,7 @@ module Rambo
8
8
 
9
9
  def initialize(resource, options={})
10
10
  @resource = resource
11
- @options = options || { rails: true }
11
+ @options = options || { framework: :rails }
12
12
  end
13
13
 
14
14
  def template
@@ -11,10 +11,19 @@ module Rambo
11
11
  def initialize(template_path:, file_path:, raml: nil, options: nil)
12
12
  @template_path = template_path
13
13
  @file_path = file_path
14
- @options = options || { rails: true }
14
+ @options = options || { framework: :rails }
15
15
  @raml = raml ? Rambo::RamlModels::Api.new(raml) : nil
16
16
  end
17
17
 
18
+ def app_classes
19
+ {
20
+ :rails => "Rails.application",
21
+ :"sinatra:classic" => "Sinatra::Application",
22
+ :"sinatra:modular" => "Sinatra::Base.descendants.find {|klass| klass != Sinatra::Application } || Sinatra::Application",
23
+ :grape => "Grape::API.descendants.first"
24
+ }
25
+ end
26
+
18
27
  def generate
19
28
  write_to_file(render) unless file_already_exists?
20
29
  end
@@ -1,4 +1,4 @@
1
- describe "<%= @resource.to_s %>" do
1
+ <% rails = @options.fetch(:framework, :rails) == :rails %> describe "<%= @resource.to_s %>" do
2
2
  let(:route) { "<%= @resource.to_s %>" }
3
3
  <%- @resource.http_methods.each do |method| %>
4
4
  describe "<%= method.method.upcase %>" do
@@ -6,12 +6,13 @@
6
6
  {
7
7
  <%= headers.join(",\n ") %>
8
8
  }
9
- end<% end %><% if method.request_body %>
9
+ end<% end %>
10
+ <% if method.request_body %>
10
11
  let(:request_body) do
11
- JSON.parse(
12
+ <% if rails %>JSON.parse(
12
13
  File.read("<%= "spec/support/examples/#{@resource.to_s.gsub("/", "")}_#{method.method}_request_body.json" %>"),
13
14
  symbolize_names: true
14
- )
15
+ )<% else %>File.read("<%= "spec/support/examples/#{@resource.to_s.gsub("/", "")}_#{method.method}_request_body.json" %>")<% end %>
15
16
  end<% end %><% if has_schema = method.responses.first.bodies.first.schema %>
16
17
 
17
18
  let(:response_schema) do
@@ -1,15 +1,16 @@
1
- require "<%= @options.fetch(:rails, nil) ? "rails_helper" : "spec_helper" %>"
1
+ require "<%= @options.fetch(:framework, nil).nil? || @options.fetch(:framework) == :rails ? "rails_helper" : "spec_helper" %>"
2
2
  require "rack/test"
3
3
  require_relative "./support/matchers/rambo_matchers"
4
4
 
5
- <% if options.fetch(:rails, nil) %>module ApiHelper
5
+ module ApiHelper
6
6
  include Rack::Test::Methods
7
7
 
8
8
  def app
9
- Rails.application
9
+ require "active_support/core_ext/class/subclasses"
10
+ <%= app_classes.fetch(@options.fetch(:framework, :rails)) %>
10
11
  end
11
12
  end
12
13
 
13
14
  RSpec.configure do |config|
14
15
  config.include ApiHelper, type: :rambo
15
- end<% end %>
16
+ end
data/lib/version.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  module Rambo
2
2
  MAJOR = '0'
3
- MINOR = '5'
3
+ MINOR = '6'
4
4
  PATCH = '0'
5
5
 
6
6
  def self.version
@@ -1,7 +1,7 @@
1
1
  RSpec.describe Rambo::CLI do
2
2
  let(:io) { StringIO.new }
3
3
  let(:stderr) { StringIO.new }
4
- let(:opts) { { rails: true } }
4
+ let(:opts) { { framework: :rails } }
5
5
  let(:valid_file) { File.join(SPEC_DIR_ROOT, 'support/foobar.raml',) }
6
6
 
7
7
  describe "run!" do
@@ -1,6 +1,6 @@
1
1
  RSpec.describe Rambo::DocumentGenerator do
2
2
  let(:valid_file) { File.join(SPEC_DIR_ROOT, "support/foobar.raml") }
3
- let(:options) { { rails: true } }
3
+ let(:options) { { framework: :rails } }
4
4
 
5
5
  subject { described_class.new(valid_file, options) }
6
6
 
@@ -65,7 +65,7 @@ RSpec.describe Rambo::DocumentGenerator do
65
65
  .with(hash_including(
66
66
  :template_path => File.join(RAMBO_ROOT, "rambo/rspec/templates/rambo_helper_file_template.erb"),
67
67
  :file_path => "spec/rambo_helper.rb",
68
- :options => { rails: true }
68
+ :options => { framework: :rails }
69
69
  ))
70
70
  expect_any_instance_of(Rambo::RSpec::HelperFile).to receive(:generate)
71
71
  end
@@ -2,13 +2,13 @@ RSpec.describe Rambo do
2
2
  let(:file_contents) do
3
3
  <<-EOF
4
4
  raml: doc/raml/foobar.raml
5
- rails: false
5
+ framework: rails
6
6
  EOF
7
7
  end
8
8
 
9
9
  describe ".generate_contract_tests!" do
10
10
  let(:valid_file) { "foobar.raml" }
11
- let(:default_options) { { rails: true } }
11
+ let(:default_options) { { framework: :rails } }
12
12
 
13
13
  before(:each) do
14
14
  allow(Dir).to receive(:foreach).and_return("/Users/dscheider/rambo/doc/raml/#{valid_file}")
@@ -39,37 +39,57 @@ rails: false
39
39
  it "sets the RAML file to the one from the file" do
40
40
  expect(Rambo::DocumentGenerator)
41
41
  .to receive(:generate!)
42
- .with(File.expand_path("doc/raml/foobar.raml"), { rails: false })
42
+ .with(File.expand_path("doc/raml/foobar.raml"), { framework: :rails })
43
43
 
44
44
  Rambo.generate_contract_tests!
45
45
  end
46
46
 
47
- context "rails option set to false in file" do
48
- it "sets rails option to false" do
49
- allow(Rambo).to receive(:yaml_options).and_return({ rails: false })
47
+ context "framework set to sinatra:classic" do
48
+ it "sets framework to sinatra:classic" do
49
+ allow(Rambo).to receive(:yaml_options).and_return({ framework: :"sinatra:classic" })
50
50
  expect(Rambo::DocumentGenerator)
51
51
  .to receive(:generate!)
52
- .with("/Users/dscheider/rambo/doc/raml/#{valid_file}", { rails: false })
52
+ .with("/Users/dscheider/rambo/doc/raml/#{valid_file}", { framework: :"sinatra:classic" })
53
53
  Rambo.generate_contract_tests!
54
54
  end
55
55
  end
56
56
 
57
- context "rails option set to true in file" do
58
- it "sets rails option to true" do
59
- allow(Rambo).to receive(:yaml_options).and_return({ rails: true })
57
+ context "framework set to sinatra:modular" do
58
+ it "sets framework to sinatra:modular" do
59
+ allow(Rambo).to receive(:yaml_options).and_return({ framework: :"sinatra:modular" })
60
60
  expect(Rambo::DocumentGenerator)
61
61
  .to receive(:generate!)
62
- .with("/Users/dscheider/rambo/doc/raml/#{valid_file}", { rails: true })
62
+ .with("/Users/dscheider/rambo/doc/raml/#{valid_file}", { framework: :"sinatra:modular" })
63
63
  Rambo.generate_contract_tests!
64
64
  end
65
65
  end
66
66
 
67
- context "rails option not set in file" do
68
- it "sets rails option to true" do
67
+ context "framework set to Grape" do
68
+ it "sets framework to Grape" do
69
+ allow(Rambo).to receive(:yaml_options).and_return({ framework: :grape })
70
+ expect(Rambo::DocumentGenerator)
71
+ .to receive(:generate!)
72
+ .with("/Users/dscheider/rambo/doc/raml/#{valid_file}", { framework: :grape })
73
+ Rambo.generate_contract_tests!
74
+ end
75
+ end
76
+
77
+ context "framework set to Rails" do
78
+ it "sets framework to Rails" do
79
+ allow(Rambo).to receive(:yaml_options).and_return({ framework: :rails })
80
+ expect(Rambo::DocumentGenerator)
81
+ .to receive(:generate!)
82
+ .with("/Users/dscheider/rambo/doc/raml/#{valid_file}", { framework: :rails })
83
+ Rambo.generate_contract_tests!
84
+ end
85
+ end
86
+
87
+ context "framework option not set in file" do
88
+ it "sets framework to Rails" do
69
89
  allow(Rambo).to receive(:yaml_options).and_return({})
70
90
  expect(Rambo::DocumentGenerator)
71
91
  .to receive(:generate!)
72
- .with(File.expand_path("/Users/dscheider/rambo/doc/raml/#{valid_file}"), { rails: true })
92
+ .with(File.expand_path("/Users/dscheider/rambo/doc/raml/#{valid_file}"), { framework: :rails })
73
93
  Rambo.generate_contract_tests!
74
94
  end
75
95
  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.5.0
4
+ version: 0.6.0
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-07-11 00:00:00.000000000 Z
11
+ date: 2016-07-13 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.6.6
288
288
  signing_key:
289
289
  specification_version: 4
290
- summary: rambo_ruby-0.5.0
290
+ summary: rambo_ruby-0.6.0
291
291
  test_files:
292
292
  - features/create_files.feature
293
293
  - features/error_modes.feature