草庐IT

ruby-on-rails - rspec - 如何检查 allow_blank 是否存在

我有一个有效的唯一性测试:it{shouldvalidate_uniqueness_of(:name).case_insensitive}然而,当我尝试对名称进行类似的测试时,它失败了it{shouldvalidate_presence_of(:name).allow_blank}我得到这个错误:undefinedmethodallow_blank'` 最佳答案 根据thislist,shoulda中没有可以链接到validate_presence_of的方法来支持你想做的事情。看看thesourcecodeofthematcher

ruby - rspec: 'should_receive' 具有多个参数预期

我有一个接收复杂参数(HTML字符串)的函数。我想检查有关此字符串的多个条件,即:receiver.should_receive(:post_data).with(json_content).with(id_matching(5))多个with参数不起作用,还有其他选择吗?如果有可能以某种方式制作复合匹配器,我很乐意定义自定义匹配器。显然,我可以多次运行相同的测试并测试不同的结果,但这是一个需要几秒钟才能运行的集成测试,所以我不想让它变得更慢。谢谢编辑:在撰写本文时,公认的答案(使用带有自定义描述的自定义匹配器)似乎是最佳选择。然而它并不完美,理想情况下with将支持“这是预期类型的​

ruby-on-rails - RSPEC 未定义局部变量或方法 `response'

我收到有关...的“响应”错误规范/特征/test_name_spec.rbrequire"spec_helper"describe"thesigninprocess",:type=>:featuredoit"doesnotsignmeinifIusethewrongpassword"dovisit'/users/sign_in'within("#new_user")douser=Fabricate(:user,email:'user@example.com',password:'password')fill_in'Email',:with=>'user@example.com'fil

ruby-on-rails - rspec 测试 respond_to 格式和 csv

我想在我的rspecController中测试top_users是否等于User.top_users。我如何访问format.csv?我需要这样的东西:it"formatcsv"doget:index,format::csv#expect(something)……end稍后想测试csv:文件格式是否正确,不保存/下载它。Controller:defindexrespond_todo|format|format.csvdotop_users=User.top_userssend_data(top_users.to_csv,filename:"top-users-#{Time.zone.t

ruby-on-rails - RSpec - 找不到 spec/spec_helper.rb

我正在阅读MichaelHartl的RubyonRails4一书,但找不到spec/spec_helper.rb。这是他的书的链接http://ruby.railstutorial.org/ruby-on-rails-tutorial-book我正在研究第3章测试驱动开发部分。我运行这段代码来调用RSpec和static_pages_spec.rb$railsgenerateintegration_teststatic_pagesinvokerspeccreatespec/requests/static_pages_spec.rb在此之后,我需要将CapybaraDSL添加到RSpec

ruby - 难以在 Windows 上安装 RSpec

我正在尝试开始使用RSpec。我已经在我的Windows7机器上安装了Ruby1.8.7。所以我输入了geminstallrspec,这似乎有效。但是,如果我在命令行中键入spec,则找不到该命令。我的路径当前包括RUBY_HOME中的bin文件夹。如果我查看C:\Users\Eric\.gem\specs\rubygems.org%80\quick\Marshal.4.8目录,我确实看到了四个RSpec文件,例如rspec-core-2.5.0.gemspec。然而,spec命令即使在这个目录中也会失败。正确安装RSpec需要做什么?这似乎是一个路径问题,但我一直无法找到spec命令

ruby - Capybara-webkit、rspec 集成规范和 xvfb : webkit_server: Fatal IO error: client killed

我正在尝试使用headless(headless)gem、xvfb和用于headless(headless)测试的capybara-webkit来获得在ubuntu服务器CI盒上运行的一套集成规范。一切都在本地开发箱上运行良好,但一旦转移到CI服务器,事情就会变得有趣。在规范助手中有一些代码包装:js在headless(headless)block中启用集成规范,如下所示:config.around(:each,:js=>true)do|example|Headless.ly&exampleend就像我说的,这一切都在本地开发箱上运行良好。在CI上,它使用headless(headle

ruby-on-rails - Rspec NoMethodError : undefined method `call' , 但一切都通过 rails 控制台工作

我是一个正在努力学习的rails/rspec新手。我设置了以下数据模型(摘录)t.string:foot.string:bart.date:future_date我有一个Web表单来创建这些与用户关联的条目,类似于此railstutorial中的微博.Web表单如下所示(摘录):带有启动帖子的“创建”按钮。通过railsconsole似乎一切正常;Web表单显示正确,条目创建正确,数据库正确填充。但是,当我运行rspec时,我得到了NoMethodError:undefinedmethod`call'for#这是相关的请求规范(摘录):it"shouldnotcreateafoobar

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 - rspec spec 自动逻辑分组(按 "tags")

是否有任何现有的解决方案(最好是gem)来使用rspec运行一些规范片段?例如:rspec.#runswholetestsuiterspec.--keywords=project#runsallspecsthathave"project"keywordtheresomewhere或类似的东西? 最佳答案 您可以通过向描述、上下文或测试提供键值对来在rspec中使用标签,如下所示:describe"Asetoftests",:constraint=>'slow'describe"Anothersetoftests",:focus=>t