/
test_helper.rb
70 lines (53 loc) · 1.48 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
module TestHelper
def fixture_path(name)
"#{File.dirname(__FILE__)}/fixtures/#{name}"
end
def load_fixture(file)
IO.readlines(fixture_path(file))
end
def fixture_file(name)
File.new fixture_path(name)
end
end
module Net #:nodoc:
class HTTP #:nodoc:
extend TestHelper
RESPONSES = {}
def self.responses=(r)
RESPONSES.clear
r.each{|k,v| RESPONSES[k] = v}
end
alias :old_net_http_request :request
def request(req, body = nil, &block)
prot = use_ssl ? "https" : "http"
uri_cls = use_ssl ? URI::HTTPS : URI::HTTP
query = req.path.split('?',2)
opts = {:host => self.address,
:port => self.port, :path => query[0]}
opts[:query] = query[1] if query[1]
uri = uri_cls.build(opts)
raise ArgumentError.new("#{req.method} method to #{uri} not being handled in testing")
end
def connect
raise ArgumentError.new("connect not being handled in testing")
end
end
end
plugin_root = "#{ File.dirname(__FILE__) }/.."
require 'rubygems'
require 'test/spec'
require 'mocha'
module BlackbookExtensions
module TestHelper
class Credentials
attr_accessor :network, :config
def initialize(network)
self.network = network.to_s
self.config = YAML.load_file( File.join(File.dirname(__FILE__), "config/credentials.yml") )
end
def get
[ self.config[self.network]["username"], self.config[self.network]["password"] ]
end
end
end
end