This might look like a newbie issue but I'm stumped. I'm trying to build a simple Ruby slack service and I'm putting together some unit tests using RSpec. I bumped into this strange issue and I can't see what's going on.
RSpec.describe SlackService do
let(:token) { 'BOT-TOKEN' }
subject do
SlackService.new(token)
end
describe '#channel_list' do
context 'get channels' do
let(:client) { instance_double(Slack::Web::Client) }
before(:each) do
allow(:subject).to receive(:client) { client }
@result = subject.channel_list
end
it { expect(@result).to eq [] }
end
end
end
The error I get when I run rspec
is
Failures:
1) SlackService#channel_list get channels
Failure/Error: allow(:subject).to receive(:client) { instance_double(Slack::Web::Client) }
TypeError:
can't define singleton
# ./spec/slack_service_spec.rb:12:in `block (4 levels) in <top (required)>'
Will edit if someone needs more information. Any idea what this error means? I can't seem to get rid of it no matter what.
It seems to be a typo. Should be subject
and not :subject
allow(subject).to receive(:client) { client }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With