# -*- coding: utf-8 -*- require 'spec_helper' describe Magellan::Cli::Messaging::Http do let(:cmd){ Magellan::Cli::Messaging::Http.new } let(:core){ double(:core) } before{ allow(cmd).to receive(:core).and_return(core) } let(:success_res){ double(:res, code: 200, body: "SUCCESS!\n") } let(:failure_res){ double(:res, code: 401, body: "NOT FOUND!\n") } describe :get do it "path only" do expect(core).to receive(:request).with("/foo", :get, nil, {}).and_return(success_res) cmd.get("/foo") end it "path only(401 error)" do expect(core).to receive(:request).with("/foo", :get, nil, {}).and_return(failure_res) cmd.get("/foo") end it "path and query string" do expect(core).to receive(:request).with("/foo?bar=baz", :get, nil, {}).and_return(success_res) cmd.get("/foo?bar=baz") end it "path and headers" do expect(core).to receive(:request).with("/foo", :get, nil, {"bar" => "baz"}).and_return(success_res) cmd.get("/foo", '{"bar":"baz"}') end let(:header_content){ YAML.load_file(File.expand_path("../http_headers.yml", __FILE__)) } it "path and headers yaml file" do expect(core).to receive(:request).with("/foo", :get, nil, header_content).and_return(success_res) cmd.get("/foo", File.expand_path("../http_headers.yml", __FILE__)) end it "path and headers json file" do expect(core).to receive(:request).with("/foo", :get, nil, header_content).and_return(success_res) cmd.get("/foo", File.expand_path("../http_headers.json", __FILE__)) end end end