Ruby and Cucumber - What Does It Mean? "([^"] *) "$ /
I'm just trying to figure out what the below means in Ruby.
"([^"]*)"$/
I have the following sample code in Ruby using cucumber at the moment:
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
At the moment I understand that it does a boolean check that the button is clicked. I researched a bit and found the following for symbolic values in Ruby (as I'm new to Ruby)
? = method returns a boolean value.
$ = global variable
@ = instance variable
@@ = class variable.
^ = bitwise XOR operator.
* = unpack array
I can't figure out what the command is doing. I am trying to clarify how functions are related to variables and I think this is the final clue for me.
Thanks a lot for any help.
source to share
This is a regular expression. The expression is contained between the "/" characters.
As an example and using your code:
/^I have entered "([^"]*)" into the query$/
interpreted as a string that:
- Matches start of line (^)
- Matches "I entered"
- Matches one quote
- (") Matches anything that is not a quote (([^"] *))
- Matches "request"
- Matches one quote (")
- Matches end of line $
For more information on Ruby and Regular expressions, see http://www.tutorialspoint.com/ruby/ruby_regular_expressions.htm .
source to share