2014-09-06 66 views
0

如何我可以用黄瓜和模拟重定向到PayPal和回?模拟测试PayPal支付黄瓜

我开发一个Web应用程序,你可以做的贝宝支付,我想创建一个使用黄瓜测试我的功能,但我坚持贝宝重定向问题来测试我的web应用程序。

使用

  • 黄瓜1.3.16
  • 黄瓜导轨1.4.1
  • 导轨4
  • 贝宝经常性

结果

功能:订阅服务

让用户可以订阅任何服务

当用户

我想一个服务添加到用户帐户

方案:订阅服务“的每月账单”正确#特性/ subscribe_service。特点:7

Given a user go to "url" and click "sign in"            # features/step_definitions/create_account_steps.rb:2 

And username and password: "[email protected]", "password"             # features/step_definitions/login_account_steps.rb:2 

And a plan "Monthly bill "                  # features/step_definitions/subscribe_service_steps.rb:1 

When a Customer login into the account with a email and passwd: "[email protected]", "password"    # features/step_definitions/login_account_steps.rb:6 

Then I should see plan "Monthly bill"               # features/step_definitions/subscribe_service_steps.rb:5 

And a user click into "Subscribe"                   # features/step_definitions/update_account_password_steps.rb:1 

Then go to click pay for subscribe                   # features/step_definitions/subscribe_service_steps.rb:9 
    **No route matches [GET] "/cgi-bin/webscr" (ActionController::RoutingError)** 
    ./features/step_definitions/subscribe_service_steps.rb:11:in `/^go to click pay for subscribe$/' 

功能/ subscribe_service.feature:14:`然后去点击付费的订阅”

有什么办法来嘲笑支付宝付款,并返回一个结果的应用程序?

回答

0

确定以解决这个问题上面我实现了这一步,但现在我得到了另一个错误,这似乎是来自PayPal模拟重定向是注销的用户,因为结果现在WHE它试图完成付款,其重定向到登录页面。这是使用webmock。

Given(/^paypal will authorize payment$/) do 
    # Because paypal_recurring will redirect the client                          \ 

    # to the http://sandbox.paypal.com/cgi-bin/webscr                           \ 

    # We need to define this route to prevent the "undefined route"                       \ 


    Rails.application.routes.append do 
    get '/cgi-bin/webscr' => "stores#subscription" 
    end 

    Rails.application.reload_routes! 

     stub_request(:post, "https://api-3t.sandbox.paypal.com/nvp"). 
     to_return(:status => 200, :body => " ", :headers => {}) 

end 

黄瓜日志

Scenario: subscribe to service "Monthly bill" correctly           # features/subscribe_service.feature:7 
    Given a user go to "http://localhost:3000" and click "sign in"            # features/step_definitions/create_account_steps.rb:2 
    And username and password: "[email protected]", "password"             # features/step_definitions/login_account_steps.rb:2 
    And a plan "Monthly bill "                  # features/step_definitions/subscribe_service_steps.rb:1 
    And paypal will authorize payment                   # features/step_definitions/subscribe_service_steps.rb:5 
    When a Customer login into the account with a email and passwd: "[email protected]", "password"    # features/step_definitions/login_account_steps.rb:6 
    Then I should see plan "Monthly bill "               # features/step_definitions/subscribe_service_steps.rb:25 
    And a user click into "Subscribe"                   # features/step_definitions/update_account_password_steps.rb:1 
    Then go to click pay for subscribe                   # features/step_definitions/subscribe_service_steps.rb:29 
    Then go to account home with a successfull message "service added"           # features/step_definitions/create_account_steps.rb:23 
     expected to find text "service added" in "You need to sign in or sign up before continuing. " (RSpec::Expectations::ExpectationNotMetError) 
     ./features/step_definitions/create_account_steps.rb:24:in `/^go to account home with a successfull message "(.*?)"$/' 
     features/subscribe_service.feature:19:in `Then go to account home with a successfull message "service added"' 
    When I open the email                      # features/step_definitions/email_steps.rb:76 
    Then I should see "We wanted to let you know that your now are subscribe to the service." in the email body # features/step_definitions/email_steps.rb:108