Hi, I created my test with capybara and rspec. This is my test
require 'rails_helper'
RSpec.feature "Users", type: :feature do
context "crear nuevo usuario" do
scenario "creacion exitosa" do
user= FactoryBot.create(:user, :super_usuario)
login_as(user, :scope => :user)
visit new_user_path
within('#frm_user') do
fill_in('user_user', with: 'elusuario')
fill_in('user_name', with: 'Jhon Smith')
fill_in('user_email', with: '[email protected]')
select('Cliente', from: 'user[roles]')
fill_in('user_password', with: '123456')
end
click_button 'Grabar'
expect(page).to have_content('Usuario creado satisfactoriamente.')
end
end
context "editar usuario" do
end
context "eliminar usuario" do
end
end
And this is the method in my controller
POST /users
# POST /users.json
def create
@flag_nuevo_usuario=true
@user = User.new(user_params)
authorize @user
respond_to do |format|
if @user.save
format.html { redirect_to @user, notice: 'Usuario creado satisfactoriamente.' }
format.json { render :show, status: :created, location: @user }
else
format.html { render :new }
format.json { render json: @user.errors, status: :unprocessable_entity }
end
end
end
But when I run it just throws me an error that fails, but it does not tell me what value it is returning. I am using pundit with devise and to validate access to tests I have configured in my rails_helper.rb
#Para que se pueda autenticar por capybara para pruebas
config.include Warden::Test::Helpers
This is the error trace:
Users crear nuevo usuario creacion exitosa
Failure/Error: expect(page).to have_content('Usuario creado satisfactoriamente.')
expected to find text "Usuario creado satisfactoriamente." in "Dashboard Charts Tables Dato Maestros Navbar Cards Example Pages Login Page Registration Page Forgot Password Page Blank Page Reportes Second Level Item Second Level Item Second Level Item Third Level Third Level Item Third Level Item Third Level Item Messages 12 New New Messages: David Miller 11:21 AM Hey there! This new version of SB Admin is pretty awesome! These messages clip off when they reach the end of the box so they don't overflow over to the sides! Jane Smith 11:21 AM I was wondering if you could meet for an appointment at 3:00 instead of 4:00. Thanks! John Doe 11:21 AM I've sent the final files over to you for review. When you're able to sign off of them let me know and we can discuss distribution. View all messages Alerts 6 New New Alerts: Status Update 11:21 AM This is an automated server response message. All systems are online. Status Update 11:21 AM This is an automated server response message. All systems are online. Status Update 11:21 AM This is an automated server response message. All systems are online. View all alerts Logout Inicio/users NUEVO USUARIO /users 1 error impiden que se pueda guardar el registro: User has already been taken × User Name Email Roles Supervisor Contador Cliente Gerente general Gerente operaciones Password Grabar Atras Copyright © Orsis 2018 Ready to Leave? × Select \"Logout\" below if you are ready to end your current session. Cancel Logout"