AutoVit
AutoVit

Reputation: 83

Rspec binding.pry from method

I'm trying to use binding.pry on method and debug it.

A simplified example of what I'm trying to do.

hello.rb

class Hello
 def self.hello
  'Hello world!'
  binding.pry
 end
end

spec/hello_spec.rb

describe Hello do
 it 'Hello#hello should print message' do
  expect {Hello.hello}.to eq('Hello world!')
 end
end

I would like to debug self.hello method, how could I log this method using binding.pry? When I try to run rspec hello_spec.rb I don't get pry console to debug that method.

Upvotes: 0

Views: 911

Answers (1)

Mike
Mike

Reputation: 309

Try changing the line:

expect {Hello.hello}.to eq('Hello world!')

to:

expect Hello.hello.to eq('Hello world!')

and it should work. In other words, remove the brackets. It worked for me.

I had to do some assumptions about your setup. I would recommend including your Gemfile next time that you have a question.

Upvotes: 1

Related Questions