ruby-on-rails - 如何使用 Rspec 正确显示双引号的 ""

标签 ruby-on-rails ruby rspec html-safe

我正在使用 Rspec 和 gem file_validators 进行测试,我需要正确放置引号(“txt”)的输出,如下所示:

expect(page).to have_content expect(page).to have_content "You are not allowed to upload \"txt\" files, allowed types: jpg, jpeg, gif, png"

double_quotes = ""txt"".html_safe
expect(page).to have_content expect(page).to have_content "You are not allowed to upload #{double_quotes} files, allowed types: jpg, jpeg, gif, png"

但是我在显示这个时遇到了失败错误:

Failure/Error: expect(page).to have_content   expect(page).to have_content "You are not allowed to upload #{double_quotes} files, allowed types: jpg, jpeg, gif, png"
   expected to find text "You are not allowed to upload "txt" files, allowed types: jpg, jpeg, gif, png" in "News CityToggle navigationHomeAdminSigned in as rubie@fayvon.netSign out×Post has not been created.New Post* TitleSubtitleFileYou are not allowed to upload \"txt\" files, allowed types: jpg, jpeg, gif, png* Content It will serve for show images about the posts."

有人可以帮我解决这个问题吗? 整个输出需要像这样:

You are not allowed to upload "rtf" files, allowed types: jpg, jpeg, gif, png

最佳答案

单引号字符串:

expect(page).to have_content('You are not allowed to upload "txt" files, allowed types: jpg, jpeg, gif, png')

other answers更好地解释单引号与双引号的细节。

关于ruby-on-rails - 如何使用 Rspec 正确显示双引号的 "",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47420477/

相关文章:

ruby-on-rails - 在关联扩展中访问代理所有者的正确方法

ruby-on-rails - Omniauth-facebook : retrieve user location

ruby - Ruby 1.8.7 中的求幂返回错误答案

ruby-on-rails - Rails 中用户的备用电子邮件地址 - 我将如何验证唯一性,或者我的方法是否不正确?

ruby-on-rails - Rails 事件记录查找 ( :all, :order => ) 问题

ruby-on-rails - Ruby -::in 类名

ruby-on-rails-3 - RoutingError 与 RSpec Controller 对作用域路由进行测试

ruby-on-rails - RSPEC 找到了我的文件,但找不到我的示例

ruby - 使用 RSpec(LeakyConstantDeclaration 问题)生成不泄漏的动态测试的最佳方法?

ruby-on-rails - '无方法错误 : undefined method `scan' for nil:NilClass' when functional testing with rails