/
client_spec.rb
67 lines (58 loc) · 2.02 KB
/
client_spec.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
require "spec_helper"
RSpec.describe Unleash do
it "has a version number" do
expect(Unleash::VERSION).not_to be nil
end
it "Uses custom http headers when initializing client" do
WebMock.stub_request(:post, "http://test-url//client/register")
.with(
headers: {
'Accept'=>'*/*',
'Content-Type'=>'application/json',
'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
'User-Agent'=>'Ruby',
'X-Api-Key'=>'123'
})
.to_return(status: 200, body: "", headers: {})
WebMock.stub_request(:post, "http://test-url//client/metrics").
with(
headers: {
'Accept'=>'*/*',
'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
'Content-Type'=>'application/json',
'User-Agent'=>'Ruby'
}).
to_return(status: 200, body: "", headers: {})
Unleash.configure do |config|
config.url = 'http://test-url/'
config.app_name = 'my-test-app'
config.instance_id = 'rspec/test'
config.custom_http_headers = {'X-API-KEY' => '123'}
end
unleash_client = Unleash::Client.new(
url: 'http://test-url/',
app_name: 'my-test-app',
instance_id: 'rspec/test',
custom_http_headers: {'X-API-KEY' => '123'}
)
expect(
a_request(:post, "http://test-url//client/register")
.with( headers: {'Content-Type': 'application/json'})
.with( headers: {'X-API-KEY': '123', 'Content-Type': 'application/json'})
).to have_been_made.once
expect(
a_request(:get, "http://test-url//client/features")
.with( headers: {'X-API-KEY': '123'})
).to have_been_made.once
# Test now sending of metrics
Unleash.reporter.send
expect(
a_request(:post, "http://test-url//client/metrics")
.with( headers: {'Content-Type': 'application/json'})
.with( headers: {'X-API-KEY': '123', 'Content-Type': 'application/json'})
).to have_been_made.once
end
it "does something useful" do
expect(false).to eq(false)
end
end