• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Unleash / unleash-client-ruby / 3639325325

pending completion
3639325325

push

github

sighphyre
bump version for release

2244 of 2432 relevant lines covered (92.27%)

27.48 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

95.35
/spec/unleash/bootstrap/handler_spec.rb
1
require 'unleash/bootstrap/handler'
1✔
2
require 'unleash/bootstrap/configuration'
1✔
3

4
RSpec.describe Unleash::Bootstrap::Handler do
1✔
5
  Unleash.configure do |config|
1✔
6
    config.url      = 'http://unleash-url/'
1✔
7
    config.app_name = 'my-test-app'
1✔
8
    config.instance_id = 'rspec/test'
1✔
9
    config.custom_http_headers = { 'X-API-KEY' => '123' }
1✔
10
  end
11

12
  it 'is marked as invalid when no bootstrap options are provided' do
1✔
13
    bootstrap_config = Unleash::Bootstrap::Configuration.new
1✔
14
    expect(bootstrap_config.valid?).to be(false)
1✔
15
  end
16

17
  it 'is marked as valid when at least one valid bootstrap option is provided' do
1✔
18
    bootstrap_config = Unleash::Bootstrap::Configuration.new({ 'data' => '' })
1✔
19
    expect(bootstrap_config.valid?).to be(true)
1✔
20
  end
21

22
  it 'resolves bootstrap toggle correctly from url provider' do
1✔
23
    expected_repsonse_data = '{
1✔
24
      "version": 1,
25
      "features": [
26
        {
27
          "name": "featureX",
28
          "enabled": true,
29
          "strategies": [{ "name": "default" }]
30
        }
31
      ]
32
    }'
33

34
    WebMock.stub_request(:get, "http://test-url/")
×
35
      .with(
×
36
        headers: {
37
          'Accept' => '*/*',
38
          'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
39
          'Content-Type' => 'application/json',
40
          'User-Agent' => 'Ruby'
41
        }
42
      )
43
      .to_return(status: 200, body: expected_repsonse_data, headers: {})
1✔
44

45
    url_provider_options = {
1✔
46
      'url' => 'http://test-url/',
47
      'url_headers' => {}
48
    }
49

50
    bootstrap_config = Unleash::Bootstrap::Configuration.new(url_provider_options)
1✔
51
    bootstrap_response = Unleash::Bootstrap::Handler.new(bootstrap_config).retrieve_toggles
1✔
52
    expect(JSON.parse(bootstrap_response)).to eq(JSON.parse(expected_repsonse_data))
1✔
53
  end
54

55
  it 'resolves bootstrap toggle correctly from file provider' do
1✔
56
    file_path = './spec/unleash/bootstrap-resources/features-v1.json'
1✔
57
    actual_file_contents = File.open(file_path).read
1✔
58

59
    file_provider_options = {
1✔
60
      'file_path' => file_path
61
    }
62

63
    bootstrap_config = Unleash::Bootstrap::Configuration.new(file_provider_options)
1✔
64
    bootstrap_response = Unleash::Bootstrap::Handler.new(bootstrap_config).retrieve_toggles
1✔
65

66
    expect(JSON.parse(bootstrap_response)).to eq(JSON.parse(actual_file_contents))
1✔
67
  end
68

69
  it 'resolves bootstrap toggle correctly from raw data' do
1✔
70
    expected_repsonse_data = '{
1✔
71
      "version": 1,
72
      "features": [
73
        {
74
          "name": "featureX",
75
          "enabled": true,
76
          "strategies": [{ "name": "default" }]
77
        }
78
      ]
79
    }'
80

81
    data_provider_options = {
1✔
82
      'data' => expected_repsonse_data
83
    }
84

85
    bootstrap_config = Unleash::Bootstrap::Configuration.new(data_provider_options)
1✔
86
    bootstrap_response = Unleash::Bootstrap::Handler.new(bootstrap_config).retrieve_toggles
1✔
87

88
    expect(JSON.parse(bootstrap_response)).to eq(JSON.parse(expected_repsonse_data))
1✔
89
  end
90

91
  it 'resolves bootstrap toggle correctly from lambda' do
1✔
92
    expected_repsonse_data = '{
1✔
93
      "version": 1,
94
      "features": [
95
        {
96
          "name": "featureX",
97
          "enabled": true,
98
          "strategies": [{ "name": "default" }]
99
        }
100
      ]
101
    }'
102

103
    data_provider_options = {
1✔
104
      'block' => -> { expected_repsonse_data }
1✔
105
    }
106

107
    bootstrap_config = Unleash::Bootstrap::Configuration.new(data_provider_options)
1✔
108
    bootstrap_response = Unleash::Bootstrap::Handler.new(bootstrap_config).retrieve_toggles
1✔
109

110
    expect(JSON.parse(bootstrap_response)).to eq(JSON.parse(expected_repsonse_data))
1✔
111
  end
112
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc