rpsec测试因“ rspec”失败,但因“ rspec path_of_the_file”而失败 [英] Rpsec tests failed with 'rspec' but not with 'rspec path_of_the_file'

查看:108
本文介绍了rpsec测试因“ rspec”失败,但因“ rspec path_of_the_file”而失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

If I run this command "rspec ./spec/requests/api/v1/password_reset_request_spec.rb" all the test inside this file pass.

但是,当我运行 rspec时,我对该文件中的测试却有失败的兴趣。

However when I run "rspec" I've a faillure on the tests inside this file.

  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 <top (required)>'

该方法称为:

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

这是RunnerMailer类:

And this is the RunnerMailer class:

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'时测试通过吗?

Any idea why the test pass when I do 'rspec file_path' and not when I do 'rspec' ?

编辑1

测试通过。

谢谢

推荐答案

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

When the execution of an individual spec succeeds but the same spec fails when run as part of the larger suite, it indicates that the prior execution of the other tests is affecting the result.

问题是深层嵌套的,在这种情况下,一种隔离问题的方法是从有问题的规范开始逐步运行后续目录中的所有规范,直到造成故障为止。找到导致问题的目录后,可以通过指定要在失败测试之前运行的不同规格规范来进一步隔离,直到找出有问题的规格为止。

If the spec in question is deeply nested, as in this case, one way to isolate the problem is to run all the specs in successive directories up from the spec in question until you cause a failure. Once you hit the directory that causes the problem, then you can isolate further by specifying different series of specs to run prior to the failing test until you isolate the problematic spec.

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

For example, in this case, you would run rspec spec/requests/api/v1 and if that succeeds, rspec spec/requests/api, and if that succeeds rspec spec/requests.

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

Since under normal conditions RSpec is careful to rollback any changes that individual tests make (both to the Ruby runtime and the database), interference is usually due to some code being run outside of the normal RSpec framework. In general, all test code should be included within the describe blocks.

这篇关于rpsec测试因“ rspec”失败,但因“ rspec path_of_the_file”而失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