草庐IT

启动异常崩溃

全部标签

ruby - 你如何断言另一个 ruby​​ 模块的异常被抛出? (使用 assert_throws)

我正在尝试编写这样的代码:assert_throws(:ExtractionFailed){unit.extract_from('5x2005')}ExtractionFailed是Exception的一个简单子(monad)类,在test/unit下,我试图断言它在我调用unit.extract_from(...坏数据...)我已经将ExtractionFailed移动到SemanticText模块中,所以现在test/unit说:expectedtobethrownbutwasthrown.我尝试编写assert_throws(:SemanticText::ExtractionFa

ruby-on-rails - 启动 Rails 服务器时出错 - 获取 "uninitialized constant Devise::Models::Invitable (NameError)"

我是Rails的新手,正在尝试按照这个预启动注册教程进行操作-http://railsapps.github.com/tutorial-rails-prelaunch-signup.html使用$railss初始化rails服务器时,我收到以下错误消息:Users/pv/.rvm/gems/ruby-1.9.3-p194@rails326/gems/devise-2.1.2/lib/devise/models.rb:97:in`const_get':未初始化常量设计::模型::邀请(NameError)后面跟着一堆文件路径,比如:from/Users/patrickvihtelic/.

ruby-on-rails - Foreman无法启动Nginx,但我可以手动启动。为什么?

我目前正在运行Foreman在暂存(Ubuntu)上,一旦我开始工作,就会切换到使用upstart。我的Procfile.staging看起来像这样:nginx:sudoservicenginxstartunicorn:bundleexecunicorn-c./config/unicorn.rbredis:bundleexecredis-serversidekiq:bundleexecsidekiq-v-C./config/sidekiq.yml我可以使用以下方法成功启动nginx:$sudoservicenginxstart然而,当我运行$foremanstart时,当其他三个进程成

ruby-on-rails - 使用自定义异常时未初始化的常量

我正在尝试为我的应用创建自定义异常(exception)。我的libs文件夹中有一个示例库,其文件夹结构如下:-lib/||--social/||--bandcamp.rb这个bandcamp.rb文件内容如下:moduleSocialclassExampleException问题是,我可以在我的应用程序中的任何地方使用Social::Bandcamp.new.some_method,它工作得很好,但我无法访问Social::ExampleException也不会在任何地方提出。它给了我NameError:uninitializedconstantSocial::ExampleExce

ruby - 为什么 Ruby 在抛出 NameError 异常后仍保留代码求值?

我无法向自己解释的简单代码:putsaifa=1这导致warning:found=inconditional,shouldbe==NameError:undefinedlocalvariableormethod'a'formain:Object不过,现在检查a我们可以看到,它已被定义:a#=>1尽管抛出异常,为什么a仍被分配给1?来自docs:Theconfusioncomesfromtheout-of-orderexecutionoftheexpression.Firstthelocalvariableisassigned-tothenyouattempttocallanonexis

ruby - 启动和停止 Ruby 线程

我如何从另一个线程中启动和停止一个单独的线程?loop_a_stopped=trueloop_a=Thread.newdoloopdoThread.stopifloop_a_stopped#Dostuffsleep3endendloop_b=Thread.newdoloopdoresponse=ask(">")caseresponse.strip.downcasewhen"start"loop_a_stopped=falseloop_a.runwhen"stop"loop_a_stopped=truewhen"exit"breakendendendloop_a.joinloop_b.j

ruby - 如何在 EventMachine 实现中捕获异常?

我有一个与thisotherpost类似的问题我已经尝试了给定的解决方案,但无济于事。我的项目是一个使用Blather的Ruby机器人库连接到Jabber服务器。问题是,当服务器出现问题并且Blather生成异常时,整个程序退出,我没有机会捕获异常。下面是一些显示问题的简单代码。本地主机上没有运行Jabber服务器,因此Blather客户端抛出异常。我的印象是EM.error_handler{}能够拦截它,但我从未看到****ERROR消息,程序就停止了。:(#!/usr/bin/envrubyrequire'rubygems'require'blather/client/client

ruby - 使用 RSpec 我如何测试救援异常 block 的结果

我有一个方法,其中有一个begin/rescueblock。如何使用RSpec2测试救援block?classCapturerdefcapturebeginstatus=ExternalService.callreturntrueifstatus=="200"returnfalserescueException=>eLogger.log_exception(e)returnfalseendendenddescribe"#capture"docontext"anexceptionisthrown"doit"shouldlogtheexceptionandreturnfalse"doc=C

Ruby 捕获 NoMethodError 并从发生异常的地方继续执行

在Ruby中,我想在另一个对象中捕获在一个对象上生成的NoMethodError,然后将一些值返回到引发异常的位置并继续执行。有没有现成的方法可以做到这一点?我想到的最好的是:classExceptionattr_accessor:continuationendclassOuterdefhelloputs"hello"endclassInnerdefworldputs"world"enddefmethod_missing(method,*args,&block)x=callccdo|cc|e=RuntimeError.exception(method)e.continuation=cc

ruby - Cucumber 测试无法启动,错误为 "Display socket is taken but lock file is missing.."

运行cucumber后bundleexeccucumberfeatures/emails.feature:20我遇到了错误Displaysocketistakenbutlockfileismissing-checktheHeadlesstroubleshootingguide(Headless::Exception)/Users/me/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/headless-2.2.0/lib/headless.rb:195:inensure_xvfb_is_running'/Users/me/.rbenv/ver