How do I strip off the extra double quote or white space in the string when using assert_equal method

Hi,

I try to read in an external file to array and compare them to the drop
down list in our application. I got into the problem when comparing, the
extra double quotes make the assertion result failed. Can anyone help me
to make it work?

Thanks for your help,

ps . I posted this question on Nabble but it is pending without reason
so I try to post it here hope it can go to the list users...

···

************************
Below is the code:

------------
arr = IO.readlines("dropList.csv") # read entire contents of the file
into a single array. Each index of the array is one line.

assert_equal([arr[0]], $ie.frame("top").select_list(:name,
"site_id").getAllContents)

------------------

This is the csv external file dropList.csv contain:

:: Select Site ::
!!Eastgate_Mall
-----------------------------

1) Failure:

test__02_DropDown_list_verified(TC_pulldownBoxVerified)
[DropVerified_test.rb:45]:

<[":: Select Site ::,!!Eastgate_Mall,\n"]> expected but was

<[":: Select Site ::", "!!Eastgate_Mall"]>.

Hi
I am a newbie to this mailing list.

I have a couple of queries:

1. Can methods be part of an array definition, which can bear similarity
to 'C' definitions
   of "array of function pointers", as part of a state machine
implementation.

2. How can we make C routine call a "method" defined in a ruby script as
we do it the other way while extending ruby call C routines

Regards,
Saumya.

A couple of options:

1) If your external file is truly CSV (comma-separated values) use a CSV
parser to parse it. Though, from your example, it doesn't seem to be
the case... here's some code anyway.

.....
require 'csv'

rows =

CSV.open('dropList.csv', 'r') do |row|
  rows << row
end
.....

Then compare the parsed rows against your dropdown array.

2) Write your own assertion:

