Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Reorganized shared examples and helpers.

  • Loading branch information...
commit b3c4b58c179efbd9a6c0d4007adecced94b5c9ce 1 parent e3af6c3
@dblock dblock authored
View
6 spec/grape/api_spec.rb
@@ -1,5 +1,5 @@
require 'spec_helper'
-require 'shared_versioning_examples'
+require 'shared/versioning_examples'
describe Grape::API do
subject { Class.new(Grape::API) }
@@ -448,7 +448,7 @@ def call(env)
subject.get(:hello){ "Hello, world."}
get '/hello'
last_response.status.should eql 401
- get '/hello', {}, 'HTTP_AUTHORIZATION' => encode_basic('allow','whatever')
+ get '/hello', {}, 'HTTP_AUTHORIZATION' => encode_basic_auth('allow','whatever')
last_response.status.should eql 200
end
@@ -476,7 +476,7 @@ def call(env)
subject.get(:hello){ "Hello, world."}
get '/hello'
last_response.status.should eql 401
- get '/hello', {}, 'HTTP_AUTHORIZATION' => encode_basic('allow','whatever')
+ get '/hello', {}, 'HTTP_AUTHORIZATION' => encode_basic_auth('allow','whatever')
last_response.status.should eql 200
end
end
View
4 spec/grape/middleware/auth/basic_spec.rb
@@ -20,12 +20,12 @@ def app
end
it 'should authenticate if given valid creds' do
- get '/whatever', {}, 'HTTP_AUTHORIZATION' => encode_basic('admin','admin')
+ get '/whatever', {}, 'HTTP_AUTHORIZATION' => encode_basic_auth('admin','admin')
last_response.status.should == 200
end
it 'should throw a 401 is wrong auth is given' do
- get '/whatever', {}, 'HTTP_AUTHORIZATION' => encode_basic('admin','wrong')
+ get '/whatever', {}, 'HTTP_AUTHORIZATION' => encode_basic_auth('admin','wrong')
last_response.status.should == 401
end
end
View
0  spec/support/shared_versioning_examples.rb → spec/shared/versioning_examples.rb
File renamed without changes
View
36 spec/spec_helper.rb
@@ -14,9 +14,6 @@
require 'pry'
require 'base64'
-def encode_basic(username, password)
- "Basic " + Base64.encode64("#{username}:#{password}")
-end
require 'hashie/hash'
@@ -24,36 +21,7 @@ def encode_basic(username, password)
config.include Rack::Test::Methods
end
-# Versioning
-
-# Returns the path with options[:version] prefixed if options[:using] is :path.
-# Returns normal path otherwise.
-def versioned_path(options = {})
- case options[:using]
- when :path
- File.join('/', options[:prefix] || '', options[:version], options[:path])
- when :header
- File.join('/', options[:prefix] || '', options[:path])
- else
- raise ArgumentError.new("unknown versioning strategy: #{options[:using]}")
- end
-end
-
-def versioned_headers(options)
- case options[:using]
- when :path
- {} # no-op
- when :header
- {
- 'HTTP_ACCEPT' => "application/vnd.#{options[:vendor]}-#{options[:version]}+#{options[:format]}"
- }
- else
- raise ArgumentError.new("unknown versioning strategy: #{options[:using]}")
- end
+Dir["#{File.dirname(__FILE__)}/support/*.rb"].each do |file|
+ require file
end
-def versioned_get(path, version_name, version_options = {})
- path = versioned_path(version_options.merge(:version => version_name, :path => path))
- headers = versioned_headers(version_options.merge(:version => version_name))
- get path, {}, headers
-end
View
4 spec/support/basic_auth_encode_helpers.rb
@@ -0,0 +1,4 @@
+def encode_basic_auth(username, password)
+ "Basic " + Base64.encode64("#{username}:#{password}")
+end
+
View
34 spec/support/versioned_helpers.rb
@@ -0,0 +1,34 @@
+# Versioning
+
+# Returns the path with options[:version] prefixed if options[:using] is :path.
+# Returns normal path otherwise.
+def versioned_path(options = {})
+ case options[:using]
+ when :path
+ File.join('/', options[:prefix] || '', options[:version], options[:path])
+ when :header
+ File.join('/', options[:prefix] || '', options[:path])
+ else
+ raise ArgumentError.new("unknown versioning strategy: #{options[:using]}")
+ end
+end
+
+def versioned_headers(options)
+ case options[:using]
+ when :path
+ {} # no-op
+ when :header
+ {
+ 'HTTP_ACCEPT' => "application/vnd.#{options[:vendor]}-#{options[:version]}+#{options[:format]}"
+ }
+ else
+ raise ArgumentError.new("unknown versioning strategy: #{options[:using]}")
+ end
+end
+
+def versioned_get(path, version_name, version_options = {})
+ path = versioned_path(version_options.merge(:version => version_name, :path => path))
+ headers = versioned_headers(version_options.merge(:version => version_name))
+ get path, {}, headers
+end
+
Please sign in to comment.
Something went wrong with that request. Please try again.