Convierta la asociación de rieles a la sintaxis de shouldamatcher usando expresiones regulares
Frecuentes
Visto 56 equipos
0
I am working on a ruby on rails project. I am trying to convert
'has_many :comments,:as=>:entity,:order=>"id asc", :dependent => :destroy'
verse así
it { should have_many(:comments).as(:entity).order("id asc").dependent(:destroy)}
I am almost successful in doing so . The only problem I face is in a part of it. The regex I am using to find the key value pairs inside the string is
'has_many :comments,:as=>:entity,:order=>"id asc", :dependent => :destroy'.scan(/:\w+\s*=>\s*.\w+/)
que regresa
#=> [":as=>:entity", ":order=>\"id", ":dependent => :destroy"]
Its not able to return the full string inside any of the values. It just takes the first word which is quite evident from the regex.
I want a result like this :
#=> [":as=>:entity", ":order=> "id asc", ":dependent => :destroy"]
1 Respuestas
0
Prueba este:
'has_many :comments,:as=>:entity,:order=>"id asc", :dependent => :destroy'.scan(/:\w+\s*=>\s*.[\w \"\']+/)
Respondido 12 Feb 14, 09:02
No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas ruby-on-rails regex or haz tu propia pregunta.