i would like to mock 开发者_如何学Goa web service response. The response is a XML, and contains both simple quotes and double quotes.
The response is pretty big, so here are my solutions:
trim the response to make it smaller and backslash the simple quotes for example
backslash the simple quotes for example
add the response to a file and parse it
But the thing is, I'd like to test a large response, and not create a resource test folder with a file. And as you can imagine, backslashing everything is long and boring.
I also tried the triple double quote, not working of course.
How would you do it?
You could use Ruby here documents.
xml = <<DOC
<xml>
<food attribute="soup">'eel'</food>
</xml>
DOC
use the %Q
operator
a = :jed
%Q| "these double quotes are ignored" for as
long as you can type says #{a}
|
any start end delimiters work so if you are using tables in cucumber for example you can use backticks instead of pipes
→ irb
ruby-1.9.2-p0 > str = <<-STR
ruby-1.9.2-p0"> ' single quote
ruby-1.9.2-p0"> " double quote
ruby-1.9.2-p0"> STR
=> "' single quote\n" double quote\n"
ruby-1.9.2-p0 >
精彩评论