Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.ruby > #3199 > unrolled thread

assert_name doesn't exist as a function?

Started byMike RegistrationErr <xandrani@gmail.com>
First post2011-04-19 20:04 -0500
Last post2011-04-20 15:38 -0500
Articles 5 — 3 participants

Back to article view | Back to comp.lang.ruby


Contents

  assert_name doesn't exist as a function? Mike RegistrationErr <xandrani@gmail.com> - 2011-04-19 20:04 -0500
    Re: assert_name doesn't exist as a function? Mike RegistrationErr <xandrani@gmail.com> - 2011-04-19 20:15 -0500
      Re: assert_name doesn't exist as a function? Brian Candler <b.candler@pobox.com> - 2011-04-20 03:45 -0500
    Re: assert_name doesn't exist as a function? 7stud -- <bbxx789_05ss@yahoo.com> - 2011-04-20 12:21 -0500
      Re: assert_name doesn't exist as a function? Brian Candler <b.candler@pobox.com> - 2011-04-20 15:38 -0500

#3199 — assert_name doesn't exist as a function?

FromMike RegistrationErr <xandrani@gmail.com>
Date2011-04-19 20:04 -0500
Subjectassert_name doesn't exist as a function?
Message-ID<0b400c83ed884b0303d1f4a910bbf476@ruby-forum.com>
The script (test.rb):

== START ==
require 'rubygems'
require 'firewatir'

include Test::Unit
include Test::Unit::Assertions
include Test::Unit::TestCase

assert_same "hello", "hello"
== END ==

doesn't seem to work. It says:
test.rb:8: undefined method `assert_same' for main:Object
(NoMethodError)

Surely the includes include this method?

I am new to ruby. Googling just brings up billions of irrelevant
results. The more I google the more confusion occurs. If someone can
just give me a quick heads up to what is wrong then I can sort this out.

Thanks!

-- 
Posted via http://www.ruby-forum.com/.

[toc] | [next] | [standalone]


#3200

FromMike RegistrationErr <xandrani@gmail.com>
Date2011-04-19 20:15 -0500
Message-ID<c79c57b7f70e1e4c454e3d5af63f8c26@ruby-forum.com>
In reply to#3199
I added this line:
require 'test/unit/assertions'

Which is different from:
include Test::Unit::Assertions

In PHP require and include are the same hence the confusion having come 
from PHP. I don't understand the difference between require and include 
in ruby yet, but at least my problem is sorted :)

-- 
Posted via http://www.ruby-forum.com/.

[toc] | [prev] | [next] | [standalone]


#3223

FromBrian Candler <b.candler@pobox.com>
Date2011-04-20 03:45 -0500
Message-ID<b89f11d980aec36ad86a4dcd486ea65f@ruby-forum.com>
In reply to#3200
Mike RegistrationErr wrote in post #993884:
> I added this line:
> require 'test/unit/assertions'
>
> Which is different from:
> include Test::Unit::Assertions
>
> In PHP require and include are the same hence the confusion having come
> from PHP. I don't understand the difference between require and include
> in ruby yet, but at least my problem is sorted :)

"require" means "go and load this ruby source file, if you've not loaded 
it before"

"include" means (roughly) "add the methods in that module into the 
current class"

"extend" means (roughly) "add the methods in that module into the 
current object"

module Foo
  def bar
    puts "I am bar!"
  end
end

bar         # doesn't work
include Foo
bar         # now it works

a = "Hello"
a.extend Foo
a.bar       # this works too

-- 
Posted via http://www.ruby-forum.com/.

[toc] | [prev] | [next] | [standalone]


#3256

From7stud -- <bbxx789_05ss@yahoo.com>
Date2011-04-20 12:21 -0500
Message-ID<051efa55f493d00e5ee11fb328565529@ruby-forum.com>
In reply to#3199
Mike RegistrationErr wrote in post #993883:
> The script (test.rb):
>
> == START ==
> require 'rubygems'
> require 'firewatir'
>
> include Test::Unit
> include Test::Unit::Assertions
> include Test::Unit::TestCase
>
> assert_same "hello", "hello"
> == END ==
>
> doesn't seem to work. It says:
> test.rb:8: undefined method `assert_same' for main:Object
> (NoMethodError)
>
> Surely the includes include this method?
>
> I am new to ruby.

In ruby 'hello' and 'hello' are not *the same*.  Quotes serve as a 
String constructor, and those are two different objects.   For instance,

a = 'hello'
b = 'hello'

if a.equal?(b)
  puts 'yes'
else
  puts 'no'
end

--output:--
no


You may wish to use assert_equal, which tests whether two strings 
contain the same characters:

a = 'hello'
b = 'hello'

if a == b
  puts 'yes'
else
  puts 'no'
end

--output:--
yes

-- 
Posted via http://www.ruby-forum.com/.

[toc] | [prev] | [next] | [standalone]


#3267

FromBrian Candler <b.candler@pobox.com>
Date2011-04-20 15:38 -0500
Message-ID<81a8b11c6bf8bedbbf7b140937bf6329@ruby-forum.com>
In reply to#3256
7stud -- wrote in post #994086:
>> test.rb:8: undefined method `assert_same' for main:Object
>> (NoMethodError)
>>
>> Surely the includes include this method?
>>
>> I am new to ruby.
>
> In ruby 'hello' and 'hello' are not *the same*.  Quotes serve as a
> String constructor, and those are two different objects.

That would explain it if assert_same raised an AssertionFailedError. But 
it does not explain the NoMethodError :-)

It works as expected for me if I require test/unit explicitly:

irb(main):001:0> require 'test/unit'
=> true
irb(main):002:0> include Test::Unit::Assertions
=> Object
irb(main):003:0> assert_same "hello","hello"
Test::Unit::AssertionFailedError: <"hello">
with id <70122845327940> expected to be equal? to
<"hello">
with id <70122845327920>.
  from /usr/lib/ruby/1.8/test/unit/assertions.rb:48:in `assert_block'
  from /usr/lib/ruby/1.8/test/unit/assertions.rb:495:in 
`_wrap_assertion'
  from /usr/lib/ruby/1.8/test/unit/assertions.rb:46:in `assert_block'
  from /usr/lib/ruby/1.8/test/unit/assertions.rb:249:in `assert_same'
  from (irb):3
  from /usr/lib/ruby/1.8/optparse.rb:311

I am using ruby 1.8.7p299 under Ubuntu 10.10 x86_64. The OP didn't 
specify their platform. Maybe they are running an old version of Ruby 
which doesn't include assert_same? Or possibly require 'firewatir' is 
defining the Test::Unit::* constants, without actually requiring 
test/unit/assertions?

-- 
Posted via http://www.ruby-forum.com/.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.ruby


csiph-web