spec/boty/slack/users_spec.rb in boty-0.0.17.1 vs spec/boty/slack/users_spec.rb in boty-0.1.0
- old
+ new
@@ -1,43 +1,69 @@
module Boty
module Slack
RSpec.describe Users do
- subject(:users) { described_class.new }
-
- let(:action) { :info }
-
- let(:url) {
+ 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 + "&user=U023BECGF").
+ 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,
- "user" => {
- "id" => "U023BECGF",
+ "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 + "&user=U023BECGF")
+ expect(Slack::URL).to receive(:get).with(url_for(:info) + "&user=U123456")
- users.info "U023BECGF"
+ users.info "U123456"
end
it "returns a channel object with the im channel information" do
- expect(Slack::URL).to receive(:get).with(url + "&user=U023BECGF")
+ expect(Slack::URL).to receive(:get).with(url_for(:info) + "&user=U123456")
- user = users.info("U023BECGF")
+ user = users.info("U123456")
- expect(user.id).to eq "U023BECGF"
+ 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 ["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