如何使用rspec-rails测试功能?

时间:2019-07-01 20:51:45

标签: ruby-on-rails rspec tdd rspec-rails

我正在尝试在一个新的Rails 5项目中测试我的设计验证系统。因此,我进行了以下测试:

require "rails_helper"

feature "User sign up", type: :feature do
  subject     { page }
  let!(:user) { build :user }
  before      { visit "/users/sign_up" }

  scenario "User creates new account" do
    find_field('user[name]').set(user.name)
    find_field('user[email]').set(user.email)
    find_field('user[password]').set(user.password)
    find_field('user[password_confirmation]').set(user.password)
    click_button "Log in"
    expect(User.count).to eq 1
  end
end

一切正常,直到我需要测试用户的实际创建为止。那时候我无法掌握如何正确测试此功能。 我应该使用诸如webdriver或capybara之类的东西吗?

这是我的gemfile的相关部分:

gem 'devise'

group :development, :test do
  # Tests
  gem 'rspec-rails'
  gem 'jasmine-rails'
  # Call 'byebug' anywhere in the code to stop execution and get a debugger console
  gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
  # Factory & Mocks
  gem 'factory_bot_rails'
end

group :test do
  # Adds support for Capybara system testing and selenium driver
  gem 'capybara', '~> 3.21'
  gem 'selenium-webdriver', '~> 3.142', '>= 3.142.3'
  # Easy installation and use of chromedriver to run system tests with Chrome
  gem 'webdrivers', '~> 4.0'
end

我欢迎使用rspec-rails测试功能的可行方法的建议和教程

0 个答案:

没有答案