ruby-on-rails - 注册用户然后访问带有系统测试的帐户页面?

标签 ruby-on-rails testing capybara minitest system-testing

如果我没理解错的话,以如下形式创建用户不会在数据库中创建记录。

我想创建一个系统测试来遵循这些步骤:
1. 以表格形式报名
2. 访问账户页面
3.更新账户信息

什么技术可以实现上述场景?

within 'form#t-signup-form' do
    fill_in 'first_name', with: 'Eve'
    fill_in 'last_name', with: 'Farmer'
    fill_in 'email', with: 'eve@example.com'
    fill_in 'password', with: 'Something'
    find('button').click
end

最佳答案

用户记录是否实际提交到数据库取决于您是否使用事务测试。如果您正在使用事务测试,那么记录实际上不会被提交,但这无关紧要,因为(如果配置正确)您的测试和应用程序中的所有内容都应该访问相同的预提交事务,因此会看到记录。做你想做的事

visit signup_path #whatever is the correct route to the page with the signup form
within '#t-signup-form' do
  fill_in 'first_name', with: 'Eve'
  fill_in 'last_name', with: 'Farmer'
  fill_in 'email', with: 'eve@example.com'
  fill_in 'password', with: 'Something'
  find('button').click
end
assert_content('You are signed up!') # assert for visible change in page that indicates signup has succeeded
visit account_path # route to whatever page you want to go to
... # do whatever actions are required to update the account

关于ruby-on-rails - 注册用户然后访问带有系统测试的帐户页面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47603011/

相关文章:

ruby-on-rails - 是否可以在 Gemfile 中让一组从另一组继承

ruby-on-rails - ActiveRecord 选择了错误的 class_name

asp.net-mvc - MVC - 强制构建和编译 Razor View 标记

ruby - capybara 与 Selenium : Can't click on hidden element

ruby-on-rails - 遇到奇怪的 capybara 问题

ruby-on-rails - Controller 规范中的 RSpec stub 辅助方法

ruby-on-rails - 在 Google Cloud 上运行的 Rails 5 应用程序出现 ConnectionBad 问题,通过套接字运行到 Google Cloud SQL 实例

ruby-on-rails - 如何使用 Capybara Rspec Matchers 测试演示者?

ios - 使用 Selenium 和 ios-driver 从 Windows 计算机测试 iOS 移动应用程序

objective-c - 在 iOS 上测试 Mantle 模型时出错