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
|
# frozen_string_literal: true
describe QA::Runtime::Feature do
let(:api_client) { double('QA::Runtime::API::Client') }
let(:request) { Struct.new(:url).new('http://api') }
let(:response_post) { Struct.new(:code).new(201) }
let(:response_get) { Struct.new(:code, :body).new(200, '[{ "name": "a-flag", "state": "on" }]') }
before do
allow(described_class).to receive(:api_client).and_return(api_client)
end
describe '.enable' do
it 'enables a feature flag' do
expect(QA::Runtime::API::Request)
.to receive(:new)
.with(api_client, "/features/a-flag")
.and_return(request)
expect(described_class)
.to receive(:post)
.with(request.url, { value: true })
.and_return(response_post)
subject.enable('a-flag')
end
end
describe '.enable_and_verify' do
it 'enables a feature flag' do
allow(described_class).to receive(:get).and_return(response_get)
expect(QA::Runtime::API::Request).to receive(:new)
.with(api_client, "/features/a-flag").and_return(request)
expect(described_class).to receive(:post)
.with(request.url, { value: true }).and_return(response_post)
expect(QA::Runtime::API::Request).to receive(:new)
.with(api_client, "/features").and_return(request)
subject.enable_and_verify('a-flag')
end
end
describe '.disable' do
it 'disables a feature flag' do
expect(QA::Runtime::API::Request)
.to receive(:new)
.with(api_client, "/features/a-flag")
.and_return(request)
expect(described_class)
.to receive(:post)
.with(request.url, { value: false })
.and_return(response_post)
subject.disable('a-flag')
end
end
describe '.disable_and_verify' do
it 'disables a feature flag' do
allow(described_class).to receive(:get)
.and_return(Struct.new(:code, :body).new(200, '[{ "name": "a-flag", "state": "off" }]'))
expect(QA::Runtime::API::Request).to receive(:new)
.with(api_client, "/features/a-flag").and_return(request)
expect(described_class).to receive(:post)
.with(request.url, { value: false }).and_return(response_post)
expect(QA::Runtime::API::Request).to receive(:new)
.with(api_client, "/features").and_return(request)
subject.disable_and_verify('a-flag')
end
end
describe '.enabled?' do
it 'returns a feature flag state' do
expect(QA::Runtime::API::Request)
.to receive(:new)
.with(api_client, "/features")
.and_return(request)
expect(described_class)
.to receive(:get)
.and_return(response_get)
expect(subject.enabled?('a-flag')).to be_truthy
end
end
end
|