Search code examples
ruby-on-railsrspeccontrollers

Testing Object Instantiation in Rails Controllers


(In RSpec) I am testing that an object in my controller is getting instantiated:

CONTROLLER:

stripe_params = StripeParams.new(params)

TEST:

it "creates a new params instance" do
  get :message, params
  StripeParams.should_receive(:new).with(params)
end

... However, this is giving me the following test error:

expected: 1 time
received: 0 times


Solution

  • you have to work expectation prior to run the code:

    it "creates a new params instance" do
      StripeParams.should_receive(:new).with(params) 
      get :message, params
    end