【问题标题】:mock testing paypal checkout with cucumber用黄瓜模拟测试贝宝结帐
【发布时间】:2014-10-31 13:00:54
【问题描述】:

如何使用 cucumber 并模拟重定向到 paypal 并返回?

我开发了一个 Web 应用程序,您可以在其中进行 paypal 付款,并且我想使用 cucumber 创建对我的功能的测试,但我遇到了 paypal 重定向问题来测试我的 Web 应用程序。

使用

  • 黄瓜1.3.16
  • 黄瓜导轨 1.4.1
  • 导轨 4
  • 贝宝定期

结果

特点:订阅服务

这样用户可以订阅任何服务

作为用户

我想向用户帐户添加服务

场景:正确订阅服务“月费”# features/subscribe_service.feature:7

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

And username and password: "user@example.com", "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: "user@example.com", "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$/'

features/subscribe_service.feature:14:in `然后去点击付费订阅'

有什么方法可以模拟贝宝付款并将结果返回给应用程序?

【问题讨论】:

    标签: ruby testing ruby-on-rails-4 paypal cucumber


    【解决方案1】:

    可以解决上面的问题,我实现了这一步,但现在我又遇到了一个错误,看来从 paypal 模拟的重定向是注销用户,结果现在它尝试完成付款,它重定向到登录页面。这是使用 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: "user@example.com", "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: "user@example.com", "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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-29
      • 2014-03-06
      • 2014-09-06
      • 1970-01-01
      • 2017-01-21
      相关资源
      最近更新 更多