sách gpt4 ai đã đi

Kiểm tra Rspec không thành công với 'rspec' nhưng không thành công với 'rspec path_of_the_file'

In lại 作者:行者123 更新时间:2023-12-04 05:59:10 30 4
mua khóa gpt4 Nike

如果我运行此命令“rspec ./spec/requests/api/v1/password_reset_request_spec.rb”,此文件中的所有测试都会通过。

但是,当我运行“rspec”时,我对该文件中的测试失败了。

  1) /api/v1/password_reset #request when the email match with a runner when there is no request pending create a token for reset the password
Failure/Error: post("/api/v1/password_reset/request", @params)
NoMethodError:
undefined method `reset_password' for RunnerMailer:Class
# ./app/services/password_manager.rb:35:in `reset_password'
# ./app/controllers/api/v1/password_reset_controller.rb:31:in `request_new_password'
# ./spec/requests/api/v1/password_reset_request_spec.rb:108:in `block (5 levels) in '

这是调用方法的行:

 RunnerMailer.reset_password(@identity, @identity.reset_password_token).deliver

这是 RunnerMailer 类:

class RunnerMailer < ActionMailer::Base
default from: "no-reply@goodgym.org"

def reset_password(runner, token)
@link = "http://url/password_reset/request/" + token
mail(to: runner.email, subject: "Goodgym -- Reset your password")
kết thúc
kết thúc

知道为什么测试在我执行 'rspec file_path' 时通过,而不是在我执行 'rspec' 时通过吗?

编辑 1

我还有一个 cucumber 功能,测试通过。

Cảm ơn

1 Câu trả lời

当单个规范的执行成功但同一规范作为较大套件的一部分运行时失败时,这表明其他测试的先前执行正在影响结果。

如果有问题的规范是深度嵌套的,就像在这种情况下,隔离问题的一种方法是运行从有问题的规范开始的连续目录中的所有规范,直到导致失败。一旦找到导致问题的目录,您就可以通过指定在失败测试之前运行的不同系列的规范来进一步隔离,直到隔离出有问题的规范。

例如,在这种情况下,您将运行 rspec spec/requests/api/v1,如果成功,则 rspec spec/requests/api,如果成功成功 rspec spec/requests.

由于在正常情况下 RSpec 会小心回滚单个测试所做的任何更改(对 Ruby 运行时和数据库),干扰通常是由于某些代码在正常 RSpec 框架之外运行。通常,所有测试代码都应包含在 describe block 中。

关于ruby-on-rails - Rspec 测试以 'rspec' 失败,但以 'rspec path_of_the_file' 失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20422856/

30 4 0
行者123
Hồ sơ cá nhân

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá Didi Taxi miễn phí
Mã giảm giá Didi Taxi
Giấy chứng nhận ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com