草庐IT

ruby-on-rails - 使用 Rspec + Factory Girl 在新线程/进程测试中数据库为空

在这篇博文之后,http://blog.arkency.com/2015/09/testing-race-conditions/我正在尝试测试并发性。但是在我的规范中,当我启动一个新线程或fork一个进程时,我无法找到记录。describe'testconcurrency'dolet(:order_1){create(:order)}let(:order_2){create(:order)}let(:order_3){create(:order)}let(:order_4){create(:order)}let(:product){create(:product)}it'testcon

ruby - RSpec 和 Open-URI 我如何模拟引发 SocketError/TimeoutError

我希望能够说明当Open-Uriopen()调用超时或引发诸如SocketError之类的异常时,我正在按预期处理事情,但是我在这方面遇到了麻烦。这是我的规范(针对SocketError):@obj.should_receive(:open).with("some_url").and_raise(SocketError)以及我使用open-uri的对象部分:beginresp=open(url)resp=resp.readrescueSocketErrorsomething=trueend然而,在这种情况下,规范会失败,出现nil.read错误。这是我这周第二次遇到这个问题,上一次我试

ruby - 干燥 RSpec 中的重复规范

在下面的测试中,Bar和Bazblock包含相同的规范。首先撇开为什么需要这样的重复不谈,我想知道如何才能把它干掉。我尝试将block转换为对象并在Bar和Baz下调用它们,但可能是因为我没有获得正确的范围,我无法使其工作。describeFoododescribeBardobefore(:each)doprepareendit"shoulddosomething"dotrueendit"shoulddosomethingelse"dotrueendenddescribeBazdobefore(:each)doprepare_something_elseendit"shoulddoso

ruby-on-rails - 使用 RSpec 和 Haml 测试嵌套布局助手

在ApplicationHelper中我有这样的代码:definside_layoutlayout='application',&block@template.instance_variable_set'@content_for_layout',capture(&block)concat\@template.render:file=>"layouts/#{layout}",:use_full_path=>trueend它的行为是这样的:应用程序.html.haml:!!!%html%head...%body=yieldcommon_pages.html.haml:-inside_lay

ruby - 在 Padrino 上模拟 current_account 以进行 rspec 测试

我正在尝试测试依赖于Padrino::Admin::AccessControl提供的current_account的padrinoController为此,我需要模拟current_account。代码是这样的:App.controller:postdopost:create,map=>'/create'doPost.create:user=>current_accountendend和rspec:describe"Postcreation"doit'shouldcreate'doaccount=Account.create:name=>'someone'loggin_asaccoun

ruby-on-rails - Rspec capybara 用户无法登录

测试设计使用capybara登录。似乎出了点问题,因为我无法使用rspec和capybara测试登录。我使用工厂女孩来定义用户FactoryGirl.definedofactory:userdoemail'admin@revol-tech.com.np'password'bhaktapur'password_confirmation'bhaktapur'admintruename'admin'confirmation_sent_at"#{DateTime.now}"confirmation_token'anupsumhikichiki'confirmed_at"#{DateTime.n

ruby - 我可以给 RSpec 匹配器取别名吗?

我得到了这两个匹配器,除了它们的名字之外是相同的:RSpec::Matchers.define:be_the_downcased_version_ofdo|actual|matchdo|actual|@actual=actual@expected=expected@actual==@expected.downcaseendfailure_messagedo|actual|"Expected#{@actual.inspect}tobethedowncasedversionof#{expected.inspect}.\nItwasnot:#{@actual.inspect}"endfail

ruby - 如何在之前访问标签过滤器(:suite)/before(:all) hook in RSpec?

我想访问命令行传递的标签过滤器命令行rspec--taguse_ffRSpec配置RSpec.configuredo|config|config.before:suite,type::featuredo#howdoIcheckifuse_fffilterwasspecifiedinthecommandline?iffilter[:use_ff]use_seleniumelseuse_poltergeistendendend在before(:suite)钩子(Hook)中,我想访问在配置的命令行中指定的标签过滤器。根据rspec-core代码库,包含标签过滤器存储在inclusion_f

ruby-on-rails - rspec-given 错误 `Then` 在示例中不可用(例如 `it` block )

我正在使用rspec-given并不断收到此错误。失败/错误:然后{Then在示例中(例如itblock)或在示例范围内运行的构造(例如before,let等)。它仅适用于示例组(例如describe或contextblock)。describeSchoolServicedoGiven(:school){create(:school_with_applications)}Given(:service){School.new(@school)}describe'create_default_programs_and_year_grades!'doit'checksprogramsize'

ruby-on-rails - 如何模拟 RSpec 期望语法中的类方法?

我对如何使用新的expect语法模拟类方法感到困惑。这有效:Facebook.should_receive(:profile).with("token").and_return({"name"=>"Hello","id"=>"14314141","email"=>"hello@me.com"})这不是:facebook=double("Facebook")allow(facebook).toreceive(:profile).with("token").and_return({"name"=>"Hello","id"=>"14314141","email"=>"hello@me.com