Rails rspec undefined方法`receive_message’用于#<RSpec :: ExampleGroups ::

我试图在before(:each)内部模拟一些数据并得到

  NoMethodError: undefined method `receive_message' for # 

before(:each

 before(:each) do @rates = {"exchangerates"=> {"row"=> [{"exchangerate"=>{"ccy"=>"EUR", "base_ccy"=>"UAH", "buy"=>"28.33917", "sale"=>"28.33917"}}, {"exchangerate"=>{"ccy"=>"RUR", "base_ccy"=>"UAH", "buy"=>"0.38685", "sale"=>"0.38685"}}, {"exchangerate"=>{"ccy"=>"USD", "base_ccy"=>"UAH", "buy"=>"24.88293", "sale"=>"24.88293"}}, {"exchangerate"=>{"ccy"=>"BTC", "base_ccy"=>"USD", "buy"=>"605.3695", "sale"=>"669.0926"}}]}} obj = double() @request = allow(obj).to receive_message(@rates) end 

怎么解决?

它只是receive ,除非你允许多条消息,然后它是receive_messages – 复数。

例:

 allow(obj).to receive(:method_name) allow(obj).to receive(:method_1 => :result_1, :method_2 => :result_2) 

请参阅Relish文档 。