module Boty module Slack RSpec.describe Users do def url_for(action) "https://slack.com/api/users.#{action}?" \ "token=#{ENV['SLACK_BOT_API_TOKEN']}" end subject(:users) { described_class.new } before do allow(Slack::URL).to receive(:get) .with(url_for(:info) + "&user=U123456").and_return( "ok" => true, "user" => { "id" => "U123456", "name" => "julian" } ) allow(Slack::URL).to receive(:get).with(url_for(:list)) .and_return( "ok" => true, "members" => [ { "id" => "U023BECGF", "name" => "bobby" }, { "id" => "U123456", "name" => "julian" } ] ) end describe "#info" do it "calls Slack::URL get with token and user" do expect(Slack::URL).to receive(:get) .with(url_for(:info) + "&user=U123456") users.info "U123456" end it "returns a channel object with the im channel information" do expect(Slack::URL).to receive(:get) .with(url_for(:info) + "&user=U123456") user = users.info("U123456") expect(user.id).to eq "U123456" expect(user.name).to eq "julian" end end describe "#list" do it "retrieves the users list" do list = Slack.users.list expect(list.map(&:name)).to eq %w(bobby julian) end end describe "#by_name" do it "uses the users.list to discover info on a given user.name" do expect(Slack.users.by_name("julian").id).to eq "U123456" end end end end end