Skip to content

Commit 7a8508b

Browse files
author
Nathan Van der Auwera
committed
Added the first specs: a simple mounted API.
1 parent 6f478c2 commit 7a8508b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+101
-792
lines changed

Gemfile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,9 @@ group :development do
1616
gem "jquery-rails"
1717
gem "rails", "~> 3.2"
1818
gem "sqlite3"
19+
20+
gem "rack-test"
21+
22+
gem "rspec-rails"
23+
gem "rspec"
1924
end

Gemfile.lock

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ GEM
3030
multi_json (~> 1.0)
3131
arel (3.0.2)
3232
builder (3.0.0)
33+
diff-lcs (1.1.3)
3334
erubis (2.7.0)
3435
git (1.2.5)
3536
grape (0.2.1)
@@ -86,6 +87,19 @@ GEM
8687
rake (0.9.2.2)
8788
rdoc (3.12)
8889
json (~> 1.4)
90+
rspec (2.11.0)
91+
rspec-core (~> 2.11.0)
92+
rspec-expectations (~> 2.11.0)
93+
rspec-mocks (~> 2.11.0)
94+
rspec-core (2.11.1)
95+
rspec-expectations (2.11.1)
96+
diff-lcs (~> 1.1.3)
97+
rspec-mocks (2.11.1)
98+
rspec-rails (2.11.0)
99+
actionpack (>= 3.0)
100+
activesupport (>= 3.0)
101+
railties (>= 3.0)
102+
rspec (~> 2.11.0)
89103
shoulda (3.1.1)
90104
shoulda-context (~> 1.0)
91105
shoulda-matchers (~> 1.2)
@@ -112,7 +126,10 @@ DEPENDENCIES
112126
grape
113127
jeweler (~> 1.8.4)
114128
jquery-rails
129+
rack-test
115130
rails (~> 3.2)
116131
rdoc (~> 3.12)
132+
rspec
133+
rspec-rails
117134
shoulda
118135
sqlite3

Rakefile

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,9 @@ Jeweler::RubygemsDotOrgTasks.new
2929

3030
Bundler::GemHelper.install_tasks
3131

32-
require 'rake/testtask'
33-
34-
Rake::TestTask.new(:test) do |t|
35-
t.libs << 'lib'
36-
t.libs << 'test'
37-
t.pattern = 'test/**/*_test.rb'
38-
t.verbose = false
39-
end
32+
require 'rspec/core'
33+
require 'rspec/core/rake_task'
4034

35+
RSpec::Core::RakeTask.new(:spec)
4136

42-
task :default => :test
37+
task :default => :spec

lib/grape-swagger.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ def add_swagger_documentation(options={})
2121
private
2222

2323
def create_documentation_class
24+
2425
Class.new(Grape::API) do
2526
class << self
2627
def name

spec/grape-swagger_spec.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
require 'spec_helper'
2+
3+
describe Grape::API do
4+
5+
it "added combined-routes" do
6+
Grape::API.should respond_to :combined_routes
7+
end
8+
9+
it "added add_swagger_documentation" do
10+
Grape::API.should respond_to :add_swagger_documentation
11+
end
12+
13+
14+
15+
end

spec/simple_mounted_api_spec.rb

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
require 'spec_helper'
2+
3+
describe "a simple mounted api" do
4+
5+
class MountedApi < Grape::API
6+
desc 'this gets something'
7+
get '/something' do
8+
{:bla => 'something'}
9+
end
10+
end
11+
12+
class SimpleApi < Grape::API
13+
mount MountedApi
14+
add_swagger_documentation
15+
end
16+
17+
subject { SimpleApi.new }
18+
def app; subject end
19+
20+
it "retrieves swagger-documentation on /swagger_doc" do
21+
get '/swagger_doc'
22+
last_response.body.should == "{:apiVersion=>\"0.1\", :swaggerVersion=>\"1.1\", :basePath=>\"http://example.org\", :operations=>[], :apis=>[{:path=>\"/swagger_doc/mountedapi.{format}\"}, {:path=>\"/swagger_doc/swagger_doc.{format}\"}]}"
23+
end
24+
25+
it "retrieves the documentation for mounted-api" do
26+
Random.stub(:rand) { 0 }
27+
get '/swagger_doc/mountedapi'
28+
last_response.body.should == "{:apiVersion=>\"0.1\", :swaggerVersion=>\"1.1\", :basePath=>\"http://example.org\", :resourcePath=>\"\", :apis=>[{:path=>\"/something.{format}\", :operations=>[{:notes=>nil, :summary=>\"this gets something\", :nickname=>0, :httpMethod=>\"GET\", :parameters=>[]}]}]}"
29+
end
30+
end

spec/spec_helper.rb

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
$LOAD_PATH.unshift(File.dirname(__FILE__))
2+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), 'support'))
4+
5+
require 'grape'
6+
require 'grape-swagger'
7+
8+
require 'rubygems'
9+
require 'bundler'
10+
Bundler.setup :default, :test
11+
12+
13+
require 'rack/test'
14+
15+
# Load support files
16+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
17+
18+
RSpec.configure do |config|
19+
# Remove this line if you don't want RSpec's should and should_not
20+
# methods or matchers
21+
require 'rspec/expectations'
22+
config.include RSpec::Matchers
23+
24+
# == Mock Framework
25+
config.mock_with :rspec
26+
27+
config.include Rack::Test::Methods
28+
#config.include Rack::Test::Methods::Patch
29+
end

0 commit comments

Comments
 (0)