rambo_ruby 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (78) hide show
  1. checksums.yaml +7 -0
  2. data/.rspec +2 -0
  3. data/.simplecov +7 -0
  4. data/.travis.yml +17 -0
  5. data/Gemfile +5 -0
  6. data/ISSUE_TEMPLATE.md +45 -0
  7. data/LICENSE +21 -0
  8. data/README.md +50 -0
  9. data/Rakefile +10 -0
  10. data/assets/logo.txt +5 -0
  11. data/bin/rambo +23 -0
  12. data/features/create_files.feature +16 -0
  13. data/features/error_modes.feature +13 -0
  14. data/features/generate_post_specs.feature +10 -0
  15. data/features/generate_simple_api_specs.feature +13 -0
  16. data/features/modify_spec_helper.feature +4 -0
  17. data/features/step_definitions/file_steps.rb +25 -0
  18. data/features/support/cucumber_helper.rb +13 -0
  19. data/features/support/env.rb +8 -0
  20. data/features/support/examples/json/basic_raml_with_example_response.json +16 -0
  21. data/features/support/examples/json/basic_raml_with_post_route_response.json +15 -0
  22. data/features/support/examples/json/basic_raml_with_schema_response.json +10 -0
  23. data/features/support/examples/raml/basic_raml_with_example.raml +30 -0
  24. data/features/support/examples/raml/basic_raml_with_post_route.raml +43 -0
  25. data/features/support/examples/raml/basic_raml_with_schema.raml +24 -0
  26. data/features/support/examples/raml/empty_raml.raml +5 -0
  27. data/features/support/examples/raml/multiple_routes.raml +15 -0
  28. data/features/support/examples/raml/post_with_request_headers.raml +45 -0
  29. data/features/support/examples/rspec/empty_spec.rb.example +5 -0
  30. data/features/support/examples/rspec/simple_spec_file_with_example.rb.example +31 -0
  31. data/features/support/examples/rspec/simple_spec_file_with_post_route.rb.example +35 -0
  32. data/features/support/examples/rspec/simple_spec_file_with_schema.rb.example +31 -0
  33. data/features/support/examples/rspec/spec_file_with_request_headers.rb.example +52 -0
  34. data/features/support/examples/rspec/spec_helper_json_added.rb.example +11 -0
  35. data/features/support/examples/rspec/spec_helper_only_json.rb.example +10 -0
  36. data/features/support/examples/rspec/spec_helper_only_rack_test.rb.example +9 -0
  37. data/features/support/examples/rspec/spec_helper_rack_test_added.rb.example +10 -0
  38. data/features/support/foobar.raml +30 -0
  39. data/lib/cli.rb +65 -0
  40. data/lib/document_generator.rb +49 -0
  41. data/lib/raml_models/api.rb +19 -0
  42. data/lib/raml_models/body.rb +33 -0
  43. data/lib/raml_models/headers.rb +21 -0
  44. data/lib/raml_models/method.rb +37 -0
  45. data/lib/raml_models/resource.rb +22 -0
  46. data/lib/raml_models/response.rb +19 -0
  47. data/lib/raml_models.rb +1 -0
  48. data/lib/rspec/example_group.rb +53 -0
  49. data/lib/rspec/examples.rb +32 -0
  50. data/lib/rspec/helper_file.rb +30 -0
  51. data/lib/rspec/spec_file.rb +31 -0
  52. data/lib/rspec/templates/example_group_template.erb +39 -0
  53. data/lib/rspec/templates/matcher_file_template.erb +8 -0
  54. data/lib/rspec/templates/rambo_helper_file_template.erb +3 -0
  55. data/lib/rspec/templates/spec_file_template.erb +15 -0
  56. data/lib/rspec.rb +1 -0
  57. data/lib/version.rb +9 -0
  58. data/rambo_ruby.gemspec +38 -0
  59. data/spec/lib/cli_spec.rb +71 -0
  60. data/spec/lib/document_generator_spec.rb +74 -0
  61. data/spec/lib/raml_models/api_spec.rb +23 -0
  62. data/spec/lib/raml_models/body_spec.rb +32 -0
  63. data/spec/lib/raml_models/headers_spec.rb +17 -0
  64. data/spec/lib/raml_models/method_spec.rb +32 -0
  65. data/spec/lib/raml_models/resource_spec.rb +30 -0
  66. data/spec/lib/raml_models/response_spec.rb +20 -0
  67. data/spec/lib/rspec/example_group_spec.rb +87 -0
  68. data/spec/lib/rspec/examples_spec.rb +38 -0
  69. data/spec/lib/rspec/helper_file_spec.rb +18 -0
  70. data/spec/lib/rspec/spec_file_spec.rb +58 -0
  71. data/spec/spec_helper.rb +26 -0
  72. data/spec/support/basic_raml_with_post_route.raml +43 -0
  73. data/spec/support/foo.raml +43 -0
  74. data/spec/support/foobar.raml +30 -0
  75. data/spec/support/foobar.yml +3 -0
  76. data/spec/support/multiple_resources.raml +56 -0
  77. data/spec/support/post_with_request_headers.raml +45 -0
  78. metadata +321 -0
