Forum: Ruby Need a help in scripting

16d74ef2ca3348d45b87cdbc2377acba?d=identicon&s=25 saurav panda (sauravpanda)
on 2013-11-15 19:34
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).
56b84705a784f48382a2e014798e3dea?d=identicon&s=25 Garfield Carneiro (Guest)
on 2013-11-15 19:42
(Received via mailing list)
You should use exception handling to get custom error messages.
Some code snippet  or error message might help !
16d74ef2ca3348d45b87cdbc2377acba?d=identicon&s=25 saurav panda (sauravpanda)
on 2013-11-15 19:53
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
09a32175057418748822c587ac08c429?d=identicon&s=25 Abinoam Jr. (abinoampraxedes_m)
on 2013-11-15 20:03
(Received via mailing list)
Could you try something like this?
Tell me if it has cleared up things now.

https://gist.github.com/abinoam/7489732

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

Best regards,
Abinoam Jr.
56b84705a784f48382a2e014798e3dea?d=identicon&s=25 Garfield C. (garfield_c)
on 2013-11-15 20:04
(Received via mailing list)
Perhaps you can print debug messages to figure out where you are
encountering the problem.


Exceptional handling code goes like this:

begin
  1/0
  p 'I should never get executed'
rescue
  p 'I am rescuing an exception and can do what I want!'
end


See a short blog about this:

http://www.skorks.com/2009/09/ruby-exceptions-and-...

--
Gary
E0d864d9677f3c1482a20152b7cac0e2?d=identicon&s=25 Robert Klemme (robert_k78)
on 2013-11-16 11:56
(Received via mailing list)
On Fri, Nov 15, 2013 at 7:53 PM, saurav panda <lists@ruby-forum.com>
wrote:
> 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
A7fca2db6ff3f4583df98043bd5166f9?d=identicon&s=25 Panagiotis Atmatzidis (Guest)
on 2013-11-17 02:09
(Received via mailing list)
Hi,

On 16 Νοε 2013, at 11:55 , Robert Klemme <shortcutter@googlemail.com>
wrote:

> On Fri, Nov 15, 2013 at 7:53 PM, saurav panda <lists@ruby-forum.com> wrote:
>> 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


>
> Regards
>
> robert

>
> --
> remember.guy do |as, often| as.you_can - without end
> http://blog.rubybestpractices.com/


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!.


Cheers!

Panagiotis (atmosx) Atmatzidis

email:  atma@convalesco.org
URL:  http://www.convalesco.org
GnuPG ID: 0x1A7BFEC5
gpg --keyserver pgp.mit.edu --recv-keys 1A7BFEC5
16d74ef2ca3348d45b87cdbc2377acba?d=identicon&s=25 saurav panda (sauravpanda)
on 2013-11-18 09:34
Robert Klemme wrote in post #1127600:
> On Fri, Nov 15, 2013 at 7:53 PM, saurav panda <lists@ruby-forum.com>
> wrote:
>> 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

Thanks
Saurav
Df9ff54e701e96e9b83b0b71254f2e40?d=identicon&s=25 Michael Bostler (obiruby)
on 2013-11-19 08:11
Hey Saurav,

Maybe try something like the following?

def run_scripts
  scripts = [path_to_script1, path_to_script2, ...]

  results = scripts.map { |cmd| system( cmd ) }

  if results.all?
    # output the "all scripts passed" html
  else
    # output the "uh-oh there was an error" html
  end
end

Two tricks here:
  1) the "system" method runs the command in cmd and returns true if the
command exited successfully, otherwise it returns false or nil
  2) 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

Hope this helps. Let us know how it goes...
16d74ef2ca3348d45b87cdbc2377acba?d=identicon&s=25 saurav panda (sauravpanda)
on 2013-11-20 07:56
Michael,

Thanks Bro,i got my hint from your script and i added some more
functionality to the script to make it work
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.