草庐IT

expected_conditions

全部标签

ruby-on-rails - expect() 在 rspec/cucumber 中做了什么?

在MichaelHartl的RailsTutorial中,许多示例使用expect()方法。这是cucumber步骤定义中的一个这样的例子:Then/^sheshouldseeherprofilepage$/doexpect(page).tohave_title(@user.name)end同样的例子可以写成同样的效果:Then/^sheshouldseeherprofilepage$/dopage.shouldhave_title(@user.name)end为什么要使用expect()?它增加了什么值(value)? 最佳答案

ruby - "string literal in condition"是什么意思?

每当我尝试运行该程序时,都会弹出一条错误消息“条件字符串文字(第10行)”。我做错了什么?puts"Welcometothebestcalculatorthereis.Wouldyouliketo(a)calculatetheareaofageometricshapeor(b)calculatetheequationofaparabola?Pleaseenteran'a'ora'b'togetstarted."response=gets.chompifresponse=="a"or"A"puts"ok."elsifresponse=="b"or"B"puts"awesome."else

ruby-on-rails - 每当 gem : I set :output but the logfile doesn't show up where I'd expect it to

在我的schedule.rb文件中,我有以下几行:set:output,'/log/cron_log.log'every5.minutesdocommand'echo"hello"'end我按照这个问题Rails,usingwhenevergemindevelopment中的建议运行了whenever-w,并且我假设cronfile已编写并正在运行。(我也尝试重新启动Rails服务器。)当我运行$crontab-l时,我看到以下内容:0,5,10,15,20,25,30,35,40,45,50,55****/bin/bash-l-c'echo"hello">>/log/cron_log

ruby-on-rails - 类型错误 : wrong argument type String (expected Module)

我有以下代码:classProfileLookup基本上包含大量查找数据,按类别拆分。目的是为数据库中的每个类别创建一个方法。通过Rails控制台,此代码按预期工作:ruby-1.9.3@hub:002>ProfileLookup.available_gendersProfileLookupLoad(0.6ms)SELECT"profile_lookups".*FROM"profile_lookups"WHERE"profile_lookups"."category"='gender'ORDERBYvalue=>["Female","Male"]但是,我的规范不合格。以下规范:requ

ruby - Sinatra::Base.condition 实际上做了什么?

我遇到了sinatracondition方法,但对它的工作原理感到困惑。我有一段代码:defauthuserconditiondoredirect'/login'unlessuser_logged_in?endend它检查用户是否登录了某些路由,示例路由:get'/',:auth=>:userdoerb:indexenduser_logged_in?方法定义在项目lib目录下的帮助文件中:defuser_logged_in?ifsession[:user]@user=session[:user]return@userendreturnnilend所以,问题是:conditionbloc

ruby - 在描述之外使用 RSpec 的 "expect"等...它会阻止

我正在构建一个网络应用程序自动化框架,旨在允许:当然是自动化任务轻松构建测试场景我正在使用Capybara与浏览器通信,我有一个组件库,其中包含许多辅助函数(login_to_the_back_office、create_customer等)。现在我希望我的组件可以独立使用,也可以在RSpec测试中使用。这意味着我的组件(包含在库中)没有环绕describe...it...默认情况下会阻塞,但在测试使用它们时它们会在某个时候出现,因此它们应该使用expect和friend尽可能多。我关注了rspec's.shouldfails(outsidedescribe/itblock)inRub

ruby-on-rails - rails 4 : how to use OR between conditions on find methods

我的问题类似于thisone,但那里的答案都没有解决我的具体问题。我想找到类似这样的对象:conditions={first_name:@searchORlast_name:@search}Stuff.where(conditions)显然,这种语法是无效的,但这是我能想到的展示我想做的事情的最简单的方法。我想在复杂/复合条件下使用更简洁的哈希语法。我知道你可以用像这样的“纯字符串条件”手写出来Stuff.where("first_name=#{@search}ORlast_name=#{@search}")...但这不是我想知道的。更新看起来您可以对这样的数组执行OR:Stuff.w

ruby-on-rails - ArgumentError : Unknown key: :conditions. 有效键是 : :class_name, :class, :foreign_key

在尝试rake:dbmigrate之后,我在终端中得到了这个错误rakeaborted!ArgumentError:Unknownkey::conditions.Validkeysare::class_name,:class,:foreign_key,:validate,:autosave,:table_name,:before_add,:after_add,:before_remove,:after_remove,:extend,:primary_key,:dependent,:as,:through,:source,:source_type,:inverse_of,:counter

ruby-on-rails - 如何格式化多行 RSpec expect {}.to change

是否有更好的方法来格式化此测试以使其更具可读性?expect{within'.foo'doclick_link'Delete'end}.tochange{Foo.count}.by1期望do...end有效,但更丑陋... 最佳答案 也许是这样的?expected=expectdowithin'.foo'doclick_link'Delete'endendexpected.tochange{Foo.count}.by1不是很漂亮,但减少了一些线路噪音。 关于ruby-on-rails-如

ruby 习语 : predicates and the conditional operator

我喜欢明智地使用三元条件运算符。在我看来,它非常简洁。但是,在ruby​​中,我发现我经常测试谓词方法,它们已经有了自己的问号:some_method(x.predicate??foo:bar)这两个问号靠得太近让我感到震惊。是否有同等紧凑和可读的替代方案? 最佳答案 C中需要条件运算符的原因是,条件语句是一个语句,即它不(也不能)返回值。所以,如果你想从条件代码中返回一个值,那你就不走运了。这就是必须添加条件运算符的原因:它是一个表达式,即它返回一个值。然而,在Ruby中,条件运算符是完全多余的,因为无论如何Ruby都没有语句。一