【发布时间】:2018-07-09 14:54:24
【问题描述】:
我有一个在 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,用于正在编辑的用户。我不知道如何将这些信息输入其中。
以防万一,我正在使用 Devise 来解决安全问题...
【问题讨论】:
-
顺便说一句,由于在 stackExchange 领域没有任何地方可以询问,如果有人在 RoR 中有一个好的 Cucumber 教程,那也会很有用!
标签: ruby-on-rails devise cucumber capybara