我还没有很好地掌握嘲弄和抄袭。我怎么去抄袭aodc.success?打电话给假? AodcWrapper :: Order.create不完整,今天总会返回成功。但我需要模拟失败案例。
这是创建方法
def create
@user = current_user
@order = Order.new(order_params)
if @order.valid?
aodc = AodcWrapper::Order.create(@order)
if aodc.success?
# pending... Capture the authorization
@order.save
UserMailer.order_received_email(@user).deliver_later
StaffMailer.order_received_email(@user).deliver_later
render json: @order, serializer: Api::V1::OrderSerializer
else
render json: { status: :failure, error: aodc.error_message }
end
else
render json: { status: :failure, error: @order.errors.full_messages }
end
end
这是测试
context "sad path 1: can not connect to the aodc" do
before do
@user = FactoryGirl.create(:user)
@order = FactoryGirl.attributes_for(:shippable_order, user: @user)
sign_in @user
post :create, user_id: @user.id, order: @order
end
it "reponds with a could not connect message" do
parsed_response = JSON.parse(response.body)
expect(parsed_response[:error]).not_to be_nil
end
end
副任务。有关探索资源的任何建议,以便我不能嘲笑模拟和存根吗?
答案 0 :(得分:1)
所以我说这完全错了。 AodcWrapper正在与Httparty进行API调用。
我解决这个问题的路径是