草庐IT

expectation-maximization

全部标签

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)这基本上是一样的,对吧?此

c++ - 如何修复 C++ 错误 : expected unqualified-id

我在第6行收到此错误:error:expectedunqualified-idbefore'{'token我不知道出了什么问题。#includeusingnamespacestd;classWordGame;{//>aWord;theGame.setWord(aWord);theGame.displaymessage();} 最佳答案 这里不应该有分号:classWordGame;...但是在你的类定义的末尾应该有一个:...private:stringtheWord;};// 关于c+

c++ - 如何修复 C++ 错误 : expected unqualified-id

我在第6行收到此错误:error:expectedunqualified-idbefore'{'token我不知道出了什么问题。#includeusingnamespacestd;classWordGame;{//>aWord;theGame.setWord(aWord);theGame.displaymessage();} 最佳答案 这里不应该有分号:classWordGame;...但是在你的类定义的末尾应该有一个:...private:stringtheWord;};// 关于c+

C++模板编译错误: expected primary-expression before ‘>’ token

这个问题在这里已经有了答案:WhereandwhydoIhavetoputthe"template"and"typename"keywords?(8个回答)关闭6个月前。此代码按预期编译和工作(它在运行时抛出,但没关系):#include#includevoidfoo(boost::property_tree::ptree&pt){std::cout("path");//但只要我添加模板并更改foo原型(prototype)成templatevoidfoo(ptree&pt)我在GCC中遇到错误:test_ptree.cpp:Infunction‘voidfoo(ptree&)’:te

C++模板编译错误: expected primary-expression before ‘>’ token

这个问题在这里已经有了答案:WhereandwhydoIhavetoputthe"template"and"typename"keywords?(8个回答)关闭6个月前。此代码按预期编译和工作(它在运行时抛出,但没关系):#include#includevoidfoo(boost::property_tree::ptree&pt){std::cout("path");//但只要我添加模板并更改foo原型(prototype)成templatevoidfoo(ptree&pt)我在GCC中遇到错误:test_ptree.cpp:Infunction‘voidfoo(ptree&)’:te