Rpsec测试失败了’rspec’但没有’rspec path_of_the_file’

如果我运行此命令“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") end end 

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

编辑1

我还有一个黄瓜function和测试通过。

谢谢

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

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

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

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

对我来说,我有

  config.before(:all) do Rails.application.load_seed # loading seeds end 

在我的rails_helper.rb文件中,该文件在每个文件的开头加载我的种子,这导致了冲突。

我更改了我的代码以在套件的开头加载种子。

  config.before(:suite) do DatabaseCleaner.clean_with(:truncation) Rails.application.load_seed # loading seeds end