Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing documentation on usage with RSpec? #233

Open
Alobeast opened this issue Aug 6, 2019 · 1 comment
Open

Missing documentation on usage with RSpec? #233

Alobeast opened this issue Aug 6, 2019 · 1 comment

Comments

@Alobeast
Copy link

Alobeast commented Aug 6, 2019

Hi,

When trying to rspec test a command such as:

command('support', &->(client, data, match){
        channel_real_name = client.channels.dig(data.channel, :name)
        client.say(channel: data.channel,
                         text: "#{channel_real_name} support url: https://url")
})

with the following spec file:

require_relative '../commands/support'
require 'pry'


describe MyBot::Commands::Support do

  it 'gives support link' do
    expect(message: "#{SlackRubyBot.config.user} support").to respond_with_slack_message(/support url/)
  end
end

and spec_helper:

require 'slack-ruby-bot/rspec'
require 'webmock/rspec'

$LOAD_PATH.unshift(File.dirname(__FILE__))

require 'yaml'
require 'json'
require 'async'

require_relative '../mybot'

When running rspec I get:

1) MyBot::Commands::Support gives support link
     Failure/Error: client.channels.dig(data.channel, :name)
     
     NoMethodError:
       undefined method `dig' for nil:NilClass

Whereas I'm expecting to get a green passing test.

In order to get over the error I think I need to connect to slack but I can’t find the proper documentation for doing so.

Thanks

@dblock
Copy link
Collaborator

dblock commented Aug 7, 2019

The RTM client's .channels is something that comes from a local store. Since we are not actually starting a client we either need to stub that store in tests or default it. I think it's a bug either way. I'm happy to take a PR for either code or docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants