forked from piotrmurach/github
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathspec_helper.rb
More file actions
110 lines (88 loc) · 2.49 KB
/
spec_helper.rb
File metadata and controls
110 lines (88 loc) · 2.49 KB
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
require 'rubygems'
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
$LOAD_PATH.unshift(File.dirname(__FILE__))
require 'rspec'
require 'json'
require 'webmock/rspec'
require 'github_api'
if RUBY_VERSION > '1.9' and (ENV['COVERAGE'] || ENV['TRAVIS'])
require 'coverage_adapter'
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
SimpleCov::Formatter::HTMLFormatter,
Coveralls::SimpleCov::Formatter
]
SimpleCov.start 'github_api'
SimpleCov.coverage_dir 'coverage/rspec'
end
# Requires supporting files with custom matchers and macros, etc,
# in ./support/ and its subdirectories.
Dir["#{File.dirname(__FILE__)}/{support,shared}/**/*.rb"].each { |f| require f }
module Github
def reset!
instance_variables.each do |ivar|
instance_variable_set(ivar, nil)
end
end
end
RSpec.configure do |config|
config.include WebMock::API
config.order = :rand
config.color_enabled = true
config.treat_symbols_as_metadata_keys_with_true_values = true
config.before(:each) do
WebMock.reset!
end
config.after(:each) do
WebMock.reset!
end
end
def stub_get(path, endpoint = Github.endpoint.to_s)
stub_request(:get, endpoint + path)
end
def stub_post(path, endpoint = Github.endpoint.to_s)
stub_request(:post, endpoint + path)
end
def stub_patch(path, endpoint = Github.endpoint.to_s)
stub_request(:patch, endpoint + path)
end
def stub_put(path, endpoint = Github.endpoint.to_s)
stub_request(:put, endpoint + path)
end
def stub_delete(path, endpoint = Github.endpoint.to_s)
stub_request(:delete, endpoint + path)
end
def a_get(path, endpoint = Github.endpoint.to_s)
a_request(:get, endpoint + path)
end
def a_post(path, endpoint = Github.endpoint.to_s)
a_request(:post, endpoint + path)
end
def a_patch(path, endpoint = Github.endpoint.to_s)
a_request(:patch, endpoint + path)
end
def a_put(path, endpoint = Github.endpoint)
a_request(:put, endpoint + path)
end
def a_delete(path, endpoint = Github.endpoint)
a_request(:delete, endpoint + path)
end
def fixture_path
File.expand_path("../fixtures", __FILE__)
end
def fixture(file)
File.new(File.join(fixture_path, '/', file))
end
OAUTH_TOKEN = 'bafec72922f31fe86aacc8aca4261117f3bd62cf'
def reset_authentication_for(object)
[ 'user', 'repo', 'basic_auth', 'oauth_token', 'login', 'password' ].each do |item|
Github.send("#{item}=", nil)
object.send("#{item}=", nil)
end
end
class Hash
def except(*keys)
cpy = self.dup
keys.each { |key| cpy.delete(key) }
cpy
end
end