草庐IT

ruby-on-rails - 将 RSpec 与 Ruby on Rails 结合使用的国际字符

我刚刚开始使用RSpec,我在RSpecgithub存储库上复制了非常简单的测试,以确保一切按预期工作:require'spec_helper'describe'HomePage'doit"Welcomestheuser"dovisit'/products'page.shouldhave_content("Welcome")endend当我将字符串更改为“Olá”或“Caçamba”之类的字符串时,问题就开始了。任何带有特殊字符的字符串。当我这样做时,出现以下错误:invalidmultibytechar(US-ASCII)(SyntaxError)invalidmultibytech

ruby-on-rails - 是否可以添加 "somewhere"一个 `before(:each)` Hook ,以便所有规范文件都可以运行它?

我正在使用RubyonRails3.2.2和rspec-rails-2.8.1。为了使我的规范文件干(不要重复自己)并为测试数据库做种子,我想运行一个before(:each)Hook所有这些规范文件。也就是说,在我所有的规范文件中,我都有以下代码:describe'testdescription'dobefore(:each)doload"#{Rails.root}/db/seeds.rb"end...end是否可以在before(:each)Hook的“某处”添加,以便所有规范文件都可以运行它?您有什么建议? 最佳答案 在spe

ruby-on-rails - Ruby VCR gem 不断记录相同的请求

在我的cucumber支持目录中,我在vcr.rb中有以下内容:require'vcr'VCR.configuredo|c|c.cassette_library_dir='fixtures/vcr_cassettes'c.hook_into:webmockc.ignore_localhost=truec.default_cassette_options={record::new_episodes}end我正在对调用GoogleMapsAPI的城市名称进行地理编码。我正在尝试记录并stub这些请求,但它一直将相同的请求记录到同一个yml文件:-request:method:geturi:

ruby-on-rails - 来自测试控制台的 RSpec 模拟

我想从Rails测试控制台测试RSpecstub和模拟。是否可以?如果是,怎么办?这是我试过的:$railsctest>require"./spec/spec_helper"true>source=double('source')NoMethodError:undefinedmethod`double'formain:Object 最佳答案 您需要要求'rspec/mocks/standalone',如statedinthedocumentation. 关于ruby-on-rails-来

ruby - rails rspec - 如何检查模型常量?

我该如何做:it{shouldhave_constant(:FIXED_LIST)}在我的模型(事件记录)中,我有FIXED_LIST='AString'它不是数据库属性或方法,我无法使用responds_to或has_attribute对其进行测试(它们失败了)。我可以用什么来检查它。-顺便说一句,我安装了shoulda-matchers。 最佳答案 根据DavidChelimsky的回答,我通过稍微修改他的代码使它起作用。在文件spec/support/utilities.rb(或spec/support中的其他文件)中,您可以

ruby-on-rails - Rspec:检查数组是否包含包含属性的对象

我有一个充满对象的json数组。my_array=[{id=>6,name=>"bob"},{id=>5,name=>"jim"},{id=>2,name=>"steve"}]我需要查看数组是否包含一个对象,该对象包含设置为5的属性“id”。“name”属性未知。我如何在rspec中执行此操作?我知道如果我有name属性我知道我可以这样做:my_array.shouldinclude({:id=>5,:name=>"jim"}) 最佳答案 expect(myArray.find{|item|item[:id]==5}).to_not

ruby-on-rails - rspec 在失败测试中的未决结果

it'shouldbeanarrayandnotbeempty'dopendingexpect(a.class).tobe(Array)expect(a.empty?).tobe(false)expect(a.first.class).tobe(ExampleClass)end当我运行rspec时:Failures:1)shouldbeanarrayandnotbeemptyFIXEDExpectedpending'Noreasongiven'tofail.NoErrorwasraised.#./spec/example_spec.rb:19知道为什么这会被列为失败吗?

ruby-on-rails - 使用服务对象的 Pundit 授权

工具Pundit授权;试验thispullrequest链接到官方Pundit自述文件;ActiveInteraction域服务对象(“DSO”);RSpec2.99.1**项目**项目仓库在Github上;这里正在审查的是pundit-1branch.我遵循了Pundit教程并获得了使用“传统”胖Controller工作的授权;看thePostsController#newaction和itsspec;thePunditApplicationPolicyclass;和thePostDataPolicy管理Posts的Rails模型实例的授权。到目前为止一切都很好。然后我们来到Sess

ruby-on-rails - 测试包含 ActionController::Live 的 Controller

我有一个包含RailsActionController::Live模块的Controller。我正在显示一个日志文件的内容,它正在使用FileTailgem读取,并使用ActionController::Live中的SSE像这样:classLogsControllereRails.logger.info"ErrorMessage::#{e.message}"ensuresse.closeendend我想使用Rspec测试live操作。这是我目前拥有的:before{get:live}it{expect(response.headers['Content-Type']).toeq("te

ruby - 使用 Rspec 2 和 Mocha 获取 Rails 3 生成器

我已经按照我能够在网上找到的使用Rspec2和Mocha配置Rails3的所有步骤进行操作。在我的Gemfile中:group:developmentdogem'rails3-generators'gem"rspec",'>=2.0.0.beta.19'gem"rspec-rails",'>=2.0.0.beta.19'endgroup:testdogem"faker"gem"rspec",'>=2.0.0.beta.19'gem"rspec-rails",'>=2.0.0.beta.19'gem"machinist",'>=2.0.0.beta1'gem"mocha"gem"capy