spec/flipper/adapters/http_spec.rb in flipper-1.0.0 vs spec/flipper/adapters/http_spec.rb in flipper-1.1.0

- old
+ new

@@ -82,20 +82,54 @@ 'Content-Type' => 'application/json', 'User-Agent' => "Flipper HTTP Adapter v#{Flipper::VERSION}", } stub_request(:get, "http://app.com/flipper/features/feature_panel") .with(headers: headers) - .to_return(status: 404, body: "", headers: {}) + .to_return(status: 404) adapter = described_class.new(url: 'http://app.com/flipper') adapter.get(flipper[:feature_panel]) end + it "sends framework versions" do + stub_const("Rails", double(version: "7.1.0")) + stub_const("Sinatra::VERSION", "3.1.0") + stub_const("Hanami::VERSION", "0.7.2") + + headers = { + "Client-Framework" => ["rails=7.1.0", "sinatra=3.1.0", "hanami=0.7.2"] + } + + stub_request(:get, "http://app.com/flipper/features/feature_panel") + .with(headers: headers) + .to_return(status: 404) + + adapter = described_class.new(url: 'http://app.com/flipper') + adapter.get(flipper[:feature_panel]) + end + + it "does not send undefined framework versions" do + stub_const("Rails", double(version: "7.1.0")) + stub_const("Sinatra::VERSION", "3.1.0") + + headers = { + "Client-Framework" => ["rails=7.1.0", "sinatra=3.1.0"] + } + + stub_request(:get, "http://app.com/flipper/features/feature_panel") + .with(headers: headers) + .to_return(status: 404) + + adapter = described_class.new(url: 'http://app.com/flipper') + adapter.get(flipper[:feature_panel]) + end + + describe "#get" do it "raises error when not successful response" do stub_request(:get, "http://app.com/flipper/features/feature_panel") - .to_return(status: 503, body: "", headers: {}) + .to_return(status: 503) adapter = described_class.new(url: 'http://app.com/flipper') expect { adapter.get(flipper[:feature_panel]) }.to raise_error(Flipper::Adapters::Http::Error) @@ -103,11 +137,11 @@ end describe "#get_multi" do it "raises error when not successful response" do stub_request(:get, "http://app.com/flipper/features?keys=feature_panel&exclude_gate_names=true") - .to_return(status: 503, body: "", headers: {}) + .to_return(status: 503) adapter = described_class.new(url: 'http://app.com/flipper') expect { adapter.get_multi([flipper[:feature_panel]]) }.to raise_error(Flipper::Adapters::Http::Error) @@ -115,11 +149,11 @@ end describe "#get_all" do it "raises error when not successful response" do stub_request(:get, "http://app.com/flipper/features?exclude_gate_names=true") - .to_return(status: 503, body: "", headers: {}) + .to_return(status: 503) adapter = described_class.new(url: 'http://app.com/flipper') expect { adapter.get_all }.to raise_error(Flipper::Adapters::Http::Error) @@ -127,10 +161,10 @@ end describe "#features" do it "raises error when not successful response" do stub_request(:get, "http://app.com/flipper/features?exclude_gate_names=true") - .to_return(status: 503, body: "", headers: {}) + .to_return(status: 503) adapter = described_class.new(url: 'http://app.com/flipper') expect { adapter.features }.to raise_error(Flipper::Adapters::Http::Error)