Reputation: 433
I'm building a gem that allows for a much more convenient and configurable 'console' for ruby gem development than the current options (ie: 'bundle console').
As such, one of if not the most important aspects of the entire gem is that it does in fact open a console session, which I currently have set up in a start method:
class MyConsole
def start
Pry.start(self)
end
end
I am trying to test this functionality, but it's difficult because their's not a lot of good resources for this. It's also really annoying because every time I run this method in rspec, pry opens, and I have to exit it before finishing the rest of the tests.
I have three main questions:
Upvotes: 0
Views: 301
Reputation: 734
The best way to do this would probably be using an RSpec spy.
Your test would probably look something like this:
describe MyConsole do
describe '#start' do
it 'calls Pry.start' do
described_class.start
expect(Pry).to have_received(:start).with('your_args_here')
end
end
end
This is a really good explanation of RSpec stubbing options, IMO, where you can learn more: https://about.futurelearn.com/blog/stubs-mocks-spies-rspec
Upvotes: 2