Hello Friends,
I am facing a problem in coding a certain thing and i am completely
unaware of it. The requirement is that…
When i am executing my ruby scripts through cmd, then after executing
the scripts an html report file is auto-generated which will have the
output of my ruby script.
For ex- If the scripts run fine than the html report will have a Passed
message
and
if the scripts failed than the html report will have the complete error
report of that script i.e which line got failed(as it is displayed in
cmd console).
Could you try something like this?
Tell me if it has cleared up things now.
def the_main_script
Your main script
Do whatever here
x = rand(3)
puts “x = #{x}”
puts “and 10/#{x} = #{10/x}” # When x==0 ZeroDivisionError
end
begin
the_main_script
rescue => exception_detail
p exception_detail.inspect
p exception_detail.message
p exception_detail.backtrace
puts exception_detail.backtrace.join(“\n”)
else
puts “Everything went ok!”
end
i am trying but its not working, the script is not running and it is
unable to generate html report…
can u please help me with the code
What code? I haven’t seen any so far. Until now I have to assume
this is an attempt to make other people do your (home-) work for free.
But I will share some code for I am kind (and just got back home from a
cocktail party, aha! )
#!/usr/bin/env ruby
Lazy module. Lyrics are released under MIT license
Figuring out the tune is left as an exercise to the
programmer
module Lazy
def self.print
“I was dreaming of rspec”
“and was failing at the test…”
“I began to lose control”
“I began to lose control”
“”
“I didn’t mean to release you”
“I’m sorry for the push request”
“Oh no, I didn’t want to upload you”
“I’m just a lazy guy”
“”
“I was feeling insecure”
“You might have buggy code in you”
“I was shivering inside”
“I was shivering inside”
“”
“I didn’t mean to release you”
“I’m sorry for the push request”
“Oh no, I didn’t want to upload you”
“I’m just a lazy guy”
“”
“I was handling your controlles”
“To avoid writing the tests”
“I was swallowing my pain”
“I was swallowing my pain!!!”
“”
“I didn’t mean to release you”
“I’m sorry for the push request”
“Oh no, I didn’t want to upload you…”
“I’m just a lazy guy…”
end
end
Feel to free to modify and/or alternate the lyrics. I’m not a English
mother-tongue and also about to sleep on the keyboard, so if I made a
mistake somewhere please correct me!.
if results.all?
# output the “all scripts passed” html
else
# output the “uh-oh there was an error” html
end
end
Two tricks here:
the “system” method runs the command in cmd and returns true if the
command exited successfully, otherwise it returns false or nil
the “all?” method is an array method that by default returns true
if all array elements are true (“true” in the ruby sense), otherwise it
returns false
So what happens is if any of the commands fail, the “all?” method
returns false and you can use that to know that there was an error
i am trying but its not working, the script is not running and it is
unable to generate html report…
can u please help me with the code
What code? I haven’t seen any so far. Until now I have to assume
this is an attempt to make other people do your (home-) work for free.
Regards
robert
Robert i was asking only about generating a html report as i had no clue of doing
it. It not like making people work, I was asking for syntax… N do mind your
words that you are talking to others. n Yes u helped me alot about getting the
mindset of what type of people are there in this forum