Skip to content

Commit

Permalink
Rspec helper.
Browse files Browse the repository at this point in the history
  • Loading branch information
oesmith committed Oct 8, 2012
1 parent 71e314c commit f2f4f2e
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 16 deletions.
26 changes: 26 additions & 0 deletions lib/billy/rspec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
require 'rspec'
require 'billy'

$billy_proxy = Billy::Proxy.new
$billy_proxy.start

module Billy
def self.proxy
$billy_proxy
end

module RspecHelper
def proxy
Billy.proxy
end
end
end

RSpec.configure do |config|
config.include(Billy::RspecHelper)

config.after(:each) do
proxy.reset
end
end

23 changes: 7 additions & 16 deletions spec/request/proxy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,59 +25,50 @@

shared_examples_for 'a request stub' do
it 'should stub GET requests' do
@proxy.stub("#{url}/foo").
proxy.stub("#{url}/foo").
and_return(200, {}, 'hello, GET!')
http.get('/foo').body.should == 'hello, GET!'
end

it 'should stub POST requests' do
@proxy.stub("#{url}/bar", :method => :post).
proxy.stub("#{url}/bar", :method => :post).
and_return(200, {}, 'hello, POST!')
http.post('/bar', :foo => :bar).body.should == 'hello, POST!'
end

it 'should stub PUT requests' do
@proxy.stub("#{url}/baz", :method => :put).
proxy.stub("#{url}/baz", :method => :put).
and_return(200, {}, 'hello, PUT!')
http.put('/baz', :foo => :bar).body.should == 'hello, PUT!'
end

it 'should stub HEAD requests' do
@proxy.stub("#{url}/bap", :method => :head).
proxy.stub("#{url}/bap", :method => :head).
and_return(200, {'HTTP-X-Hello' => 'hello, HEAD!'}, nil)
http.head('/bap').headers['http_x_hello'] == 'hello, HEAD!'
end

it 'should stub DELETE requests' do
@proxy.stub("#{url}/bam", :method => :delete).
proxy.stub("#{url}/bam", :method => :delete).
and_return(200, {}, 'hello, DELETE!')
http.delete('/bam').body.should == 'hello, DELETE!'
end
end

describe Billy::Proxy do

before :all do
@proxy = Billy::Proxy.new
@proxy.start
end

before do
@http = Faraday.new @http_url,
:proxy => { :uri => @proxy.url },
:proxy => { :uri => proxy.url },
:keepalive => false,
:timeout => 0.5
@https = Faraday.new @https_url,
:ssl => { :verify => false },
:proxy => { :uri => @proxy.url },
:proxy => { :uri => proxy.url },
:keepalive => false,
:timeout => 0.5
end

after do
@proxy.reset
end

context 'proxying' do

context 'HTTP' do
Expand Down
2 changes: 2 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
Dir[File.expand_path("../support/**/*.rb", __FILE__)].each {|f| require f}

require 'billy/rspec'

RSpec.configure do |config|
config.treat_symbols_as_metadata_keys_with_true_values = true
config.run_all_when_everything_filtered = true
Expand Down

0 comments on commit f2f4f2e

Please sign in to comment.