简体   繁体   English

红宝石和黄瓜 - 这是什么意思? “([^”] *)“$ /

[英]Ruby and Cucumber - What does this mean? “([^”]*)"$/

I am just trying to figure out what the below means in Ruby. 我只想弄清楚以下Ruby中的含义。

"([^"]*)"$/   

I have the following code sample in Ruby using cucumber at the moment: 我现在使用黄瓜在Ruby中有以下代码示例:

require "watir-webdriver"
require "rspec/expectations"

Given /^I have entered "([^"]*)" into the query$/ do |term|
   @browser ||= Watir::Browser.new :firefox
   @browser.goto "google.com"
   @browser.text_field(:name => "q").set term
end

When /^I click "([^"]*)"$/ do |button_name|
   @browser.button.click
end

Then /^I should see some results$/ do
  @browser.div(:id => "resultStats").wait_until_present
  @browser.div(:id => "resultStats").should exist
  @browser.close
end

I understand at the moment that it is doing a logic check that a button has been clicked. 我现在明白它正在进行逻辑检查,点击了一个按钮。 I did a bit of research around and found the following for symbal meanings in Ruby (as I am new to Ruby) 我做了一些研究,并发现以下Ruby中的符号含义(因为我是Ruby的新手)

? = method returns a boolean value.   
$ = global variable   
@ = instance variable   
@@ = class variable.   
^ = bitwise XOR operator.   
* = unpack array 

I cannot see to find what the command does. 我看不到找到命令的作用。 I am trying to clarify exactly how functions are linked to variables and I think this is the final clue for me. 我试图澄清函数如何与变量相关联,我认为这是我的最终线索。

Many thanks in advance for any help. 非常感谢您的帮助。

It's a regular expression. 这是一个正则表达式。 The expression is contained between the "/" characters. 表达式包含在“/”字符之间。

By way of an example and using your code: 通过示例并使用您的代码:

/^I have entered "([^"]*)" into the query$/

is interpreted as a string that : 被解释为一个字符串:

  • Matches the beginning of the line (^) 匹配行的开头(^)
  • Matches "I have entered" 匹配“我已进入”
  • Matches a single quote 匹配单引号
  • (") Matches everything that is not a quote ( ([^"]*) ) (“)匹配不是引用的所有内容(([^”] *))
  • Matches " into the query" 匹配“进入查询”
  • Matches a single quote (") 匹配单引号(“)
  • Matches the end of the line $ 匹配行的结尾$

See http://www.tutorialspoint.com/ruby/ruby_regular_expressions.htm for more information on Ruby and Regular expressions. 有关Ruby和Regular表达式的更多信息,请参见http://www.tutorialspoint.com/ruby/ruby_regular_expressions.htm

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM