Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added ability to specify custom rack browser... #66

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/airborne.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
config.add_setting :base_url
config.add_setting :headers
config.add_setting :rack_app
config.add_setting :rack_browser
config.add_setting :requester_type
config.add_setting :requester_module
end
2 changes: 1 addition & 1 deletion lib/airborne/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def self.configure
def self.included(base)
if !Airborne.configuration.requester_module.nil?
base.send(:include, Airborne.configuration.requester_module)
elsif !Airborne.configuration.rack_app.nil?
elsif !Airborne.configuration.rack_app.nil? || !Airborne.configuration.rack_browser.nil?
base.send(:include, RackTestRequester)
else
base.send(:include, RestClientRequester)
Expand Down
3 changes: 2 additions & 1 deletion lib/airborne/rack_test_requester.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ def make_request(method, url, options = {})
headers = options[:headers] || {}
base_headers = Airborne.configuration.headers || {}
headers = base_headers.merge(headers)
browser = Rack::Test::Session.new(Rack::MockSession.new(Airborne.configuration.rack_app))
browser = Airborne.configuration.rack_browser
browser ||= Rack::Test::Session.new(Rack::MockSession.new(Airborne.configuration.rack_app))
headers.each { |name, value| browser.header(name, value) }
browser.send(method, url, options[:body] || {}, headers)
Rack::MockResponse.class_eval do
Expand Down
23 changes: 23 additions & 0 deletions spec/airborne/rack/rack_sinatra_browser_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
require 'json'
require 'sinatra'

class SampleApp < Sinatra::Application
before do
content_type 'application/json'
end

get '/' do
{ foo: 'bar' }.to_json
end
end

Airborne.configure do |config|
config.rack_browser = Rack::Test::Session.new(Rack::MockSession.new(SampleApp))
end

describe 'rack app via browser' do
it 'should allow requests against a sinatra app' do
get '/'
expect_json_types(foo: :string)
end
end