我有一个在 Cucumber 中进行功能测试的 Ruby on Rails 程序。
我刚刚实现了一个功能,管理员可以为客户端用户创建一个新密码。现在,在“编辑客户端”页面上,有一个额外的按钮允许管理员设置密码。现在,我只需要做一个黄瓜测试。
我试图将此基于客户端更改密码的正常测试,以及管理员更改用户信息的测试。我所拥有的是:
Feature: Analyst changes client's password
As an Analyst
I want to change client's password
So that I can reset the client's account
Background:
Given the following client accounts
| email | password |
| user1@someorg.com | password |
And I am logged in as an admin
@javascript
Scenario: Update a Client user
Given I navigate to the Clients Management Page
When I edit the Client User "user1@someorg.com"
And I click on "button"
Then I should be on the Clients Password Page
@javascript
Scenario: Can change password if confirmation matches
Given I navigate to the Clients Password Page
And I enter "Password1" as the password
And I enter "Password1" as the password confirmation
And I submit the form
Then I should be taken to the Client Landing Page
And The client's password should be "Password1"
在步骤中,我有:
Given /^I navigate to the Clients Password Page$/ do
client_management_index_page = ClientsPasswordPage.new Capybara.current_session
client_management_index_page.visit
end
Then /^I should be on the Clients Password Page$/ do
client_password_page = ClientsPasswordPage.new Capybara.current_session
expect(client_password_page).to be_current_page
end
和客户密码页:
class ClientsPasswordPage
include PageMixin
include Rails.application.routes.url_helpers
def initialize session
initialize_page session, edit_admin_client_password_path
end
end
除了 edit_admin_client_password_path 需要一个 :id,用于正在编辑的用户。我不知道如何将这些信息输入其中。
万一这很重要,我正在使用设计来解决安全问题......