这是我的用户控制器。如何在 RSpec 中测试此代码?

This is my user controller. How to test this code in RSpec?

如何在这个用户登录中编写测试用例。我是 rails 测试的新手 我正在使用 Rspec gem。我需要 rails 测试的任何教程。

if params.key?(:mobile) && params.key?(:password)
 user = User.find_by(mobile: params[:mobile], is_active: 1)
                          if user.nil?
                            output = { status: '06', message: 'Invalid user.' }.to_json
                          elsif user.authenticate(params[:password])

                            auth_token = JsonWebToken.encode(id: user.id,
                                                             user_type: user.user_type)
                            object = { id: user.id, user_type: user.user_type,
                                       name: user.name }
                            output = { status: '10', message: 'Successful.',
                                       auth_token: auth_token, user: object}.to_json
                          else
                            output = { status: '06', message: 'Incorrect password.' }.to_json                         
 end
                        else
                          output = { status: '01', message: 'Invalid parameters.' }.to_json
                        end
                        render json: output, status: :ok

如果您使用 Rspec gem 编写测试用例,那么您可以使用 Tutorial point rspec Turorials。这将是一个良好的开端,让您在 Rails 上的 Ruby 中了解测试的工作原理。您也可以尝试一些电子书来深入了解知识。