require 'spec_helper' describe WebhookStopwatch::Client do let(:base_url) { "http://0.0.0.0:9292" } subject { WebhookStopwatch::Client.new(base_url) } before(:each) do stub_request(:post, /#{base_url}/) end describe "#start" do it "POSTs to start" do subject.start(123, 1000000) a_request(:post, "http://0.0.0.0:9292/messages/123/start"). with(:body => {"timestamp" => "1000000"}). should have_been_made end it "returns true" do subject.start(123, 1000000).should == true end context "all hell breaks loose" do before(:each) do stub_request(:post, /#{base_url}/).to_return(:status => 500) end it "returns false" do subject.start(123, 1000000).should == false end end end describe "#stop" do it "POSTs to stop" do subject.stop(123, 1000000) a_request(:post, "http://0.0.0.0:9292/messages/123/stop"). with(:body => {"timestamp" => "1000000"}). should have_been_made end it "returns true" do subject.stop(123, 1000000).should == true end context "all hell breaks loose" do before(:each) do stub_request(:post, /#{base_url}/).to_return(:status => 500) end it "returns false" do subject.stop(123, 1000000).should == false end end end end