rambo_ruby 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +59 -9
  3. data/bin/rambo +1 -1
  4. data/features/support/cucumber_helper.rb +3 -3
  5. data/features/support/env.rb +3 -0
  6. data/lib/rambo.rb +36 -0
  7. data/lib/{cli.rb → rambo/cli.rb} +7 -13
  8. data/lib/{document_generator.rb → rambo/document_generator.rb} +14 -2
  9. data/lib/rambo/rake.rb +1 -0
  10. data/lib/rambo/rake/task.rb +30 -0
  11. data/lib/{raml_models.rb → rambo/raml_models.rb} +0 -0
  12. data/lib/{raml_models → rambo/raml_models}/api.rb +0 -0
  13. data/lib/{raml_models → rambo/raml_models}/body.rb +0 -0
  14. data/lib/{raml_models → rambo/raml_models}/headers.rb +0 -0
  15. data/lib/{raml_models → rambo/raml_models}/method.rb +0 -0
  16. data/lib/{raml_models → rambo/raml_models}/resource.rb +0 -0
  17. data/lib/{raml_models → rambo/raml_models}/response.rb +0 -0
  18. data/lib/{rspec.rb → rambo/rspec.rb} +0 -0
  19. data/lib/{rspec → rambo/rspec}/example_group.rb +1 -1
  20. data/lib/{rspec → rambo/rspec}/examples.rb +2 -2
  21. data/lib/{rspec → rambo/rspec}/helper_file.rb +0 -0
  22. data/lib/{rspec → rambo/rspec}/spec_file.rb +2 -2
  23. data/lib/{rspec → rambo/rspec}/templates/example_group_template.erb +0 -0
  24. data/lib/{rspec → rambo/rspec}/templates/matcher_file_template.erb +0 -0
  25. data/lib/{rspec → rambo/rspec}/templates/rambo_helper_file_template.erb +0 -0
  26. data/lib/{rspec → rambo/rspec}/templates/spec_file_template.erb +0 -0
  27. data/lib/version.rb +1 -1
  28. data/rambo_ruby.gemspec +3 -6
  29. data/spec/lib/{cli_spec.rb → rambo/cli_spec.rb} +1 -1
  30. data/spec/lib/{document_generator_spec.rb → rambo/document_generator_spec.rb} +44 -3
  31. data/spec/lib/rambo/rake/task_spec.rb +20 -0
  32. data/spec/lib/{raml_models → rambo/raml_models}/api_spec.rb +1 -1
  33. data/spec/lib/{raml_models → rambo/raml_models}/body_spec.rb +3 -3
  34. data/spec/lib/{raml_models → rambo/raml_models}/headers_spec.rb +1 -1
  35. data/spec/lib/{raml_models → rambo/raml_models}/method_spec.rb +1 -1
  36. data/spec/lib/{raml_models → rambo/raml_models}/resource_spec.rb +1 -1
  37. data/spec/lib/{raml_models → rambo/raml_models}/response_spec.rb +1 -1
  38. data/spec/lib/{rspec → rambo/rspec}/example_group_spec.rb +4 -4
  39. data/spec/lib/{rspec → rambo/rspec}/examples_spec.rb +1 -1
  40. data/spec/lib/{rspec → rambo/rspec}/helper_file_spec.rb +2 -2
  41. data/spec/lib/{rspec → rambo/rspec}/spec_file_spec.rb +2 -2
  42. data/spec/lib/rambo_spec.rb +55 -0
  43. data/spec/spec_helper.rb +3 -3
  44. metadata +72 -72
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 181b7e230121fc0dd07a1577c7dd39697ab18409
4
- data.tar.gz: 399cbdee63d18ff87611250c0f0b9e8d9ecdf4d9
3
+ metadata.gz: 0cce940ea2b21f4db0e40bdc31be6e8c8193b0bb
4
+ data.tar.gz: d44fe75445872974782a1d0f79b5da966175897d
5
5
  SHA512:
6
- metadata.gz: 61746a4c0f25f15a25cfe25588045506040fb2dcff720ae38d7f322802227b196dec5fed092eae158877d99e8e62f794acba20fe8e05f11fa9df43a35a2b8635
7
- data.tar.gz: e254055accaecd97a45e116fbd9e9522484e8b6aeae75244da60fa076afc9594d1f65dbd23911a6eed82d1142e30d0cf876f19fe82d0909f66dbe57157d9c906
6
+ metadata.gz: 349fbeddb405567e4276791a1b6682c950a56164403a14f4a788ae3afe546c80c09e654e0ce1155f5df0ae8c8dbeb03f849686eaa2c5bf5cfb4327666af39996
7
+ data.tar.gz: 355b9f9c0604387b3d4640a853d68bd2cedfbd60016a74d6b9ba3e765ef869550fa0cd7b842af9d7572ce42512ee50f0e46d92991e4eb486b48d708021b06362
data/README.md CHANGED
@@ -1,10 +1,10 @@
1
1
  # Rambo