.....
def assert_equal_without_quotes(a,b)
  assert_equal a.gsub(/['"]/, ''), b.gsub(/['"]/, '')
end
.....

Untested, but that might work :wink:

Ben

···

On Thu, Aug 24, 2006, Ban Hoang wrote:

I try to read in an external file to array and compare them to the drop
down list in our application. I got into the problem when comparing, the
extra double quotes make the assertion result failed. Can anyone help me
to make it work?

Look up Object#method and Method in the docs:

you can do ['aaa'.method(:size), 10.method("+")]

UnboundMethod could be useful as well.

Other than that, its possible to call methods by name. I you just need
to call methods on one object, it is enough to store just their names
(preferably as symbols):

methods = [:size, :length, :whatever]

then you would for example do: methods.each {|m| 'aaaa'.send(m) }

···

On 8/23/06, Dikshit Saumya-G19445 <somc@motorola.com> wrote:

Hi
I am a newbie to this mailing list.

I have a couple of queries:

1. Can methods be part of an array definition, which can bear similarity
to 'C' definitions
   of "array of function pointers", as part of a state machine
implementation.

Another approach would be to use Procs in the array instead of
methods, this would allow you to store arguments in the array entries
as well, and to execute more than just a method.

actions = [
  lambda {obj.size},
  lambda {obj.length},
  lambda {obj.foo(3, "abc") }
  lambda {puts "Hi Mom!"; obj.callhome }
]

then to invoke an action it's just

actions[n].call

as a variation on this, if the blocks have parameters, you can use
call(arg1, [arg2,...]) to pass parameters.

···

On 8/23/06, Jan Svitok <jan.svitok@gmail.com> wrote:

On 8/23/06, Dikshit Saumya-G19445 <somc@motorola.com> wrote:
> Hi
> I am a newbie to this mailing list.
>
> I have a couple of queries:> >
> 1. Can methods be part of an array definition, which can bear similarity
> to 'C' definitions
> of "array of function pointers", as part of a state machine
> implementation.

Look up Object#method and Method in the docs:

you can do ['aaa'.method(:size), 10.method("+")]

UnboundMethod could be useful as well.

Other than that, its possible to call methods by name. I you just need
to call methods on one object, it is enough to store just their names
(preferably as symbols):

methods = [:size, :length, :whatever]

then you would for example do: methods.each {|m| 'aaaa'.send(m) }

--
Rick DeNatale

My blog on Ruby
http://talklikeaduck.denhaven2.com/

Thanks
Making it a proc really helped.

I have few more problems

How can we make C routine call a "method" defined in a ruby script ?
I am familiar with extending ruby to call C routines with/without swig.
But I was not able to find a easy solution for it. The only way it may
workout is
spawning the script in a different process/thread from C code and then
make it do all query/answer sequence by calling a C routine. Is there a
easy way out?
Can't we make a C routine call a specific method in a Ruby Script.

Can we access a C stack from Ruby or vice versa while debugging the
Ruby extension.

Regards,
Saumya.

···

-----Original Message-----
From: Rick DeNatale [mailto:rick.denatale@gmail.com]
Sent: Wednesday, August 23, 2006 10:41 PM
To: ruby-talk ML
Subject: Re: Can methods be part of a array

On 8/23/06, Jan Svitok <jan.svitok@gmail.com> wrote:

On 8/23/06, Dikshit Saumya-G19445 <somc@motorola.com> wrote:
> Hi
> I am a newbie to this mailing list.
>
> I have a couple of queries:> >
> 1. Can methods be part of an array definition, which can bear
> similarity to 'C' definitions
> of "array of function pointers", as part of a state machine
> implementation.

Look up Object#method and Method in the docs:

you can do ['aaa'.method(:size), 10.method("+")]

UnboundMethod could be useful as well.

Other than that, its possible to call methods by name. I you just need

to call methods on one object, it is enough to store just their names
(preferably as symbols):

methods = [:size, :length, :whatever]

then you would for example do: methods.each {|m| 'aaaa'.send(m) }

Another approach would be to use Procs in the array instead of methods,
this would allow you to store arguments in the array entries as well,
and to execute more than just a method.

actions = [
  lambda {obj.size},
  lambda {obj.length},
  lambda {obj.foo(3, "abc") }
  lambda {puts "Hi Mom!"; obj.callhome } ]

then to invoke an action it's just

actions[n].call

as a variation on this, if the blocks have parameters, you can use
call(arg1, [arg2,...]) to pass parameters.

--
Rick DeNatale

My blog on Ruby
http://talklikeaduck.denhaven2.com/

I have few more problems

How can we make C routine call a "method" defined in a ruby script ?
I am familiar with extending ruby to call C routines with/without swig.
But I was not able to find a easy solution for it. The only way it may
workout is spawning the script in a different process/thread from C code
and then make it do all query/answer sequence by calling a C routine. Is
there a easy way out?
Can't we make a C routine call a specific method in a Ruby Script.

Can we access a C stack from Ruby or vice versa while debugging the
Ruby extension.

Regards,
Saumya.

···

-----Original Message-----
From: Rick DeNatale [mailto:rick.denatale@gmail.com]
Sent: Wednesday, August 23, 2006 10:41 PM
To: ruby-talk ML
Subject: Re: Can methods be part of a array

On 8/23/06, Jan Svitok <jan.svitok@gmail.com> wrote:

On 8/23/06, Dikshit Saumya-G19445 <somc@motorola.com> wrote:
> Hi
> I am a newbie to this mailing list.
>
> I have a couple of queries:> >
> 1. Can methods be part of an array definition, which can bear
> similarity to 'C' definitions
> of "array of function pointers", as part of a state machine
> implementation.

Look up Object#method and Method in the docs:

you can do ['aaa'.method(:size), 10.method("+")]

UnboundMethod could be useful as well.

Other than that, its possible to call methods by name. I you just need

to call methods on one object, it is enough to store just their names
(preferably as symbols):

methods = [:size, :length, :whatever]

then you would for example do: methods.each {|m| 'aaaa'.send(m) }

Another approach would be to use Procs in the array instead of methods,
this would allow you to store arguments in the array entries as well,
and to execute more than just a method.

actions = [
  lambda {obj.size},
  lambda {obj.length},
  lambda {obj.foo(3, "abc") }
  lambda {puts "Hi Mom!"; obj.callhome } ]

then to invoke an action it's just

actions[n].call

as a variation on this, if the blocks have parameters, you can use
call(arg1, [arg2,...]) to pass parameters.

--
Rick DeNatale

My blog on Ruby
http://talklikeaduck.denhaven2.com/

I have few more queries

How can we make C routine call a "method" defined in a ruby script ?
I am familiar with extending ruby to call C routines with/without swig.
But I was not able to find a easy solution for it. The only way it may
workout is spawning the script in a different process/thread from C code
and then make it do all query/answer sequence by calling a C routine. Is
there a easy way out?
Can't we make a C routine call a specific method in a Ruby Script.

Can we access a C stack from Ruby or vice versa while debugging the
Ruby extension.

Regards,
Saumya.

···

-----Original Message-----
From: Rick DeNatale [mailto:rick.denatale@gmail.com]
Sent: Wednesday, August 23, 2006 10:41 PM
To: ruby-talk ML
Subject: Re: Can methods be part of a array

On 8/23/06, Jan Svitok <jan.svitok@gmail.com> wrote:

On 8/23/06, Dikshit Saumya-G19445 <somc@motorola.com> wrote:
> Hi
> I am a newbie to this mailing list.
>
> I have a couple of queries:> >
> 1. Can methods be part of an array definition, which can bear
> similarity to 'C' definitions
> of "array of function pointers", as part of a state machine
> implementation.

Look up Object#method and Method in the docs:

you can do ['aaa'.method(:size), 10.method("+")]

UnboundMethod could be useful as well.

Other than that, its possible to call methods by name. I you just need

to call methods on one object, it is enough to store just their names
(preferably as symbols):

methods = [:size, :length, :whatever]

then you would for example do: methods.each {|m| 'aaaa'.send(m) }

Another approach would be to use Procs in the array instead of methods,
this would allow you to store arguments in the array entries as well,
and to execute more than just a method.

actions = [
  lambda {obj.size},
  lambda {obj.length},
  lambda {obj.foo(3, "abc") }
  lambda {puts "Hi Mom!"; obj.callhome } ]

then to invoke an action it's just

actions[n].call

as a variation on this, if the blocks have parameters, you can use
call(arg1, [arg2,...]) to pass parameters.

--
Rick DeNatale

My blog on Ruby
http://talklikeaduck.denhaven2.com/