-
Notifications
You must be signed in to change notification settings - Fork 3
/
test_helper.rb
43 lines (36 loc) · 1.24 KB
/
test_helper.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
require 'rubygems'
require 'test/unit'
require 'shoulda'
require 'rr'
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
$LOAD_PATH.unshift(File.dirname(__FILE__))
require 'trample'
class Test::Unit::TestCase
include RR::Adapters::TestUnit unless include?(RR::Adapters::TestUnit)
protected
def trample(config)
Trample::Cli.new.start(config)
end
def mock_get(url, opts={})
mock(RestClient).get(url, :cookies => opts[:cookies] || {}).times(opts[:times]) do
response = RestClient::Response.new("", stub!)
stub(response).cookies { opts[:return_cookies] || {} }
stub(response).code { 200 }
end
end
def mock_post(url, opts={})
mock(RestClient).post(url, opts[:payload],
:cookies => opts[:cookies] || {}).times(opts[:times]) do
response = RestClient::Response.new("", stub!)
stub(response).cookies { opts[:return_cookies] || {} }
stub(response).code { 200 }
end
end
def stub_get(url, opts = {})
stub(RestClient).get(url, :cookies => opts[:cookies] || {}).times(opts[:times]) do
response = RestClient::Response.new("", stub!)
stub(response).cookies { opts[:return_cookies] || {} }
stub(response).code { 200 }
end
end
end