I'm trying to call a step that takes an argument in an another step definitions but i'm getting an error like
Cucumber::UndefinedDynamicStep: Undefined dynamic step: "And user
select Electronics as category group from dropdown list"
.feature file
And user fill the create new category form "Electronics"
.rb file
And(/^user fill the create new category form "([^"]*)"$/) do |name|
step "And user type name #{name}"
And(/^user type name "([^"]*)"$/) do |name|
find(:id, 'namePanelGroup').set(name)
end
How can i handle with this situation?
You need to add escaped double quotes because the step you are calling has double quotes around the regex, and you need to remove the "And" like so:
step "user type name \"#{name}\""
Related
I am trying to implement a FormAction here, and I’ve overridden validate method.
Here is the code for the same:
def validate(self, dispatcher, tracker, domain):
logger.info("Validate of single entity called")
document_number = tracker.get_slot("document_number")
# Run regex on latest_message
extracted = re.findall(regexp, tracker.latest_message['text'])
document_array = []
for e in extracted:
document_array.append(e[0])
# generate set for needed things and
document_set = set(document_array)
document_array = list(document_set)
logger.info(document_set)
if len(document_set) > 0:
if document_number and len(document_number):
document_array = list(set(document_array + document_number))
return [SlotSet("document_number", document_array)]
else:
if document_number and len(document_number):
document_array = list(set(document_array + document_number))
return [SlotSet("document_number", document_array)]
else:
# Here it doesn't have previously set slot
# So Raise an error
raise ActionExecutionRejection(self.name(),
"Please provide document number")
So, ideally as per the docs, when ActionExecutionRejection occurs, it should utter a template with name utter_ask_{slotname} but it doesn’t trigger that action.
Here is my domain.yml templates
templates:
utter_greet:
- text: "Hi, hope you are having a good day! How can I help?"
utter_ask_document_number:
- text: "Please provide document number"
utter_help:
- text: "To find the document, please say the ID of a single document or multiple documents"
utter_goodbye:
- text: "Talk to you later!"
utter_thanks:
- text: "My pleasure."
The ActionExecutionRejection doesn't by default utter a template with the name utter_ask_{slotname}, but rather leaves the form logic to allow other policies (e.g. FallbackPolicy) to take action. The utter_ask_{slotname} is the default for the happy path in which it's trying to get a required slot for the first time. This default implementation of the action rejection is there in order to handle certain unhappy paths such as if a user decides they want to exit the flow by denying, or take a detour by chatting, etc.
If you want to implement the template to re-ask for the required slot using the utterance, you could replace the ActionExecutionRejection with dispatcher.utter_template(<desired template name>, tracker). However, this will leave you with no way to exit the form action without validation -- I don't know what your intents are, but perhaps you want to also incorporate some logic based on the intent (i.e. if it's something like "deny", let the ActionExecutionRejection happen so it can exit, it it's an "enter data" type of intent make sure it asks again).
I created a standard not_found page that is working OK as long as I have it inside the "web/templates/error" folder (not_found.html.eex).
I'm using (in error_view.ex):
def render("404.html", _assigns) do
render("not_found.html", %{})
end
When I try to move it into another folder (in this particular case the standard "web/templates/page" folder) I get the "Server internal error" message that is suppose to appear because no render clause matches or no template is found. The template is there and I've tried with different folders.
I'm using this render function in error_view.ex:
def render("404.html", _assigns) do
render("MyProject.PageView", "not_found.html", %{})
end
Shouldn't this work?
The render/3 function takes 3 arguments. The first argument should be the module to call render on:
def render("404.html", _assigns) do
render(MyProject.PageView, "not_found.html", %{})
end
You have provided the string "MyProject.PageView" instead of the module MyProject.PageView.
I have a method in Ruby to query a database and print out some data, and I'm trying to use a prepared statement instead.
Here's the functioning method without the prepared statement:
def print_state_speakers(*states)
puts "STATE SPEAKERS"
state_string = "'#{states.*"', '"}'"
state_speakers = $db.execute("
SELECT name, location
FROM congress_members
WHERE location IN (#{state_string})
ORDER BY location")
state_speakers.each { |rep, location| puts "#{rep} - #{location}" }
end
Here's my attempt at the same method using a prepared statement:
def print_state_speakers(*states)
puts "STATE SPEAKERS"
state_string = "'#{states.*"', '"}'"
begin
pst = $db.prepare "SELECT name, location
FROM congress_members
WHERE location IN (?)
ORDER BY location"
state_speakers = pst.execute state_string
end
state_speakers.each { |rep, location| puts "#{rep} - #{location}" }
end
Here's where I call the method:
print_state_speakers('NJ', 'NY' , 'ME', 'FL', 'AK')
When I run the file with the 1st method it shows the data, when I use the 2nd, it shows nothing. It doesn't throw an error. I feel like the syntax needs to be different to account for the string being passed in, but I've been searching online and messing around with it for a while and can't get it to work. Any insight as to how to fix the prepared statement would be appreciated.
When you say this:
pst = $db.prepare "SELECT name, location
FROM congress_members
WHERE location IN (?)
ORDER BY location"
state_speakers = pst.execute state_string
The pst.execute call will escape and quote state_string like any other string. But your state_string isn't really a single string, it is an SQL list represented as a (Ruby) string so you'll end up double quoting everything.
An easy solution is to use string interpolation to add the appropriate number of placeholders and then let SQLite3::Statement deal with all the quoting itself:
placeholders = ([ '?' ] * states.length).join(',')
pst = $db.prepare "SELECT name, location
FROM congress_members
WHERE location IN (#{placeholders})
ORDER BY location"
state_speakers = pst.execute states
This use of string interpolation is perfectly safe because you know exactly what is in placeholders.
comics = load_comics( '/comics.txt' )
Popup.make do
h1 "Comics on the Web"
list do
comics.each do |name, url|
link name, url
end
end
end
I am new to ruby. This is a piece of code from a ruby website.
I cant find what 'link' and 'list' keyword in the menu.
can someone explain it a little bit those two keywords, and where is the definition of those two keyword .
I am also confused on how they read the variables name and url, they are reading it by the space at the same line or what?
so if I have
Comics1 link_of_comics_site_1
Comics2 link_of_comics_site_2
Comics3 link_of_comics_site_3
so for the first iteration, name=Comics1, and url =link_of_comics_site_1
Thanks.
That's not just Ruby. That's a template for a webpage using ruby add-on methods for HTML generation.
But presumably, the result of the call to load_comics is a Hash, where the keys are names and the values are URLs. You could make one of those yourself:
my_comics_hash = { "name1" => "url1", "name2" => "url2" }
which you can then iterate over the same way:
my_comics_hash.each do |name, url|
puts "Name #{name} goes with URL #{url}"
end
In your code, it's building up an HTML list inside a popup window, but it's the same idea. The each method iterates over a collection - in this case a Hash - and runs some code on every item in that collection - in this case, each key/value pair. When you call each, you pass it a block of code inside do ... end; that's the code that gets run on each item. The current item is passed to the code block, which declares a variable to hold it inside the pipes right after the word do. Since we're iterating over key/value pairs, we can declare two variables, and the key goes in the first and the value in the second.
In ruby function, parenthesis is optional and the ";" end of statement is also optional. ej
link "click here" , "http://myweb.com"
is equivalent to :
link("click here", "http://myweb.com");
But If you have more than one statement in a line the ";" is a must, ej
link("click here1", "http://myweb.com"); link("click here2", "http://myweb.com");
In your code it could be written in
link(name, url)
or just
link(name, url);
or
link name, url
But it is highly recommended to put parenthesis around function parameters for readability unless you have other reason . The ";" is not common in ruby world .
I'm using iReport-3.7.6
I have created a sample_Report1 with one parameter as (Project_name) and
I have created the Sample_Report2 with one parameter as (Employee_No)
Now I want to create a hyper-link in Sample_Report1 to Sample_Report2.
(pass the employee_no as a parameter to Sample_Report2 from Sample_Report1 using hyper-link)
rclick on the text field > link parameter
hyperlink target: Self
hyperlink type: ReportExecution
A. add "link parameter name" = uri (well in my repository setup this is what I use)
then Value Expression is the URL enclosed in " "
B. Click on add again "parameter name" value will be the field parameter
when you click mouse over on the link it should be like this
www.yoursite.com/reports/executeReports.jsp?uri=/path/report/yearend&year=2010
this is your URI = "uri=/path/report/yearend"
this is your parameter = "year=2010"
hope this helps...