首页 \ 问答 \ Rpsec测试失败了'rspec'但没有'rspec path_of_the_file'(Rpsec tests failed with 'rspec' but not with 'rspec path_of_the_file')

Rpsec测试失败了'rspec'但没有'rspec path_of_the_file'(Rpsec tests failed with 'rspec' but not with '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 <top (required)>'

这是调用该方法的行:

 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

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

谢谢


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

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)>'

This is the line where the the method is called:

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

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

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

EDIT 1

I've also a cucumber feature for that and the test pass.

Thanks


原文:https://stackoverflow.com/questions/20422856
更新时间:2024-01-15 10:01

最满意答案

注意:在Chrome中, Ctrl + W是“保留”,请使用window.onbeforeunload

试试这个(禁用Ctrl + WCtrl + S ):

window.onbeforeunload = function () {//Prevent Ctrl+W
    return "Really want to quit the game?";
};

document.onkeydown = function (e) {
    e = e || window.event;//Get event
    if (e.ctrlKey) {
        var c = e.which || e.keyCode;//Get key code
        switch (c) {
            case 83://Block Ctrl+S
            case 87://Block Ctrl+W --Not work in Chrome
                e.preventDefault();     
                e.stopPropagation();
            break;
        }
    }
};

Note: In Chrome Ctrl+W is "reserved", use window.onbeforeunload

Note: Chrome requires event.returnValue to be set

In this code document.onkeydown is used for old browsers and window.onbeforeunload is used to Chrome and Firefox

Try this (disable Ctrl+W and Ctrl+S):

window.onbeforeunload = function (e) {
    // Cancel the event
    e.preventDefault();

    // Chrome requires returnValue to be set
    e.returnValue = 'Really want to quit the game?';
};

//Prevent Ctrl+S (and Ctrl+W for old browsers and Edge)
document.onkeydown = function (e) {
    e = e || window.event;//Get event

    if (!e.ctrlKey) return;

    var code = e.which || e.keyCode;//Get key code

    switch (code) {
        case 83://Block Ctrl+S
        case 87://Block Ctrl+W -- Not work in Chrome and new Firefox
            e.preventDefault();
            e.stopPropagation();
            break;
    }
};

相关问答

更多
  • 这里有一个很好的报道: http : //unixpapa.com/js/key.html 至于这是否应该完成,stackoverflow的问题编辑器会覆盖好几个按键,而不会中断太多(悬停在工具栏按钮上)。 There's an excellent coverage of this here: http://unixpapa.com/js/key.html As for whether this is something that should be done, stackoverflow's questi ...
  • 在Javascript中捕获Ctrl键盘事件 示例代码: $(window).keydown(function(event) { if(event.ctrlKey && event.keyCode == 84) { console.log("Hey! Ctrl+T event captured!"); event.preventDefault(); } if(event.ctrlKey && event.keyCode == 83) { console.log("H ...
  • 对于特定的窗口,您可以在这里查看所有窗口快捷方式。 只是为了确保你也可以看看这个维基百科文章 。“Alt”优先于“Ctrl”或其他方式的偏好只是你认为更加实用和更加用户友好的。 我建议你考虑其他键,比如“Shift”和F键。 For windows specifically you can look here for all the windows shortcuts. Just to be sure you can also look at this wikipedia article The prefe ...
  • 注意:在Chrome中, Ctrl + W是“保留”,请使用window.onbeforeunload 试试这个(禁用Ctrl + W和Ctrl + S ): window.onbeforeunload = function () {//Prevent Ctrl+W return "Really want to quit the game?"; }; document.onkeydown = function (e) { e = e || window.event;//Get event ...
  • 您可以通过javascript禁用所需的任何键。 您只需要知道它们的关键代码。 You can disable any keys you want via javascript. You just need to know the key code for them.
  • 谢谢wOxxOm的帮助。 当你说这个问题与分配了相同热键的冲突扩展时,你是对的。 一旦我禁用扩展我的扩展工作正常。 Thank you wOxxOm for your help. You were right when you said the issue was with a conflicting extension with the same hotkey assigned. Once I disabled the extension my extension worked properly.
  • 我不确定你能从我读过的内容来判断。 但是,您可以使用将其传递给silverlight应用程序的页面上的javascript代码来破解它。 (参见javascript / silverlight interop ) I'm not sure you can judging by what I've read. You may be able to hack it with javascript code on the page that passes it on to the silverlight appl ...
  • function Disable_Control_C() { var keystroke = String.fromCharCode(event.keyCode).toLowerCase(); if (event.ctrlKey && (keystroke == 'c' || keystroke == 'v' || keystroke == 'p' || keystroke == 's' || keystroke == 'u')) { alert("this function is disable ...
  • 我不明白密钥是如何翻译的,这些代码是什么意思? 使用Ctrl + AnyKey组合获得的值是Ascii控制代码。 它们源于需要从键盘输入非打印(控制)字符。 控制字符的(典型)值低于32加del字符(127)。 有关历史和标准的更多信息可以在这里和这里找到。 I don't understand how keys are translated, what does these codes mean? The values you get with the Ctrl+AnyKey combinations a ...
  • 今天我了解到,当在窗口中显示所有快捷方式时,可以再次按Ctrl - Shift - L ,它会转到快捷键首选项页面,其中有一个文本框来搜索键绑定。 Today I learned that when in the window displaying all the shortcuts one can just hit Ctrl-Shift-L again and it takes you to the key shortcuts preferences page, where there is a text ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)