2
- [![Build Status](https://travis-ci.org/danascheider/rambo.svg?branch=master)](https://travis-ci.org/danascheider/rambo) [![Code Climate](https://codeclimate.com/github/danascheider/rambo/badges/gpa.svg)](https://codeclimate.com/github/danascheider/rambo) [![Dependency Status](https://gemnasium.com/badges/github.com/danascheider/rambo.svg)](https://gemnasium.com/github.com/danascheider/rambo)
2
+ [![Gem Version](https://badge.fury.io/rb/rambo_ruby.svg)](https://badge.fury.io/rb/rambo_ruby) [![Build Status](https://travis-ci.org/danascheider/rambo.svg?branch=master)](https://travis-ci.org/danascheider/rambo) [![Code Climate](https://codeclimate.com/github/danascheider/rambo/badges/gpa.svg)](https://codeclimate.com/github/danascheider/rambo) [![Dependency Status](https://gemnasium.com/badges/github.com/danascheider/rambo.svg)](https://gemnasium.com/github.com/danascheider/rambo)
3
3
  [![Coverage Status](https://coveralls.io/repos/github/danascheider/rambo/badge.svg?branch=dev)](https://coveralls.io/github/danascheider/rambo?branch=master)
4
4
 
5
- Rambo is a gem that generates API contract tests from API docs in [RAML](http://raml.org/).
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.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!
7
+ #### The current version of Rambo is 0.2.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,22 +14,72 @@ 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.0.1'
17
+ gem 'rambo_ruby', '~> 0.2.0'
18
18
  end
19
19
  ```
20
- To run Rambo, from the root directory of your project, run:
21
- ```
22
- $ rambo foobar.raml
23
- ```
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.
21
+
24
22
  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
23
 
24
+ The Rack::Test API uses different syntax for Rails and non-Rails Rack apps. By default, Rambo assumes it is dealing with a Rails app, but this is easily modified by passing options or using a .rambo.yml file.
25
+
26
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
27
 
28
28
  - `require "rack/test"`
29
29
  - `require "json"`
30
30
  - `require "json-schema"`
31
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.
32
+ ### The Command Line Tool
33
+ To use the command line tool, simply `cd` into the root directory of your project and run
34
+ ```
35
+ $ rambo foobar.raml
36
+ ```
37
+ Replace `foobar.raml` with the path of the actual RAML file from which you want to generate tests.
38
+
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.
41
+
42
+ ### The Rake Task
43
+ After adding `rambo_ruby` to your Gemfile or gemspec, you will need to add the following to your Rakefile:
44
+ ```ruby
45
+ require "rambo"
46
+
47
+ Rambo::Rake::Task.new
48
+ ```
49
+ This will create a Rake task called `rambo`. Now, you can generate tests by running:
50
+ ```
51
+ rake rambo
52
+ ```
53
+
54
+ ### The Ruby API
55
+ You can generate Rambo tests from a Ruby script using:
56
+ ```ruby
57
+ require "rambo"
58
+
59
+ Rambo.generate_contract_tests!(File.expand_path("doc/foobar.raml"), {})
60
+ ```
61
+ 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.
62
+
63
+ ## The .rambo.yml File
64
+ 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).
65
+
66
+ A sample `.rambo.yml` file could look like this:
67
+ ```yaml
68
+ raml: docs/contracts/foobar.raml
69
+ rails: false
70
+ ```
71
+ The two possible keys are:
72
+ - `raml` - specifies the RAML file to use to generate the tests. The default, relative
73
+ 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
+ - `rails` - specifies whether your app is a Rails app. The default value is `true`.
75
+
76
+ ## Default Behavior
77
+ 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).
78
+
79
+ ### RAML File
80
+ 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.
81
+
82
+ 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.
33
83
 
34
84
  ## About the Project
35
85
  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.
data/bin/rambo CHANGED
@@ -4,7 +4,7 @@ lib = File.expand_path("../../lib", __FILE__)
4
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
5
 
6
6
  require "fileutils"
7
- require "cli"
7
+ require "rambo/cli"
8
8
  require "optparse"
9
9
 
10
10
  filename = ARGV[0] ? File.expand_path(ARGV[0], FileUtils.pwd) : nil
@@ -1,9 +1,9 @@
1
1
  module CucumberHelper
2
2
  def read_example(example)
3
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__)
4
+ File.join(CUCUMBER_DIR_ROOT, "examples/raml/#{example}"),
5
+ File.join(CUCUMBER_DIR_ROOT, "examples/rspec/#{example}"),
6
+ File.join(CUCUMBER_DIR_ROOT, "examples/rspec/#{example}")
7
7
  ]
8
8
 
9
9
  possible_paths.each do |path|
@@ -6,3 +6,6 @@ require 'aruba/cucumber'
6
6
  require_relative './cucumber_helper'
7
7
 
8
8
  World(CucumberHelper)
9
+
10
+ CUCUMBER_DIR_ROOT = File.expand_path("../", __FILE__)
11
+ RAMBO_ROOT = File.expand_path("../../lib", __FILE__)
data/lib/rambo.rb ADDED
@@ -0,0 +1,36 @@
1
+ Dir["#{File.dirname(__FILE__)}/rambo/**/*.rb"].each {|file| require file }
2
+
3
+ module Rambo
4
+ class << self
5
+ attr_reader :options, :file
6
+
7
+ def generate_contract_tests!(file = nil, opts = nil)
8
+ @options = opts || yaml_options
9
+ @file = file || @options.fetch(:raml, nil) || raml_file
10
+
11
+ DocumentGenerator.generate!(@file, @options)
12
+ end
13
+
14
+ private
15
+
16
+ def yaml_options
17
+ opts = YAML.load(File.read(File.expand_path(".rambo.yml")))
18
+
19
+ if opts && opts.fetch("raml", nil)
20
+ opts["raml"] = File.expand_path(opts.fetch("raml"))
21
+ end
22
+
23
+ opts
24
+ rescue
25
+ { rails: true }
26
+ end
27
+
28
+ # TODO: Permit use of multiple RAML files, since right now this only takes
29
+ # the first one it finds in the "doc" directory.
30
+
31
+ def raml_file
32
+ return options.fetch("raml") if options && options.fetch("raml", nil)
33
+ Dir.foreach("doc/raml") {|file| return "doc/raml/#{file}" if file.match(/\.raml$/) }
34
+ end
35
+ end
36
+ end
@@ -1,5 +1,5 @@
1
1
  require "colorize"
2
- require "document_generator"
2
+ require "rambo/document_generator"
3
3
 
4
4
  module Rambo
5
5
  class CLI
@@ -10,23 +10,17 @@ module Rambo
10
10
  @options = opts
11
11
 
12
12
  validate!
13
-
14
- @generator = Rambo::DocumentGenerator.new(file, options)
15
13
  end
16
14
 
17
15
  def run!
18
16
  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
17
 
28
18
  begin
29
- generator.generate_spec_file!
19
+ Rambo::DocumentGenerator.generate!(file, options)
20
+
21
+ stdout.puts("Generating contract tests...")
22
+ sleep 0.4
23
+
30
24
  stdout.puts("Done!".green)
31
25
  rescue NoMethodError => e
32
26
  stderr.puts("Error: #{e.message}".red)
@@ -59,7 +53,7 @@ module Rambo
59
53
  end
60
54
 
61
55
  def logo
62
- File.read(File.expand_path("../../assets/logo.txt", __FILE__))
56
+ File.read(File.expand_path("../../../assets/logo.txt", __FILE__))
63
57
  end
64
58
  end
65
59
  end
@@ -1,13 +1,25 @@
1
1
  require "fileutils"
2
2
  require "raml-rb"
3
3
 
4
- require "rspec/spec_file"
5
- require "rspec/helper_file"
4
+ require "rambo/rspec/spec_file"
5
+ require "rambo/rspec/helper_file"
6
6
 
7
7
  module Rambo
8
8
  class DocumentGenerator
9
9
  attr_accessor :file, :raml, :options
10
10
 
11
+ class << self
12
+ def generate!(file, options={})
13
+ generator = new(file, options)
14
+ generator.generate_spec_dir!
15
+ generator.generate_matcher_dir!
16
+ generator.generate_examples!
17
+ generator.generate_spec_file!
18
+ generator.generate_rambo_helper!
19
+ generator.generate_matchers!
20
+ end
21
+ end
22
+
11
23
  def initialize(file, options={})
12
24
  @file = file
13
25
  @raml = Raml::Parser.parse_file(file)
data/lib/rambo/rake.rb ADDED
@@ -0,0 +1 @@
1
+ Dir["#{File.dirname(__FILE__)}/rake/**/*.rb"].each {|file| require file }
@@ -0,0 +1,30 @@
1
+ lib = File.expand_path("../../..", __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+
4
+ require "rake"
5
+ require "yaml"
6
+ require "colorize"
7
+ require "rambo"
8
+
9
+ module Rambo
10
+ module Rake
11
+ class Task
12
+ include ::Rake::DSL
13
+
14
+ def initialize
15
+ define_task
16
+ end
17
+
18
+ private
19
+
20
+ def define_task
21
+ desc "Generate contract tests"
22
+ task :rambo do
23
+ Rambo.generate_contract_tests!
24
+
25
+ puts "Done generating contract tests.".green
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -8,7 +8,7 @@ module Rambo
8
8
 
9
9
  def initialize(resource, options={})
10
10
  @resource = resource
11
- @options = options
11
+ @options = options || { rails: true }
12
12
  end
13
13
 
14
14
  def template
@@ -1,11 +1,11 @@
1
- require "rspec/example_group"
1
+ require "rambo/rspec/example_group"
2
2
 
3
3
  module Rambo
4
4
  module RSpec
5
5
  class Examples
6
6
  attr_reader :raml, :resources, :examples, :options
7
7
 
8
- def initialize(raml, options={})
8
+ def initialize(raml, options=nil)
9
9
  @raml = raml
10
10
  @options = options
11
11
  end
File without changes
@@ -1,8 +1,8 @@
1
1
  require 'erb'
2
2
  require 'raml'
3
3
 
4
- require "rspec/examples"
5
- require "raml_models"
4
+ require "rambo/rspec/examples"
5
+ require "rambo/raml_models"
6
6
 
7
7
  module Rambo
8
8
  module RSpec
data/lib/version.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  module Rambo
2
2
  MAJOR = '0'
3
- MINOR = '1'
3
+ MINOR = '2'
4
4
  PATCH = '0'
5
5
 
6
6
  def self.version
data/rambo_ruby.gemspec CHANGED
@@ -1,7 +1,5 @@
1
1
  # -*- encoding: utf-8 -*-
2
- lib = File.expand_path("../lib", __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require "version"
2
+ require File.expand_path "../lib/version.rb", __FILE__
5
3
 
6
4
  Gem::Specification.new do |s|
7
5
  s.name = "rambo_ruby"
@@ -16,14 +14,13 @@ Gem::Specification.new do |s|
16
14
 
17
15
  s.add_dependency "rspec", "~> 3.4"
18
16
  s.add_dependency "raml-rb", "~> 0.0.6"
19
- s.add_dependency "rack-test", "~> 0.6"
20
17
  s.add_dependency "colorize", "~> 0.7"
21
- s.add_dependency "json_test_data", "~> 1.0"
18
+ s.add_dependency "json_test_data", "~> 1.1", ">= 1.1.1"
22
19
  s.add_dependency "json-schema", "~> 2.6"
20
+ s.add_dependency "rake", "~> 11.0"
23
21
 
24
22
  s.add_development_dependency "cucumber", "~> 2.1"
25
23
  s.add_development_dependency "json", "~> 1.7"
26
- s.add_development_dependency "rake", "~> 11.0"
27
24
  s.add_development_dependency "coveralls", "~> 0.7"
28
25
  s.add_development_dependency "aruba", "~> 0.13"
29
26
 
@@ -2,7 +2,7 @@ RSpec.describe Rambo::CLI do
2
2
  let(:io) { StringIO.new }
3
3
  let(:stderr) { StringIO.new }
4
4
  let(:opts) { { rails: true } }
5
- let(:valid_file) { File.expand_path('../../support/foobar.raml', __FILE__) }
5
+ let(:valid_file) { File.join(SPEC_DIR_ROOT, 'support/foobar.raml',) }
6
6
 
7
7
  describe "run!" do
8
8
  let(:cli) { Rambo::CLI.new(valid_file, opts, io, stderr) }
@@ -1,5 +1,5 @@
1
1
  RSpec.describe Rambo::DocumentGenerator do
2
- let(:valid_file) { File.expand_path('../../support/foobar.raml', __FILE__) }
2
+ let(:valid_file) { File.join(SPEC_DIR_ROOT, "support/foobar.raml") }
3
3
  let(:options) { { rails: true } }
4
4
  let(:generator) { Rambo::DocumentGenerator.new(valid_file, options) }
5
5
 
@@ -7,6 +7,47 @@ RSpec.describe Rambo::DocumentGenerator do
7
7
  allow_any_instance_of(Rambo::DocumentGenerator).to receive(:extract_raml)
8
8
  end
9
9
 
10
+ describe ".generate!" do
11
+ before(:each) do
12
+ allow_any_instance_of(described_class).to receive(:generate_matchers!)
13
+ allow_any_instance_of(described_class).to receive(:generate_spec_dir!)
14
+ allow_any_instance_of(described_class).to receive(:generate_spec_file!)
15
+ allow_any_instance_of(described_class).to receive(:generate_matcher_dir!)
16
+ allow_any_instance_of(described_class).to receive(:generate_rambo_helper!)
17
+ allow_any_instance_of(described_class).to receive(:generate_examples!)
18
+ end
19
+
20
+ it "generates a spec directory" do
21
+ expect_any_instance_of(described_class).to receive(:generate_spec_dir!)
22
+ described_class.generate!(valid_file, options)
23
+ end
24
+
25
+ it "generates the Rambo helper" do
26
+ expect_any_instance_of(described_class).to receive(:generate_rambo_helper!)
27
+ described_class.generate!(valid_file, options)
28
+ end
29
+
30
+ it "generates the matcher directory" do
31
+ expect_any_instance_of(described_class).to receive(:generate_matcher_dir!)
32
+ described_class.generate!(valid_file, options)
33
+ end
34
+
35
+ it "generates the matchers" do
36
+ expect_any_instance_of(described_class).to receive(:generate_matchers!)
37
+ described_class.generate!(valid_file, options)
38
+ end
39
+
40
+ it "generates the examples" do
41
+ expect_any_instance_of(described_class).to receive(:generate_examples!)
42
+ described_class.generate!(valid_file, options)
43
+ end
44
+
45
+ it "generates a spec file" do
46
+ expect_any_instance_of(described_class).to receive(:generate_spec_file!)
47
+ described_class.generate!(valid_file, options)
48
+ end
49
+ end
50
+
10
51
  describe "#generate_spec_dir!" do
11
52
  it "generates the spec/contract directory" do
12
53
  expect(FileUtils).to receive(:mkdir_p).with("spec/contract/output")
@@ -20,7 +61,7 @@ RSpec.describe Rambo::DocumentGenerator do
20
61
  expect_any_instance_of(Rambo::RSpec::HelperFile)
21
62
  .to receive(:initialize)
22
63
  .with({
23
- :template_path => File.expand_path("lib/rspec/templates/rambo_helper_file_template.erb"),
64
+ :template_path => File.join(RAMBO_ROOT, "rambo/rspec/templates/rambo_helper_file_template.erb"),
24
65
  :file_path => "spec/rambo_helper.rb"
25
66
  })
26
67
  expect_any_instance_of(Rambo::RSpec::HelperFile).to receive(:generate)
@@ -55,7 +96,7 @@ RSpec.describe Rambo::DocumentGenerator do
55
96
  expect_any_instance_of(Rambo::RSpec::HelperFile)
56
97
  .to receive(:initialize)
57
98
  .with(
58
- template_path: File.expand_path("lib/rspec/templates/matcher_file_template.erb"),
99
+ template_path: File.join(RAMBO_ROOT, "rambo/rspec/templates/matcher_file_template.erb"),
59
100
  file_path: "spec/support/matchers/rambo_matchers.rb"
60
101
  )
61
102
  expect_any_instance_of(Rambo::RSpec::HelperFile).to receive(:generate)
@@ -0,0 +1,20 @@
1
+ RSpec.describe Rambo::Rake::Task do
2
+ describe "#initialize" do
3
+ it "defines the task" do
4
+ expect_any_instance_of(Rambo::Rake::Task)
5
+ .to receive(:define_task)
6
+ described_class.new
7
+ end
8
+ end
9
+
10
+ describe "rambo task" do
11
+ before(:each) do
12
+ Rambo::Rake::Task.new
13
+ end
14
+
15
+ it "calls generate_contract_tests!" do
16
+ expect(Rambo).to receive(:generate_contract_tests!)
17
+ Rake::Task[:rambo].invoke
18
+ end
19
+ end
20
+ end
@@ -1,5 +1,5 @@
1
1
  RSpec.describe Rambo::RamlModels::Api do
2
- let(:raml_file) { File.expand_path("../../../support/multiple_resources.raml", __FILE__) }
2
+ let(:raml_file) { File.join(SPEC_DIR_ROOT, "support/multiple_resources.raml") }
3
3
  let(:raml) { Raml::Parser.parse_file(raml_file) }
4
4
 
5
5
  subject { described_class.new(raml) }
@@ -5,7 +5,7 @@ RSpec.describe Rambo::RamlModels::Body do
5
5
  subject { described_class.new(body) }
6
6
 
7
7
  describe "#content_type" do
8
- let(:raml_file) { File.expand_path("../../../support/foobar.raml", __FILE__) }
8
+ let(:raml_file) { File.join(SPEC_DIR_ROOT, "support/foobar.raml") }
9
9
 
10
10
  it "returns the content type" do
11
11
  expect(subject.content_type).to eql body.content_type
@@ -14,7 +14,7 @@ RSpec.describe Rambo::RamlModels::Body do
14
14
 
15
15
  describe "#example" do
16
16
  context "when an example is given" do
17
- let(:raml_file) { File.expand_path("../../../support/foobar.raml", __FILE__) }
17
+ let(:raml_file) { File.join(SPEC_DIR_ROOT, "support/foobar.raml") }
18
18
 
19
19
  it "returns an example" do
20
20
  expect(subject.example).to eql body.example
@@ -22,7 +22,7 @@ RSpec.describe Rambo::RamlModels::Body do
22
22
  end
23
23
 
24
24
  context "when a schema is given" do
25
- let(:raml_file) { File.expand_path("../../../../features/support/examples/raml/basic_raml_with_schema.raml", __FILE__) }
25
+ let(:raml_file) { File.join(SPEC_DIR_ROOT, "../features/support/examples/raml/basic_raml_with_schema.raml") }
26
26
 
27
27
  it "returns generated JSON data" do
28
28
  expect(JSON.parse(subject.example)).to have_key "data"
@@ -1,6 +1,6 @@
1
1
  RSpec.describe Rambo::RamlModels::Headers do
2
2
  let(:raml) { Raml::Parser.parse_file(raml_file) }
3
- let(:raml_file) { File.expand_path("../../../support/post_with_request_headers.raml", __FILE__) }
3
+ let(:raml_file) { File.join(SPEC_DIR_ROOT, "support/post_with_request_headers.raml") }
4
4
  let(:headers) { raml.resources.first.methods.first.headers }
5
5
 
6
6
  subject { described_class.new(headers) }
@@ -1,5 +1,5 @@
1
1
  RSpec.describe Rambo::RamlModels::Method do
2
- let(:raml_file) { File.expand_path("../../../support/foo.raml", __FILE__) }
2
+ let(:raml_file) { File.join(SPEC_DIR_ROOT, "support/foo.raml") }
3
3
  let(:raml) { Raml::Parser.parse_file(raml_file) }
4
4
  let(:method) { raml.resources.first.methods.first }
5
5
 
@@ -1,5 +1,5 @@
1
1
  RSpec.describe Rambo::RamlModels::Resource do
2
- let(:raml_file) { File.expand_path("../../../support/foobar.raml", __FILE__) }
2
+ let(:raml_file) { File.join(SPEC_DIR_ROOT, "support/foobar.raml") }
3
3
  let(:raml) { Raml::Parser.parse_file(raml_file) }
4
4
  let(:resource) { raml.resources.first }
5
5
 
@@ -1,5 +1,5 @@
1
1
  RSpec.describe Rambo::RamlModels::Response do
2
- let(:raml_file) { File.expand_path("../../../support/foobar.raml", __FILE__) }
2
+ let(:raml_file) { File.join(SPEC_DIR_ROOT, "support/foobar.raml") }
3
3
  let(:raml) { Raml::Parser.parse_file(raml_file) }
4
4
  let(:response) { raml.resources.first.methods.first.responses.first }
5
5
 
@@ -1,5 +1,5 @@
1
1
  RSpec.describe Rambo::RSpec::ExampleGroup do
2
- let(:raml_file) { File.expand_path("../../../support/foobar.raml", __FILE__) }
2
+ let(:raml_file) { File.join(SPEC_DIR_ROOT, "/support/foobar.raml") }
3
3
  let(:raml) { Raml::Parser.parse_file(raml_file) }
4
4
  let(:resource) { Rambo::RamlModels::Resource.new(raml.resources.first) }
5
5
  let(:options) { { rails: true } }
@@ -31,7 +31,7 @@ RSpec.describe Rambo::RSpec::ExampleGroup do
31
31
  end
32
32
 
33
33
  context "when the route has a response schema" do
34
- let(:raml_file) { File.expand_path("../../../support/basic_raml_with_post_route.raml", __FILE__) }
34
+ let(:raml_file) {File.join(SPEC_DIR_ROOT, "support/basic_raml_with_post_route.raml") }
35
35
 
36
36
  it "creates a response schema object" do
37
37
  aggregate_failures do
@@ -51,7 +51,7 @@ RSpec.describe Rambo::RSpec::ExampleGroup do
51
51
  end
52
52
 
53
53
  context "when the route has a request body" do
54
- let(:raml_file) { File.expand_path("../../../support/basic_raml_with_post_route.raml", __FILE__) }
54
+ let(:raml_file) { File.join(SPEC_DIR_ROOT, "support/basic_raml_with_post_route.raml") }
55
55
 
56
56
  it "adds a request body" do
57
57
  expect(subject.render).to include("let(:request_body) do")
@@ -63,7 +63,7 @@ RSpec.describe Rambo::RSpec::ExampleGroup do
63
63
  end
64
64
 
65
65
  context "when the route has request headers" do
66
- let(:raml_file) { File.expand_path("../../../support/post_with_request_headers.raml", __FILE__) }
66
+ let(:raml_file) { File.join(SPEC_DIR_ROOT, "support/post_with_request_headers.raml") }
67
67
 
68
68
  it "adds headers" do
69
69
  expect(subject.render).to include("let(:headers) do")
@@ -1,5 +1,5 @@
1
1
  RSpec.describe Rambo::RSpec::Examples do
2
- let(:raml_file) { File.expand_path("../../../support/foobar.raml", __FILE__) }
2
+ let(:raml_file) { File.join(SPEC_DIR_ROOT, "support/foobar.raml") }
3
3
  let(:raw_raml) { Raml::Parser.parse_file(raml_file) }
4
4
  let(:options) { { rails: true } }
5
5
  let(:raml) { Rambo::RamlModels::Api.new(raw_raml) }
@@ -1,10 +1,10 @@
1
1
  RSpec.describe Rambo::RSpec::HelperFile do
2
2
  let(:template_path) {
3
- File.expand_path("lib/rspec/templates/matcher_file_template.erb")
3
+ File.join(RAMBO_ROOT, "rambo/rspec/templates/matcher_file_template.erb")
4
4
  }
5
5
 
6
6
  let(:file_path) {
7
- File.expand_path("spec/support/matchers/rambo_matchers.rb")
7
+ File.join(SPEC_DIR_ROOT, "support/matchers/rambo_matchers.rb")
8
8
  }
9
9
 
10
10
  subject { described_class.new(template_path: template_path, file_path: file_path) }
@@ -13,7 +13,7 @@ RSpec.describe Rambo::RSpec::SpecFile do
13
13
  end
14
14
 
15
15
  context "file with examples" do
16
- let(:raml_file) { File.expand_path("../../../support/foobar.raml", __FILE__) }
16
+ let(:raml_file) { File.join(SPEC_DIR_ROOT, "support/foobar.raml") }
17
17
 
18
18
  describe "#initialize" do
19
19
  it "assigns @raml" do
@@ -40,7 +40,7 @@ RSpec.describe Rambo::RSpec::SpecFile do
40
40
 
41
41
  context "file with schema" do
42
42
  let(:raml_file) do
43
- File.expand_path("../../../../features/support/examples/raml/basic_raml_with_schema.raml", __FILE__)
43
+ File.join(RAMBO_ROOT, "../features/support/examples/raml/basic_raml_with_schema.raml")
44
44
  end
45
45
 
46
46
  describe "#initialize" do
@@ -0,0 +1,55 @@
1
+ RSpec.describe Rambo do
2
+ let(:file_contents) do
3
+ <<-EOF
4
+ raml: doc/raml/foobar.raml
5
+ rails: false
6
+ EOF
7
+ end
8
+
9
+ describe ".generate_contract_tests!" do
10
+ let(:valid_file) { File.join(SPEC_DIR_ROOT, "support/foobar.raml") }
11
+ let(:default_options) { { rails: true } }
12
+
13
+ before(:each) do
14
+ allow(Dir).to receive(:foreach).and_return(valid_file)
15
+ end
16
+
17
+ context "in all cases" do
18
+ it "generates documents" do
19
+ expect(Rambo::DocumentGenerator).to receive(:generate!).with(valid_file, default_options)
20
+ Rambo.generate_contract_tests!(valid_file, default_options)
21
+ end
22
+ end
23
+
24
+ context "when there is a .rambo.yml file" do
25
+ before(:each) do
26
+ allow(Rambo::DocumentGenerator).to receive(:generate!)
27
+
28
+ allow(File)
29
+ .to receive(:read)
30
+ .with(File.expand_path(".rambo.yml"))
31
+ .and_return(file_contents)
32
+ end
33
+
34
+ it "reads from the file" do
35
+ expect(File).to receive(:read).with(File.expand_path(".rambo.yml"))
36
+ Rambo.generate_contract_tests!
37
+ end
38
+
39
+ it "sets the RAML file to the one from the file" do
40
+ expect(Rambo::DocumentGenerator)
41
+ .to receive(:generate!)
42
+ .with(File.expand_path("doc/raml/foobar.raml"), { "raml" => File.expand_path("doc/raml/foobar.raml"), "rails" => false })
43
+
44
+ Rambo.generate_contract_tests!
45
+ end
46
+ end
47
+
48
+ context "when there is no .rambo.yml file" do
49
+ it "uses default options" do
50
+ expect(Rambo::DocumentGenerator).to receive(:generate!).with(valid_file, default_options)
51
+ Rambo.generate_contract_tests!
52
+ end
53
+ end
54
+ end
55
+ end
data/spec/spec_helper.rb CHANGED
@@ -10,10 +10,10 @@ require "raml-rb"
10
10
  require "json_test_data"
11
11
  require "fileutils"
12
12
 
13
- lib = File.expand_path("../../lib", __FILE__)
14
13
  SPEC_DIR_ROOT = File.expand_path("../", __FILE__)
15
-
16
- Dir.foreach("#{lib}") {|f| require f if f.match(/.*\.rb\z/) }
14
+ RAMBO_ROOT = File.expand_path("../../lib", __FILE__)
15
+ lib = File.expand_path(File.join(RAMBO_ROOT, "**/*.rb"))
16
+ Dir[lib].each {|f| require f }
17
17
 
18
18
  RSpec.configure do |c|
19
19
  c.disable_monkey_patching!
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.1.0
4
+ version: 0.2.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-06-07 00:00:00.000000000 Z
11
+ date: 2016-06-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -38,20 +38,6 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: 0.0.6
41
- - !ruby/object:Gem::Dependency
42
- name: rack-test
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: '0.6'
48
- type: :runtime
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: '0.6'
55
41
  - !ruby/object:Gem::Dependency
56
42
  name: colorize
57
43
  requirement: !ruby/object:Gem::Requirement
@@ -72,14 +58,20 @@ dependencies:
72
58
  requirements:
73
59
  - - "~>"
74
60
  - !ruby/object:Gem::Version
75
- version: '1.0'
61
+ version: '1.1'
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: 1.1.1
76
65
  type: :runtime
77
66
  prerelease: false
78
67
  version_requirements: !ruby/object:Gem::Requirement
79
68
  requirements:
80
69
  - - "~>"
81
70
  - !ruby/object:Gem::Version
82
- version: '1.0'
71
+ version: '1.1'
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: 1.1.1
83
75
  - !ruby/object:Gem::Dependency
84
76
  name: json-schema
85
77
  requirement: !ruby/object:Gem::Requirement
@@ -95,47 +87,47 @@ dependencies:
95
87
  - !ruby/object:Gem::Version
96
88
  version: '2.6'
97
89
  - !ruby/object:Gem::Dependency
98
- name: cucumber
90
+ name: rake
99
91
  requirement: !ruby/object:Gem::Requirement
100
92
  requirements:
101
93
  - - "~>"
102
94
  - !ruby/object:Gem::Version
103
- version: '2.1'
104
- type: :development
95
+ version: '11.0'
96
+ type: :runtime
105
97
  prerelease: false
106
98
  version_requirements: !ruby/object:Gem::Requirement
107
99
  requirements:
108
100
  - - "~>"
109
101
  - !ruby/object:Gem::Version
110
- version: '2.1'
102
+ version: '11.0'
111
103
  - !ruby/object:Gem::Dependency
112
- name: json
104
+ name: cucumber
113
105
  requirement: !ruby/object:Gem::Requirement
114
106
  requirements:
115
107
  - - "~>"
116
108
  - !ruby/object:Gem::Version
117
- version: '1.7'
109
+ version: '2.1'
118
110
  type: :development
119
111
  prerelease: false
120
112
  version_requirements: !ruby/object:Gem::Requirement
121
113
  requirements:
122
114
  - - "~>"
123
115
  - !ruby/object:Gem::Version
124
- version: '1.7'
116
+ version: '2.1'
125
117
  - !ruby/object:Gem::Dependency
126
- name: rake
118
+ name: json
127
119
  requirement: !ruby/object:Gem::Requirement
128
120
  requirements:
129
121
  - - "~>"
130
122
  - !ruby/object:Gem::Version
131
- version: '11.0'
123
+ version: '1.7'
132
124
  type: :development
133
125
  prerelease: false
134
126
  version_requirements: !ruby/object:Gem::Requirement
135
127
  requirements:
136
128
  - - "~>"
137
129
  - !ruby/object:Gem::Version
138
- version: '11.0'
130
+ version: '1.7'
139
131
  - !ruby/object:Gem::Dependency
140
132
  name: coveralls
141
133
  requirement: !ruby/object:Gem::Requirement
@@ -208,38 +200,43 @@ files:
208
200
  - features/support/examples/rspec/spec_helper_only_rack_test.rb.example
209
201
  - features/support/examples/rspec/spec_helper_rack_test_added.rb.example
210
202
  - features/support/foobar.raml
211
- - lib/cli.rb
212
- - lib/document_generator.rb
213
- - lib/raml_models.rb
214
- - lib/raml_models/api.rb
215
- - lib/raml_models/body.rb
216
- - lib/raml_models/headers.rb
217
- - lib/raml_models/method.rb
218
- - lib/raml_models/resource.rb
219
- - lib/raml_models/response.rb
220
- - lib/rspec.rb
221
- - lib/rspec/example_group.rb
222
- - lib/rspec/examples.rb
223
- - lib/rspec/helper_file.rb
224
- - lib/rspec/spec_file.rb
225
- - lib/rspec/templates/example_group_template.erb
226
- - lib/rspec/templates/matcher_file_template.erb
227
- - lib/rspec/templates/rambo_helper_file_template.erb
228
- - lib/rspec/templates/spec_file_template.erb
203
+ - lib/rambo.rb
204
+ - lib/rambo/cli.rb
205
+ - lib/rambo/document_generator.rb
206
+ - lib/rambo/rake.rb
207
+ - lib/rambo/rake/task.rb
208
+ - lib/rambo/raml_models.rb
209
+ - lib/rambo/raml_models/api.rb
210
+ - lib/rambo/raml_models/body.rb
211
+ - lib/rambo/raml_models/headers.rb
212
+ - lib/rambo/raml_models/method.rb
213
+ - lib/rambo/raml_models/resource.rb
214
+ - lib/rambo/raml_models/response.rb
215
+ - lib/rambo/rspec.rb
216
+ - lib/rambo/rspec/example_group.rb
217
+ - lib/rambo/rspec/examples.rb
218
+ - lib/rambo/rspec/helper_file.rb
219
+ - lib/rambo/rspec/spec_file.rb
220
+ - lib/rambo/rspec/templates/example_group_template.erb
221
+ - lib/rambo/rspec/templates/matcher_file_template.erb
222
+ - lib/rambo/rspec/templates/rambo_helper_file_template.erb
223
+ - lib/rambo/rspec/templates/spec_file_template.erb
229
224
  - lib/version.rb
230
225
  - rambo_ruby.gemspec
231
- - spec/lib/cli_spec.rb
232
- - spec/lib/document_generator_spec.rb
233
- - spec/lib/raml_models/api_spec.rb
234
- - spec/lib/raml_models/body_spec.rb
235
- - spec/lib/raml_models/headers_spec.rb
236
- - spec/lib/raml_models/method_spec.rb
237
- - spec/lib/raml_models/resource_spec.rb
238
- - spec/lib/raml_models/response_spec.rb
239
- - spec/lib/rspec/example_group_spec.rb
240
- - spec/lib/rspec/examples_spec.rb
241
- - spec/lib/rspec/helper_file_spec.rb
242
- - spec/lib/rspec/spec_file_spec.rb
226
+ - spec/lib/rambo/cli_spec.rb
227
+ - spec/lib/rambo/document_generator_spec.rb
228
+ - spec/lib/rambo/rake/task_spec.rb
229
+ - spec/lib/rambo/raml_models/api_spec.rb
230
+ - spec/lib/rambo/raml_models/body_spec.rb
231
+ - spec/lib/rambo/raml_models/headers_spec.rb
232
+ - spec/lib/rambo/raml_models/method_spec.rb
233
+ - spec/lib/rambo/raml_models/resource_spec.rb
234
+ - spec/lib/rambo/raml_models/response_spec.rb
235
+ - spec/lib/rambo/rspec/example_group_spec.rb
236
+ - spec/lib/rambo/rspec/examples_spec.rb
237
+ - spec/lib/rambo/rspec/helper_file_spec.rb
238
+ - spec/lib/rambo/rspec/spec_file_spec.rb
239
+ - spec/lib/rambo_spec.rb
243
240
  - spec/spec_helper.rb
244
241
  - spec/support/basic_raml_with_post_route.raml
245
242
  - spec/support/foo.raml
@@ -268,10 +265,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
268
265
  version: '0'
269
266
  requirements: []
270
267
  rubyforge_project:
271
- rubygems_version: 2.5.1
268
+ rubygems_version: 2.4.6
272
269
  signing_key:
273
270
  specification_version: 4
274
- summary: rambo_ruby-0.1.0
271
+ summary: rambo_ruby-0.2.0
275
272
  test_files:
276
273
  - features/create_files.feature
277
274
  - features/error_modes.feature
@@ -300,18 +297,20 @@ test_files:
300
297
  - features/support/examples/rspec/spec_helper_only_rack_test.rb.example
301
298
  - features/support/examples/rspec/spec_helper_rack_test_added.rb.example
302
299
  - features/support/foobar.raml
303
- - spec/lib/cli_spec.rb
304
- - spec/lib/document_generator_spec.rb
305
- - spec/lib/raml_models/api_spec.rb
306
- - spec/lib/raml_models/body_spec.rb
307
- - spec/lib/raml_models/headers_spec.rb
308
- - spec/lib/raml_models/method_spec.rb
309
- - spec/lib/raml_models/resource_spec.rb
310
- - spec/lib/raml_models/response_spec.rb
311
- - spec/lib/rspec/example_group_spec.rb
312
- - spec/lib/rspec/examples_spec.rb
313
- - spec/lib/rspec/helper_file_spec.rb
314
- - spec/lib/rspec/spec_file_spec.rb
300
+ - spec/lib/rambo/cli_spec.rb
301
+ - spec/lib/rambo/document_generator_spec.rb
302
+ - spec/lib/rambo/rake/task_spec.rb
303
+ - spec/lib/rambo/raml_models/api_spec.rb
304
+ - spec/lib/rambo/raml_models/body_spec.rb
305
+ - spec/lib/rambo/raml_models/headers_spec.rb
306
+ - spec/lib/rambo/raml_models/method_spec.rb
307
+ - spec/lib/rambo/raml_models/resource_spec.rb
308
+ - spec/lib/rambo/raml_models/response_spec.rb
309
+ - spec/lib/rambo/rspec/example_group_spec.rb
310
+ - spec/lib/rambo/rspec/examples_spec.rb
311
+ - spec/lib/rambo/rspec/helper_file_spec.rb
312
+ - spec/lib/rambo/rspec/spec_file_spec.rb
313
+ - spec/lib/rambo_spec.rb
315
314
  - spec/spec_helper.rb
316
315
  - spec/support/basic_raml_with_post_route.raml
317
316
  - spec/support/foo.raml
@@ -319,3 +318,4 @@ test_files:
319
318
  - spec/support/foobar.yml
320
319
  - spec/support/multiple_resources.raml
321
320
  - spec/support/post_with_request_headers.raml
321
+ has_rdoc: