草庐IT

the_mock

全部标签

ruby /Rspec : Possible to compare the content of two objects?

我在ruby​​中创建了2个不同的对象,它们具有完全相同的属性和值。现在我想比较两个对象的内容是相同的,但进行以下比较:actual.should==expectedactual.shouldeq(expected)actual.should(beexpected)失败:Diff:@@-1,4+1,4@@-#在rspec/ruby中有什么方法可以轻松实现这一点吗?干杯! 最佳答案 执行此操作的惯用方法是覆盖#==运算符:classStationdef==(o)primary_key==o.primary_keyenddefhashp

ruby - 是否有与 Rspec 的 “mock().as_null_object” 等效的 Mocha?

是否有与Rspec的“mock().as_null_object”等效的Mocha? 最佳答案 是的。使用“stub_everything()”记录在此处:http://mocha.rubyforge.org/classes/Mocha/API.html#M000004. 关于ruby-是否有与Rspec的“mock().as_null_object”等效的Mocha?,我们在StackOverflow上找到一个类似的问题: https://stackover

ruby-on-rails - rails 上的 ruby : Yielding specific views in a specific places in the layout

如果我有一个标记然后我的所有View都呈现在布局中的同一位置。我可以有不同的不同观点的标签?那么我该怎么做呢?谢谢 最佳答案 查看ActionView::Helpers::CaptureHelper.你可以在你的View中做这样的事情:这将在content_forblock中运行模板,但不会作为常规模板的一部分输出yield缓冲区,它将存储在一个单独的缓冲区中以备后用。然后稍后,包括在布局中,您可以使用yield:content_name输出内容:所以在某种意义上你可以有不同的yield对于不同的View,你只需要给不同的内容一个名

ruby-on-rails - rails 2 : test 'link_to' and other view helpers from the rails console?

在Rails2中,我经常使用控制台,并且想知道使用它测试View助手(例如“link_to”或“url_for”)的最佳方法是什么。执行此操作的最佳方法是什么? 最佳答案 您可以将您的includeActionView::Helpers::UrlHelper添加到~/.irbrc以在您启动控制台时自动加载它。 关于ruby-on-rails-rails2:test'link_to'andotherviewhelpersfromtherailsconsole?,我们在StackOverfl

ruby-on-rails - rails : How to test if an attribute of a class object is required in the model policy?

简单地说,我有一个模型用户,其中包含名称、电子邮件和评论作为属性。validates_presence_of:namevalidates_presence_of:email所以“姓名”和“电子邮件”是必需的,但不是“评论”。my_user=User.new我想找到一种方法来测试像my_user.name.required?或User.name.required?类似的东西。我的目标是创建一个表单,并根据该项目是否设置为“validates_presence_of”,将特定类动态添加到表单项目span或td我试图搜索它,但没有找到任何相关信息。有没有简单的方法可以做到这一点?谢谢

ruby-on-rails - postgresql 数据库错误 : Is the server running locally and accepting connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?

当我运行rakedb:migrate或运行railss命令时,我得到同样的错误:Error:couldnotconnecttoserver:NosuchfileordirectoryIstheserverrunninglocallyandacceptingconnectionsonUnixdomainsocket"/var/run/postgresql/.s.PGSQL.5432"?当我尝试railss时,浏览器出现错误。这是我的database.ymldefault:&defaultadapter:postgresqlencoding:unicodepool:5development

ruby 正则表达式 : capture the path of url

我想从任何URL中提取其路径。例如:网址:https://stackoverflow.com/questions/ask路径:questions/ask应该不难:url[/(?:\w{2,}\/).+/]但我认为我使用了错误的模式来“忽略这个”('?:'-不起作用)。什么是正确的方法? 最佳答案 我建议您不要使用正则表达式来执行此操作,而是使用内置的URI库:require'uri'uri=URI::parse('http://stackoverflow.com/questions/ask')putsuri.path#results

ruby-on-rails - 助手设计 : could not find the `Warden::Proxy` instance on request environment

我尝试将Devise用于我的Rails应用程序。我可以注册并登录,但是当我转到其他页面“构建”时,出现以下错误:Devise::MissingWardeninHome#showDevisecouldnotfindtheWarden::Proxyinstanceonyourrequestenvironment.MakesurethatyourapplicationisloadingDeviseandWardenasexpectedandthattheWarden::Managermiddlewareispresentinyourmiddlewarestack.Ifyouareseeing

ruby-on-rails - cucumber + capybara : Problem with a scenario that redirects the browser outside of my app

GivenIhavearailsappAndI'musingcucumberAndI'musingcapybaraAndIhaveanactionthatresultsinaredirect_to"http://some.other.domain.com/some_path"WhenItestthisactionThenthein-appportionofthetestworksfineButIseethiserror:Noroutematches"/some_path"with{:method=>:get}(ActionController::RoutingError)所以capyb

ruby-on-rails - slim 的模板 : Is it possible to put two elements on the same line?

我经常想嵌套元素,比如下面的导航:ullia(href="#")linkNamelia(href="#")linkNamelia(href="#")linkName是否可以将li和a放在同一行?像li>a这样的语法会很好。 最佳答案 我相信你可以做这样的事情ulli:ahref="#"Link1li:ahref="#"Link2参见内嵌标签:http://rdoc.info/gems/slim/file/README.md#Inline_tags 关于ruby-on-rails-slim