Sha256: 3b8e2c02f8edf0e953f2990290da4a07dd18c9f28de40943e2b84f72632e11a1

Contents?: true

Size: 1.98 KB

Versions: 5

Compression:

Stored size: 1.98 KB

Contents

module Boty
  module Slack
    RSpec.describe URL do
      class Pseudo
        include URL
        url "http://example.org"

        def omg(parameters: {}, path: nil)
          parameterize parameters, path
        end
      end

      context "when included" do
        subject(:client_class) { Pseudo }

        it "injects the configuration method .url" do
          expect(client_class).to respond_to :url
        end

        it "injects the #parameterize" do
          expect(client_class.new.respond_to?(:parameterize, true)).to eq true
        end
      end

      describe ".get" do
        subject(:url) { described_class }

        it "sends the http request" do
          expect(Net::HTTP).to receive(:get).with(URI("http://example.org"))
          url.get "http://example.org"
        end

        it "parses the json response" do
          expect(Net::HTTP).to receive(:get).with(URI("http://example.org"))
            .and_return "{\"it\": \"works\"}"
          response = url.get "http://example.org"
          expect(response).to eq "it" => "works"
        end
      end

      describe "#parameterize" do
        subject(:client) { Pseudo.new }

        it "appends a path to the configured url" do
          url = client.send :parameterize, {}, path: "/omg"
          expect(url).to include "/omg?"
        end

        it "appends the api token" do
          url = client.send :parameterize, {}
          expect(url).to include "token=#{ENV['SLACK_BOT_API_TOKEN']}"
        end

        it "add extra parameters" do
          url = client.send :parameterize, really: "omg"
          expect(url).to include "really=omg"
        end

        it "uses the url configured by #url" do
          url = client.send :parameterize, {}
          expect(url).to include "http://example.org"
        end

        it "applies URI.encode to parameter values" do
          url = client.send :parameterize, really: "omg lol"
          expect(url).to include "really=omg%20lol"
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
boty-1.0.1 spec/boty/slack/url_spec.rb
boty-1.0.0 spec/boty/slack/url_spec.rb
boty-0.2.0 spec/boty/slack/url_spec.rb
boty-0.1.2 spec/boty/slack/url_spec.rb
boty-0.1.1 spec/boty/slack/url_spec.rb