如何使用Rspec正确显示双引号马克的“”

时间:2017-11-21 18:46:43

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

我正在使用Rspec和gem file_validators进行测试,我需要正确地输出引用标记(“txt”)的输出,如:

import UIKit
import AudioKit

class ViewController: UIViewController {

    var microphone = AKMicrophone()
    var reverb = AKReverb()

    override func viewDidLoad() {
        super.viewDidLoad()

        microphone >>> reverb
        AudioKit.output = reverb
        AKSettings.ioBufferDuration = 0.002 // Optional, set this to decrease latency
        AudioKit.start()
    }
}

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."

2 个答案:

答案 0 :(得分:3)

单引号字符串:

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

other answers可以更好地解释单引号与双引号的详细信息。

答案 1 :(得分:1)

我把这个和工作:

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

谢谢@anothermh