3

Need help ;) Here is example of the code:

def some_method
  @some_variable = "some logic for a few strings and operations"
end

I want to stub this method like a

controller.stub(:some_method).and_return( ??? )

But @some_variable should be defined also, how I can do that?

prosto.vint
  • 1,403
  • 2
  • 17
  • 30

1 Answers1

5

You can stub it like

allow(controller).to receive(:some_method) { your_return_value }

Just using the new syntax for stubbing above.

For your instance variable, you can do

controller.instance_variable_set(:@some_variable, value)
Jagdeep Singh
  • 4,880
  • 2
  • 17
  • 22