This repository has been archived by the owner on Dec 31, 2019. It is now read-only.
/
helper.rb
90 lines (74 loc) · 1.9 KB
/
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
require 'cloudprint'
require 'minitest/autorun'
require 'shoulda/context'
require 'mocha/mini_test'
class Minitest::Test
def new_client
CloudPrint::Client.new(refresh_token: "refresh_token")
end
def any_connection
CloudPrint::Connection.any_instance
end
def any_access_token
OAuth2::AccessToken.any_instance
end
def stub_access_token
mock_access_token.stub_everything
any_access_token.stubs(:refresh!).returns(mock_access_token)
end
def mock_access_token(token = 'token')
mock = mock('token')
mock.stubs(:token).returns(token)
mock.stubs(:expired?).returns(false)
mock
end
def mock_refresh_token
mock = mock("refresh_token")
mock.stubs(refresh_token: "random_refresh_token")
mock
end
def stub_http
mock = mock_http()
Net::HTTP.stubs(:new).returns(mock)
end
def stub_parsing_responses
CloudPrint::Connection.any_instance.stubs(:parse_response)
end
def mock_http
@mock_http ||= mock('http')
@mock_http.stub_everything
@mock_http
end
def mock_oauth_client
@oauth_client ||= mock('oauth_client')
end
def stub_oauth_client
CloudPrint::Client.any_instance.stubs(:oauth_client).returns(mock_oauth_client)
end
def fake_connection
@connection ||= mock('connection')
end
def stub_connection
CloudPrint::Client.any_instance.stubs(:connection).returns(fake_connection)
@connection.stub_everything
end
def fixture_file(filename)
File.join(File.dirname(__FILE__), 'fixtures', filename)
end
# Adapted from minitest's assert_raises
def assert_nothing_raised(msg = nil)
begin
yield
pass # count assertion
rescue Minitest::Skip, Minitest::Assertion
# don't count assertion
raise
rescue SignalException, SystemExit
raise
rescue Exception => e
flunk proc {
exception_details(e, "#{e} exception not expected")
}
end
end
end