草庐IT

no-use-before-define

全部标签

ruby-on-rails - 从 before(:each) block) 中获取完整的 RSpec 测试名称

RSpec允许您通过执行以下操作在before(:each)block中获取当前运行的测试方法名称:Spec::Runner.configuredo|config|config.before:eachdo|x|x.method_name#returns'shouldbecool'endend这是为了这样的测试:requireFile.expand_path(File.dirname(__FILE__)+'/../spec_helper')describe'Helloworld'doit'shouldbecool'do#testcodeendend是否有可能在beforeblock中获得

ruby-on-rails - 尝试为 ror 应用程序设置 postgres,出现错误 - fe_sendauth : no password supplied

获得:Anerrorhasoccurred:Errorconnectingtotheserver:fe_sendauth:nopasswordsupplieddatabase.yml中的设置与其他机器上的应用设置相同。我如何设置才能不需要硬编码密码?我可以使用PgAdmin-III查看数据库。我宁愿不要在database.yml中设置密码,因为使用此应用程序的其他机器没有/不需要密码,所以这似乎与我的Pg安装有关。 最佳答案 您需要更改您的pg_hba.conf。这是我的一个例子:pg_hba.conf:TYPEDATABASEUS

ruby-on-rails - rails : How to use dependent: :destroy in rails?

我有2个模型,如下所述。classEmpGroup和classEmpGroupMember现在的问题是,每当我试图摧毁一个组时,我都会收到如下错误。PG::ForeignKeyViolation:ERROR:updateordeleteontable"emp_groups"violatesforeignkeyconstraint"fk_rails_bd68440021"ontable"emp_group_members"DETAIL:Key(id)=(1)isstillreferencedfromtable"emp_group_members".我错过了什么?

ruby - 如何在 initialize() 中使用 define_method

尝试在initialize中使用define_method但得到undefined_methoddefine_method。我做错了什么?classCdefinitialize(n)define_method("#{n}"){puts"somemethod#{n}"}endendC.new("abc")#=>NoMethodError:undefinedmethod`define_method'for# 最佳答案 我怀疑您正在寻找define_singleton_method:define_singleton_method(symb

ruby-on-rails -/usr/bin/env ruby​​ 没有这样的文件或目录 : Using capistrano 3, capistrano/rbenv、capistrano/bundler 和 capistrano/rails(使用 rails 4)

我正在使用capistrano、capistrano/rbenv、capistrano/bundler和capistrano/rails。我在capistrano编译Assets的步骤中得到这个错误:DEBUG[49a50df6]/usr/bin/env:DEBUG[49a50df6]rubyDEBUG[49a50df6]:NosuchfileordirectoryDEBUG[49a50df6]在生产服务器中/usr/bin/envruby​​-v是正确的。我知道这一点:why-does-something-work-in-my-ssh-session-but-not-in-capis

ruby - 在 Ruby 的 define_method 中使用 yield

是否可以让yield关键字在给定define_method的block内工作?简单示例:classTestdefine_method:testdo|&b|putsb#=>#yieldendendTest.new.test{puts"Hi!"}此代码在Ruby1.8.7和1.9.0中都会产生以下错误:test.rb:4:in`test':noblockgiven(LocalJumpError)fromtest.rb:8奇怪的是bblock变量!=nil但block_given?返回false。不识别Proc对象的block是Ruby的故意行为吗?编辑:向Beerlington的回答致意:

ruby - 反对在 RSpec 测试中使用 before、let 和 subject 的理由是什么?

关闭。这个问题是opinion-based.它目前不接受答案。想要改进这个问题?更新问题,以便editingthispost可以用事实和引用来回答它.关闭4年前。Improvethisquestion我刚开始编写RSpec测试,我遇到了thoughtbot'sStyleGuide,它反对let、let!、before和subject(以及其他)。我也在其他几个地方读过类似的建议(包括关于before(:all)的旧RSpecdocs警告),但我似乎找不到反对的实际论据他们。那么问题是:为什么我不应该在我的测试中使用这些方法?什么是更好的方法?

ruby - 在 Sinatra 中,你如何制作一个 "before"过滤器来匹配除某些路由之外的所有路由

我有一个RubySinatra应用程序,我有一些代码需要在除少数异常(exception)情况外的所有路由上执行。我该怎么做?如果我想在选定的路由(白名单样式)上执行代码,我会这样做:['/join',"/join/*","/payment/*"].eachdo|path|beforepathdo#somecodeendend我该如何反其道而行之(黑名单样式)?我想匹配除'/join'、'/join/*'和'/payment/*'之外的所有路由 最佳答案 负面前瞻:before/^(?!\/(join|payment))/do#..

ruby-on-rails - 有没有办法使 before_save 成为条件?

我正在尝试在Rails应用程序中进行有条件的before_save,但它似乎不起作用。before_savemethod_call_to_runifself.related_model.some_method_that_returns_t_or_f?如果“some_method_that_returns_t_or_f”返回true,我希望它在保存对象之前运行该方法,否则我只希望它忽略before_save。 最佳答案 你可以使用:ifbefore_savedo_something,:if=>Proc.new{|model|model

ruby RSpec : No color on output with a Mac

使用我的第一台Mac进行开发时,我注意到我的Rspec输出在我的终端中没有着色,即使我在命令中使用“-c”标志:bundleexecrspec-c-fd。有任何想法吗? 最佳答案 将以下内容添加到项目根目录的.rspec文件中。--颜色 关于rubyRSpec:NocoloronoutputwithaMac,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/9264773/