RSpec存在奇怪的期望错误

时间:2015-04-10 07:31:27

标签: ruby-on-rails ruby rspec stubbing

我已经测试了我的控制器并且遇到了类似的奇怪错误:

    expected: ("376")
          got: (376)
    Please stub a default value first if message might be received with other args as well. 

这是我的规范:

   it 'should send confirm-email if information is good' do
     sign_in user
     allow(Order).to receive(:find).with(order.id.to_s).and_return(order)
     allow(order).to receive(:finalize) {order}
     allow(order.errors).to receive(:empty?) {true}
     expect(OrderMailer).to receive_message_chain(:send_finish_notification, :deliver)
     patch :save_order, {:id => order.id , :order => {:street_address => 'Baker street', :apt => '123#', :zip_id => zip.id, :frequency_id => frequency.id, :amount_per_hour => '5',
                                                  :extras_ids => '', :phone_number => '3213', :credit_card_number => '4242424242424242', :credit_card_cvv => '777',
                                                  :credit_card_expiration => '12/20', :source_information => ''}}
   end

我在一些逻辑密切的规范中得到了这个错误。但是有些测试通过了,就像这样:

   it 'should not update user data if order errors is not empty' do
     sign_in user
     allow(Order).to receive(:find).with(order.id.to_s).and_return(order)
     allow(order).to receive(:finalize) {order}
     allow(order.errors).to receive(:empty?) {false}
     expect(User).to_not receive(:update_user_data)
     patch :save_order, {:id => order.id, :order => {:street_address => 'Baker street', :apt => '123#', :zip_id => zip.id, :frequency_id => frequency.id, :amount_per_hour => '5',
                                                  :extras_ids => '', :phone_number => '3213', :credit_card_number => '4242424242424242', :credit_card_cvv => '777',
                                                  :credit_card_expiration => '12/20', :source_information => ''}}
   end

to_s或to_i没有帮助。控制器中的错误行 -

   @order = Order.find(params[:id]

那么在那种情况下可能是什么? '因为它看起来像一些规格通过,但与他们相似并不相同。有什么建议吗?

0 个答案:

没有答案