草庐IT

expection

全部标签

ruby - 如何编写 expect {}.to raise_error when rspec's syntax is configured with only should

我在rspec上有这个配置:config.expect_with:rspecdo|c|c.syntax=:shouldend它使expect{}.toraise_error无效,我怎么能用should语法编写这个错误引发测试? 最佳答案 我建议仅在最新的RSpecexpect{code()}.toraise_error语法对您不可用时才使用它:lambda{foo(:bad_param)}.shouldraise_error或lambda{foo(:bad_param)}.shouldraise_error(ArgumentErro

ruby-on-rails - 我如何解决 "bad argument (expected URI object or URI string)"? Ruby on Rails,Michael Hartl 教程

我正在关注RubyonRailsTutorial作者:MichaelHartl。我到达了Chapter11.37但我的测试失败了。我收到以下错误:Failure/Error:xhr:post,:create,relationship:{followed_id:other_user.id}ArgumentError:badargument(expectedURIobjectorURIstring)我是RubyonRails的新手,所以我真的不知道出了什么问题。有人可以帮助解决此错误吗?controllers/relationships_controller.rb:classRelatio

ruby-on-rails - Michael Hartl 的 Rails 教程 : Rspec's "Expected response to be a redirect to ..." is wrong

在MichaelHartl的(精彩的)Rails教程中,我遇到了一个意外的Rspec测试失败的形式:"Expectedresponsetobearedirecttohttp://test.host/signin>butwasaredirecttohttp://test.host/signin?notice=Please+sign+in+to+access+this+page.>."(在第10.3节中找到它。)因此,从错误本身,您可以看出服务器正在重定向到适当的页面,除了有一个额外的通知“请登录”。测试代码如下所示:describe"GET'index'"dodescribe"forno

ruby-on-rails - "Association expected, got String"与多对多关联

目前我正在Rails3中创建类似“运动管理和结果收集应用程序”的东西。在这个应用程序中我需要创建几个练习,它们本身可以有多个“结果类型”(心率,距离公里,重复,...)。并且应该可以按照我喜欢的顺序排列结果类型。所以,这是一个经典的多对多关系。我提出了以下迁移:classCreateExercisestruet.timestampsendenddefself.downdrop_table:exercisesendendclassCreateResulttypesfalsedo|t|t.integer"exercise_id"t.integer"resulttype_id"endadd_

ruby - minitest - 将任何参数传递给 expect

我有以下代码用于模拟对类方法的调用:deftest_calls_update_profile_job_for_a_leadinput=ContactInput.newvalid_attributesmock=MiniTest::Mock.newuse_case=CreateContact.newuser,input,mockmock.expect(:perform_async,nil,[user.id,1,::Contact])use_case.run!assertmock.verifyend问题是我必须传递特定值-[user.id,1,::Contact]使测试通过。有没有一种方法我

ruby-on-rails - 失败 : Expected 0 to be >= 1 on ruby on rails

我正在做Hartle教程,每次运行rake测试时我都会看到这个失败:1)Failure:StaticPagesControllerTest#test_should_get_help[.../sample_app/test/controllers/static_pages_controller_test.rb:14]:expectedbutwas..Expected0tobe>=1.这是什么意思?我该如何解决?这是我的static_pages_controller_test.rb文件。require'test_helper'classStaticPagesControllerTest这是

ruby - rspec : it { is_expected. 中的这个符号是什么...}

我正在阅读'Betterspecs'页面,并在其中一个示例中说:context'whenloggedin'doit{is_expected.torespond_with200}endcontext'whenloggedout'doit{is_expected.torespond_with401}end我不认识这个。我通常会这样做:context'whenloggedout'doit'respondswitha401'doexpect(response).toeq(401)endend这是什么语法? 最佳答案 这是在Rspec3.XX

Ruby - Expect 和 Pty 的问题

我正在尝试编写一个Ruby脚本,它将通过ssh连接到服务器,运行给定的命令,并从中获取输出。这是我目前所掌握的,大部分改编自ProgrammingRuby书:require'pty'require'expect'$expect_verbose=truePTY.spawn("sshroot@x.y")do|reader,writer,pid|reader.expect(/root@x.y'spassword:.*/)writer.puts("password")reader.expect(/.*/)writer.puts("ls-l")reader.expect(/.*/)answer=

ruby-on-rails - rails 协会 :autosave doesn't seem to working as expected

我做了一个真正的基础github项目here这说明了这个问题。基本上,当我创建一个新评论时,它会按预期保存;当我更新现有评论时,它不会被保存。然而,这不是:autosave=>true的文档所说的……他们说的恰恰相反。这是代码:classPosttrue,:inverse_of=>:post,:dependent=>:destroydefcomment=(val)obj=comments.find_or_initialize_by(:posted_at=>Date.today)obj.text=valendendclassComment:commentsend现在在控制台中,我测试:p

ruby-on-rails - 与 Capybara (Rails) 的 TDD; page.should 和 expect(page).to 之间的区别?

我是Rails和测试驱动开发领域的新手。对于TDD,我使用的是RSpec和Capybara。目前,我正在编写教程以了解有关Rails的更多信息,作者使用以下语法:page.shouldhave_title('Allusers')expect(page).tohave_selector('li',text:user.name)由于两者似乎可以互换,我想知道何时使用哪种语法?因为,对于上述情况,我还可以这样写:page.shouldhave_title('Allusers')page.shouldhave_selector('li',text:user.name)这基本上是一样的,对吧?此