@@ -0,0 +1,71 @@
1
+ RSpec.describe Rambo::CLI do
2
+ let(:io) { StringIO.new }
3
+ let(:stderr) { StringIO.new }
4
+ let(:opts) { { rails: true } }
5
+ let(:valid_file) { File.expand_path('../../support/foobar.raml', __FILE__) }
6
+
7
+ describe "run!" do
8
+ let(:cli) { Rambo::CLI.new(valid_file, opts, io, stderr) }
9
+
10
+ before(:each) do
11
+ allow_any_instance_of(Rambo::DocumentGenerator).to receive(:generate_rambo_helper!)
12
+ allow_any_instance_of(Rambo::DocumentGenerator).to receive(:generate_spec_file!)
13
+ allow_any_instance_of(Rambo::DocumentGenerator).to receive(:generate_matchers!)
14
+ allow_any_instance_of(Rambo::DocumentGenerator).to receive(:generate_matcher_dir!)
15
+ allow_any_instance_of(Rambo::DocumentGenerator).to receive(:generate_examples!)
16
+ allow_any_instance_of(Rambo::DocumentGenerator).to receive(:generate_spec_dir!)
17
+ end
18
+
19
+ it "creates a spec/contract directory" do
20
+ expect_any_instance_of(Rambo::DocumentGenerator).to receive(:generate_spec_dir!)
21
+ cli.run!
22
+ end
23
+
24
+ it "creates a spec/support/matchers directory" do
25
+ expect_any_instance_of(Rambo::DocumentGenerator).to receive(:generate_matchers!)
26
+ cli.run!
27
+ end
28
+
29
+ it "creates a rambo_helper file" do
30
+ allow(File).to receive(:exist?).with('spec/rambo_helper.rb').and_return(true)
31
+ expect_any_instance_of(Rambo::DocumentGenerator).to receive(:generate_rambo_helper!)
32
+ cli.run!
33
+ end
34
+
35
+ it "creates foobar_spec.rb" do
36
+ expect_any_instance_of(Rambo::DocumentGenerator).to receive(:generate_spec_file!)
37
+ cli.run!
38
+ end
39
+
40
+ it "creates the spec/support/examples directory" do
41
+ expect_any_instance_of(Rambo::DocumentGenerator).to receive(:generate_examples!)
42
+ cli.run!
43
+ end
44
+
45
+ context "when there is an error" do
46
+ it "prints the error messaage" do
47
+ allow_any_instance_of(Rambo::DocumentGenerator)
48
+ .to receive(:generate_spec_file!)
49
+ .and_raise NoMethodError, "Undefined method generate_spec_file!"
50
+
51
+ expect{ cli.run! }.to rescue(NoMethodError)
52
+ end
53
+ end
54
+ end
55
+
56
+ describe "validate!" do
57
+ context "with no file given" do
58
+ it "exits" do
59
+ expect{ Rambo::CLI.new(nil, io) }.to raise_error(SystemExit)
60
+ end
61
+ end
62
+
63
+ context "with the wrong file format" do
64
+ let(:invalid_file) { File.expand_path('../support/foobar.yml', __FILE__) }
65
+
66
+ it "exits" do
67
+ expect{ Rambo::CLI.new(invalid_file, io) }.to raise_error(SystemExit)
68
+ end
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,74 @@
1
+ RSpec.describe Rambo::DocumentGenerator do
2
+ let(:valid_file) { File.expand_path('../../support/foobar.raml', __FILE__) }
3
+ let(:options) { { rails: true } }
4
+ let(:generator) { Rambo::DocumentGenerator.new(valid_file, options) }
5
+
6
+ before(:each) do
7
+ allow_any_instance_of(Rambo::DocumentGenerator).to receive(:extract_raml)
8
+ end
9
+
10
+ describe "#generate_spec_dir!" do
11
+ it "generates the spec/contract directory" do
12
+ expect(FileUtils).to receive(:mkdir_p).with("spec/contract/output")
13
+ generator.generate_spec_dir!
14
+ end
15
+ end
16
+
17
+ describe "#generate_rambo_helper!" do
18
+ it "generates the rambo_helper file" do
19
+ aggregate_failures do
20
+ expect_any_instance_of(Rambo::RSpec::HelperFile)
21
+ .to receive(:initialize)
22
+ .with({
23
+ :template_path => File.expand_path("lib/rspec/templates/rambo_helper_file_template.erb"),
24
+ :file_path => "spec/rambo_helper.rb"
25
+ })
26
+ expect_any_instance_of(Rambo::RSpec::HelperFile).to receive(:generate)
27
+ end
28
+
29
+ generator.generate_rambo_helper!
30
+ end
31
+ end
32
+
33
+ describe "#generate_spec_file!" do
34
+ before(:each) do
35
+ allow(File).to receive(:open)
36
+ end
37
+
38
+ it "generates foobar_spec.rb" do
39
+ allow_any_instance_of(Rambo::RSpec::SpecFile).to receive(:render).and_return("foo")
40
+ expect(File).to receive(:write).with("spec/contract/foobar_spec.rb", "foo")
41
+ generator.generate_spec_file!
42
+ end
43
+ end
44
+
45
+ describe "#generate_matcher_dir!" do
46
+ it "creates a spec/support/matchers directory" do
47
+ expect(FileUtils).to receive(:mkdir_p).with("spec/support/matchers")
48
+ generator.generate_matcher_dir!
49
+ end
50
+ end
51
+
52
+ describe "#generate_matchers!" do
53
+ it "adds a matcher file" do
54
+ aggregate_failures do
55
+ expect_any_instance_of(Rambo::RSpec::HelperFile)
56
+ .to receive(:initialize)
57
+ .with(
58
+ template_path: File.expand_path("lib/rspec/templates/matcher_file_template.erb"),
59
+ file_path: "spec/support/matchers/rambo_matchers.rb"
60
+ )
61
+ expect_any_instance_of(Rambo::RSpec::HelperFile).to receive(:generate)
62
+ end
63
+
64
+ generator.generate_matchers!
65
+ end
66
+ end
67
+
68
+ describe "#generate_examples!" do
69
+ it "creates the directory" do
70
+ expect(FileUtils).to receive(:mkdir_p).with("spec/support/examples")
71
+ generator.generate_examples!
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,23 @@
1
+ RSpec.describe Rambo::RamlModels::Api do
2
+ let(:raml_file) { File.expand_path("../../../support/multiple_resources.raml", __FILE__) }
3
+ let(:raml) { Raml::Parser.parse_file(raml_file) }
4
+
5
+ subject { described_class.new(raml) }
6
+
7
+ describe "#resources" do
8
+ it "has the right number of resources" do
9
+ expect(subject.resources.count).to eql 2
10
+ end
11
+
12
+ it "returns an array of Resource objects" do
13
+ all_are_resources = subject.resources.all? {|resource| resource.is_a?(Rambo::RamlModels::Resource) }
14
+ expect(all_are_resources).to be true
15
+ end
16
+ end
17
+
18
+ describe "#title" do
19
+ it "returns the API title from the RAML doc" do
20
+ expect(subject.title).to eql raml.title
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,32 @@
1
+ RSpec.describe Rambo::RamlModels::Body do
2
+ let(:raml) { Raml::Parser.parse_file(raml_file) }
3
+ let(:body) { raml.resources.first.methods.first.responses.first.bodies.first }
4
+
5
+ subject { described_class.new(body) }
6
+
7
+ describe "#content_type" do
8
+ let(:raml_file) { File.expand_path("../../../support/foobar.raml", __FILE__) }
9
+
10
+ it "returns the content type" do
11
+ expect(subject.content_type).to eql body.content_type
12
+ end
13
+ end
14
+
15
+ describe "#example" do
16
+ context "when an example is given" do
17
+ let(:raml_file) { File.expand_path("../../../support/foobar.raml", __FILE__) }
18
+
19
+ it "returns an example" do
20
+ expect(subject.example).to eql body.example
21
+ end
22
+ end
23
+
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__) }
26
+
27
+ it "returns generated JSON data" do
28
+ expect(JSON.parse(subject.example)).to have_key "data"
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,17 @@
1
+ RSpec.describe Rambo::RamlModels::Headers do
2
+ let(:raml) { Raml::Parser.parse_file(raml_file) }
3
+ let(:raml_file) { File.expand_path("../../../support/post_with_request_headers.raml", __FILE__) }
4
+ let(:headers) { raml.resources.first.methods.first.headers }
5
+
6
+ subject { described_class.new(headers) }
7
+
8
+ describe "#pretty" do
9
+ let(:pretty) do
10
+ "{\n\t\"Content-Type\" => \"application/json\"\n}"
11
+ end
12
+
13
+ it "makes it pretty" do
14
+ expect(subject.pretty).to eql pretty
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,32 @@
1
+ RSpec.describe Rambo::RamlModels::Method do
2
+ let(:raml_file) { File.expand_path("../../../support/foo.raml", __FILE__) }
3
+ let(:raml) { Raml::Parser.parse_file(raml_file) }
4
+ let(:method) { raml.resources.first.methods.first }
5
+
6
+ subject { described_class.new(method) }
7
+
8
+ describe "#to_s" do
9
+ it "returns the method name" do
10
+ expect(subject.method).to eql method.method
11
+ end
12
+ end
13
+
14
+ describe "#description" do
15
+ it "returns the description" do
16
+ expect(subject.description).to eql method.description
17
+ end
18
+ end
19
+
20
+ describe "#request_body" do
21
+ it "returns a request body" do
22
+ expect(subject.request_body).to be_a Rambo::RamlModels::Body
23
+ end
24
+ end
25
+
26
+ describe "#responses" do
27
+ it "returns an array of Response objects" do
28
+ all_are_responses = subject.responses.all? {|resp| resp.is_a?(Rambo::RamlModels::Response) }
29
+ expect(all_are_responses).to be true
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,30 @@
1
+ RSpec.describe Rambo::RamlModels::Resource do
2
+ let(:raml_file) { File.expand_path("../../../support/foobar.raml", __FILE__) }
3
+ let(:raml) { Raml::Parser.parse_file(raml_file) }
4
+ let(:resource) { raml.resources.first }
5
+
6
+ subject { described_class.new(resource) }
7
+
8
+ describe "#to_s" do
9
+ it "returns the URI partial" do
10
+ expect(subject.to_s).to eql resource.uri_partial
11
+ end
12
+ end
13
+
14
+ describe "#uri_partial" do
15
+ it "returns the URI partial" do
16
+ expect(subject.uri_partial).to eql resource.uri_partial
17
+ end
18
+ end
19
+
20
+ describe "#http_methods" do
21
+ it "returns the correct methods" do
22
+ expect(subject.http_methods.count).to eql 1
23
+ end
24
+
25
+ it "returns an array of Method objects" do
26
+ all_are_methods = subject.http_methods.all? {|method| method.is_a?(Rambo::RamlModels::Method) }
27
+ expect(all_are_methods).to be true
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,20 @@
1
+ RSpec.describe Rambo::RamlModels::Response do
2
+ let(:raml_file) { File.expand_path("../../../support/foobar.raml", __FILE__) }
3
+ let(:raml) { Raml::Parser.parse_file(raml_file) }
4
+ let(:response) { raml.resources.first.methods.first.responses.first }
5
+
6
+ subject { described_class.new(response) }
7
+
8
+ describe "#status_code" do
9
+ it "returns the response status code" do
10
+ expect(subject.status_code).to eql response.code
11
+ end
12
+ end
13
+
14
+ describe "bodies" do
15
+ it "creates an array of Body objects" do
16
+ all_are_bodies = subject.bodies.all? {|body| body.is_a?(Rambo::RamlModels::Body) }
17
+ expect(all_are_bodies).to be true
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,87 @@
1
+ RSpec.describe Rambo::RSpec::ExampleGroup do
2
+ let(:raml_file) { File.expand_path("../../../support/foobar.raml", __FILE__) }
3
+ let(:raml) { Raml::Parser.parse_file(raml_file) }
4
+ let(:resource) { Rambo::RamlModels::Resource.new(raml.resources.first) }
5
+ let(:options) { { rails: true } }
6
+ subject { Rambo::RSpec::ExampleGroup.new(resource, options) }
7
+
8
+ before(:each) do
9
+ FileUtils.mkdir_p(File.expand_path("spec/support/examples"))
10
+ end
11
+
12
+ after(:each) do
13
+ FileUtils.rm_rf(File.expand_path("spec/support/examples"))
14
+ end
15
+
16
+ describe "#render" do
17
+ it "interpolates the correct values" do
18
+ aggregate_failures do
19
+ expect(subject.render).to include("let(:output_file) do")
20
+ expect(subject.render).to include("describe \"#{raml.resources.first.methods.first.method.upcase}\" do")
21
+ expect(subject.render).to include('describe "GET" do')
22
+ end
23
+ end
24
+
25
+ it "does not include a request body" do
26
+ expect(subject.render).not_to include("let(:request_body) do")
27
+ end
28
+
29
+ it "does not include headers" do
30
+ expect(subject.render).not_to include("let(:headers) do")
31
+ end
32
+
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__) }
35
+
36
+ it "creates a response schema object" do
37
+ aggregate_failures do
38
+ expect(subject.render).to include("let(:response_schema) do")
39
+ expect(subject.render).to include("expect(response.body).to match_schema response_schema")
40
+ end
41
+ end
42
+ end
43
+
44
+ context "when there is a response example but not a response schema" do
45
+ it "creates a response_body object" do
46
+ aggregate_failures do
47
+ expect(subject.render).to include("let(:response_body) do")
48
+ expect(subject.render).to include("expect(response.body).to eql response_body")
49
+ end
50
+ end
51
+ end
52
+
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__) }
55
+
56
+ it "adds a request body" do
57
+ expect(subject.render).to include("let(:request_body) do")
58
+ end
59
+
60
+ it "does not include headers" do
61
+ expect(subject.render).not_to include("let(:headers) do")
62
+ end
63
+ end
64
+
65
+ context "when the route has request headers" do
66
+ let(:raml_file) { File.expand_path("../../../support/post_with_request_headers.raml", __FILE__) }
67
+
68
+ it "adds headers" do
69
+ expect(subject.render).to include("let(:headers) do")
70
+ end
71
+ end
72
+
73
+ context "Rails app" do
74
+ it "uses response" do
75
+ expect(subject.render).to include("expect(response.body)")
76
+ end
77
+ end
78
+
79
+ context "non-Rails app" do
80
+ let(:options) { { rails: false } }
81
+
82
+ it "uses last_response" do
83
+ expect(subject.render).to include("expect(last_response.body)")
84
+ end
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,38 @@
1
+ RSpec.describe Rambo::RSpec::Examples do
2
+ let(:raml_file) { File.expand_path("../../../support/foobar.raml", __FILE__) }
3
+ let(:raw_raml) { Raml::Parser.parse_file(raml_file) }
4
+ let(:options) { { rails: true } }
5
+ let(:raml) { Rambo::RamlModels::Api.new(raw_raml) }
6
+
7
+ subject { Rambo::RSpec::Examples.new(raml, options) }
8
+
9
+ before(:each) do
10
+ FileUtils.mkdir_p(File.expand_path("spec/support/examples"))
11
+ end
12
+
13
+ after(:each) do
14
+ FileUtils.rm_rf(File.expand_path("spec/support/examples"))
15
+ end
16
+
17
+ describe "#generate!" do
18
+ it "calls render on each group" do
19
+ expect_any_instance_of(Rambo::RSpec::ExampleGroup).to receive(:render)
20
+ subject.generate!
21
+ end
22
+
23
+ it "returns an array of strings" do
24
+ aggregate_failures do
25
+ expect(subject.generate!).to be_a(Array)
26
+ expect(subject.generate!.first).to be_a(String)
27
+ end
28
+ end
29
+ end
30
+
31
+ describe "#compose" do
32
+ before(:each) { subject.generate! }
33
+
34
+ it "returns a string" do
35
+ expect(subject.compose).to be_a(String)
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,18 @@
1
+ RSpec.describe Rambo::RSpec::HelperFile do
2
+ let(:template_path) {
3
+ File.expand_path("lib/rspec/templates/matcher_file_template.erb")
4
+ }
5
+
6
+ let(:file_path) {
7
+ File.expand_path("spec/support/matchers/rambo_matchers.rb")
8
+ }
9
+
10
+ subject { described_class.new(template_path: template_path, file_path: file_path) }
11
+
12
+ describe "generate" do
13
+ it "writes the file" do
14
+ expect(File).to receive(:write).with(file_path, File.read(template_path))
15
+ subject.generate
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,58 @@
1
+ RSpec.describe Rambo::RSpec::SpecFile do
2
+ let(:raw_raml) { Raml::Parser.parse_file(raml_file) }
3
+ let(:options) { { rails: true } }
4
+ let(:raml) { Rambo::RamlModels::Api.new(raw_raml) }
5
+ let(:spec_file) { Rambo::RSpec::SpecFile.new(raw_raml, options) }
6
+
7
+ before(:each) do
8
+ FileUtils.mkdir_p(File.expand_path("spec/support/examples"))
9
+ end
10
+
11
+ after(:each) do
12
+ FileUtils.rm_rf(File.expand_path("spec/support/examples"))
13
+ end
14
+
15
+ context "file with examples" do
16
+ let(:raml_file) { File.expand_path("../../../support/foobar.raml", __FILE__) }
17
+
18
+ describe "#initialize" do
19
+ it "assigns @raml" do
20
+ expect(spec_file.raml).not_to be_nil
21
+ end
22
+
23
+ it "uses the correct schema" do
24
+ expect(spec_file.raml.schema).to eq raw_raml
25
+ end
26
+ end
27
+
28
+ describe "#template" do
29
+ it "is a string" do
30
+ expect(spec_file.template.is_a?(String)).to be true
31
+ end
32
+ end
33
+
34
+ describe "#render" do
35
+ it "interpolates the correct values" do
36
+ expect(spec_file.render).to include("e-BookMobile API")
37
+ end
38
+ end
39
+ end
40
+
41
+ context "file with schema" do
42
+ let(:raml_file) do
43
+ File.expand_path("../../../../features/support/examples/raml/basic_raml_with_schema.raml", __FILE__)
44
+ end
45
+
46
+ describe "#initialize" do
47
+ it "assigns @raml" do
48
+ expect(spec_file.raml).not_to be_nil
49
+ end
50
+ end
51
+
52
+ describe "#template" do
53
+ it "is a string" do
54
+ expect(spec_file.template.is_a?(String)).to be true
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,26 @@
1
+ require "coveralls"
2
+
3
+ Coveralls.wear! if ENV["COVERAGE"] == "true"
4
+
5
+ require "rspec"
6
+ require "rspec/core"
7
+ require "rspec/matchers"
8
+ require "rspec/expectations"
9
+ require "raml-rb"
10
+ require "json_test_data"
11
+ require "fileutils"
12
+
13
+ lib = File.expand_path("../../lib", __FILE__)
14
+ SPEC_DIR_ROOT = File.expand_path("../", __FILE__)
15
+
16
+ Dir.foreach("#{lib}") {|f| require f if f.match(/.*\.rb\z/) }
17
+
18
+ RSpec.configure do |c|
19
+ c.disable_monkey_patching!
20
+ c.order = :random
21
+
22
+ c.after(:each) do
23
+ File.delete("spec/rambo_helper.rb") rescue nil
24
+ FileUtils.rm_rf("spec/support/matchers") rescue nil
25
+ end
26
+ end
@@ -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,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,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,3 @@
1
+ title: e-BookMobile API
2
+ baseUri: http://api.e-bookmobile.com/{version}
3
+ version: v1