Skip to content

Commit

Permalink
Request stub matching specs.
Browse files Browse the repository at this point in the history
  • Loading branch information
oesmith committed Oct 9, 2012
1 parent 7409e94 commit 3122fd3
Showing 1 changed file with 33 additions and 2 deletions.
35 changes: 33 additions & 2 deletions spec/lib/billy/proxy_request_stub_spec.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,40 @@
require 'spec_helper'

describe Billy::ProxyRequestStub do
let(:subject) { Billy::ProxyRequestStub.new('url') }
context '#matches?' do
it 'should match urls and methods' do
Billy::ProxyRequestStub.new('http://example.com').
matches?('GET', 'http://example.com').should be
Billy::ProxyRequestStub.new('http://example.com', :method => :get).
matches?('GET', 'http://example.com').should be
Billy::ProxyRequestStub.new('http://example.com', :method => :post).
matches?('GET', 'http://example.com').should_not be
Billy::ProxyRequestStub.new('http://example.com', :method => :post).
matches?('POST', 'http://example.com').should be
Billy::ProxyRequestStub.new('http://fooxample.com', :method => :post).
matches?('POST', 'http://example.com').should_not be
end

it 'should match regexps' do
Billy::ProxyRequestStub.new(/http:\/\/.+\.com/, :method => :post).
matches?('POST', 'http://example.com').should be
Billy::ProxyRequestStub.new(/http:\/\/.+\.co\.uk/, :method => :get).
matches?('GET', 'http://example.com').should_not be
end
end

context '#and_return + #call' do
let(:subject) { Billy::ProxyRequestStub.new('url') }

it 'should generate bare responses' do
subject.and_return :body => 'baz foo bar'
subject.call({}, {}, nil).should == [
200,
{},
'baz foo bar'
]
end

context 'responses' do
it 'should generate text responses' do
subject.and_return :text => 'foo bar baz'
subject.call({}, {}, nil).should == [
Expand Down

0 comments on commit 3122fd3

Please sign in to comment.