我有以下链式数据:
Data::Universal.find("501c2599dc1c82704e000037").data.last.foo
=> [#<Data::Universal::Foo::ErrorMessage _id: 501c24f1dc1c82704e000014, _type: "Data::Universal::Foo::ErrorMessage", created_at: nil, updated_at: nil, is_enabled: true, left_px: 1, top_px: 1, width_px: 420, height_px: 198, inner_width: nil, inner_height: nil, z_index: 1000, position: nil, name: nil, custom_css: "", element_label: "Error Message ", can_be_deleted: true, sticky: false, sticky_eigenscreen: "top", sticky_screens: [], audience_id: "", can_be_spatially_edited: false, editable_left_px_setting: true, editable_top_px_setting: true, editable_width_px_setting: true, editable_height_px_setting: true, version: nil, modifier_id: nil, primary_color: "#6D84B4", primary_border_color: "#29447E", secondary_color: "#F2F2F2", screen_id: "4f9058772774e2279200004d">]
如何使用rspec来存根?
答案 0 :(得分:0)
自然地使用stub_chain:)
subject.stub_chain(:one, :two, :three).and_return(:four)
subject.one.two.three.should eq(:four)
对于带参数的存根链,请参阅this answer。