Rails rspec未定义方法`receive_message'用于#<rspec :: examplegroups ::

时间:2016-06-27 12:34:59

标签: ruby-on-rails ruby rspec

=“”

我正在尝试模拟{{1}内的一些数据获取

INFO ] 2016-06-27 18:00:14.880 [main] AuthenticationFilter - 226
[INFO ] 2016-06-27 18:00:14.881 [main] AuthenticationFilter - 202f660a-00e9-436e-af48-bcc7dcbd85c9
[INFO ] 2016-06-27 18:00:14.974 [main] OffersController - insert inside the InsertOfferController
[INFO ] 2016-06-27 18:00:14.975 [main] OffersServicesImpl - Insert offerInsert Services
[INFO ] 2016-06-27 18:00:15.009 [main] TransactionContext - **Rolled back transaction for test context** [DefaultTestContext@4848681d testClass = OfferControllerTest, testInstance = com.my.endpoint.OfferControllerTest@7712c315, testMethod = insertOrderTest@OfferControllerTest, testException = [null], mergedContextConfiguration = [MergedContextConfiguration@54d6f172 testClass = OfferControllerTest, locations = '{}', classes = '{class com.my.MyApplication}', contextInitializerClasses = '[]', activeProfiles = '{}', propertySourceLocations = '{}', propertySourceProperties = '{}', contextLoader = 'org.springframework.boot.test.SpringApplicationContextLoader', parent = [null]]].

我的before(:each)

 NoMethodError:
   undefined method `receive_message' for #<RSpec::ExampleGroups::CurrencyExchange:0x007f87c652f3c8>

如何解决?

1 个答案:

答案 0 :(得分:1)

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

示例:

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

请参阅the Relish documentation