我一直在尝试使用RSpec测试OmniAuth,但它没有奏效。在spec_helper.rbOmniAuth.config.test_mode=trueOmniAuth.config.add_mock(:twitter,{:uid=>'12345'})并且在spec/requests/static_pages_spec.rbdescribe"forsigned-inusers"dobeforedovisit"auth/twitter"endit{shouldhave_content("Logout")}end然后出现以下错误。Failure/Error:visit"auth/twitt
当我添加一个guard-rspecgem并将Guardfile设置为:guard:rspec,cmd:'bundleexecrspec'dowatch('spec/spec_helper.rb'){"spec"}watch('config/routes.rb'){"spec/routing"}watch('app/controllers/application_controller.rb'){"spec/controllers"}watch(%r{^spec/.+_spec\.rb$})end然后运行rubocop检查:rakerubocop:rubocop它显示:Guardfile:
我正在尝试让通过RubyMine创建的项目运行。我有一个终极版本的IntelliJ,我更愿意将它与Ruby插件一起使用来运行这些测试。然而,当我尝试运行时,我收到一条错误消息“在SDK中找不到Rspecgem”。我没有我的Gem环境是这样的:mac:~cmietzner$gemenvironmentRubyGemsEnvironment:-RUBYGEMSVERSION:2.4.7-RUBYVERSION:2.2.1(2015-02-26patchlevel85)[x86_64-darwin14]-INSTALLATIONDIRECTORY:/Users/colemietzner/.r
我当前的代码如下所示:/spec/support/spec_test_helper.rbmoduleSpecTestHelperdeflogin_adminuser=FactoryGirl.create(:user,type:0)session[:user_id]=user.idendend/app/controllers/application_controller.rbdefcurrent_userifsession[:user_id].nil?renderplain:'Error',status::unauthorizedelse@current_user||=User.find
我有一个UserMailDispatcher类,它的工作是根据特定条件通过ActiveMailer发送邮件。我正在尝试使用RSpec对其进行测试,但效果不佳。我想以某种方式stub测试邮件并查看该类是否正确传递它。这是我到目前为止所拥有的:我所有的邮件程序都继承自ApplicationMailer:application_mailer.rbclassApplicationMaileruser_mail_dispatcher_spec.rbrequire'rails_helper'describeUserMailDispatcherdoclassUserMailer我想测试调度程序是否可
Thisquestion告诉我如何测试来自RSpec模型和Controller规范的记录器语句。不幸的是,它似乎不适用于功能规范。使用此代码:#controller.rbdefactionlogger.info'foobar'end#spec.rbscenario'loggingshouldwork'doexpect(Rails.logger).toreceive(:info).with('foobar')visitaction_pathend我得到错误:Failure/Error:visitaction_path#received:infowithunexpectedargument
我需要对具有特定属性或属性集的模型的所有实例进行stub。例如,使用ActiveRecord:let(:model1){Model.create!(uid:1)}let(:model2){Model.create!(uid:2)}beforedoallow(model1).toreceive(:foo).and_return:barallow(model2).toreceive(:foo).and_return:bazenditdoexpect(model1.foo).toeq:bar#=>passesexpect(model2.foo).toeq:baz#=>passes######
我在将Rails5.0.1应用程序升级到Rails5.1的过程中遇到了一些弃用警告。除了一个,我能够解决所有问题。我做了一些搜索,但没有找到明确的答案。背景这是一个刚刚完成的应用程序。我刚刚将Rails版本更新到5.1我有一些RSpec请求规范。他们在(设计)登录中测试重定向。该错误出现在这些规范中。Controller规范运行良好。我在有关css、js、图像等的请求规范中看到此警告。Assets管道中确实有dashboard.js。还有一个app/assets/javascripts/dashboard.coffee文件。#config/initializers/assets.rbR
我想测试我的bash脚本将一些消息输出到stderr。我试试这个:require'rspec'describe'Mybehaviour'doit'shoulddosomething'doexpect{`echo"foo"1>&2`}.tooutput.to_stderrendend但似乎在测试期间没有输出到stderr。 最佳答案 RSpec的output.to_stderr匹配器正在寻找写入$stdout/$stderr的东西——你的shell命令没有这样做,因为它作为一个单独的子进程运行。为了对此进行测试,您需要明确捕获shel
这完全是愚蠢和不重要的,但我只是好奇:使用RSpec,我能以某种方式访问我所处范围的“深度”吗?那就是……describeSomeClassdodescribe"#some_method"docontext"withinsomecontext"doit"ispossible,whatI'masking"do#Actually,I'mnotentirelysurewhatI'dexpectthis#valuetobe...basically,whatevertheRSpecdesigners#feltmadesense.mysterious_method_to_get_depth.s