Forum: RSpec how to play with rSpec using irb

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Alr A. (Guest)
on 2008-10-15 08:10
Hi,

Is there any way to experiment with rSpec in irb or script/console
session?

Tried this:

>> require 'spec'
=> true
>> [1,2,3].should have(3).items
=> NoMethodError: undefined method `have' for main:Object
  from (irb):4
  from
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/fileutils.rb:1576

What I am doing wrong?

Thx
Caius D. (Guest)
on 2008-10-15 10:43
(Received via mailing list)
On 15 Oct 2008, at 05:10, Alr Alr wrote:

> => NoMethodError: undefined method `have' for main:Object
>  from (irb):4
>  from
> /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/
> 1.8/fileutils.rb:1576
>
> What I am doing wrong?


%w(1 2 3).should have(3).items

the call to have is Object#have, which doesn't exist. If you include
the Spec::Matchers module however, then it adds Object#have, etc.

Julius:~ caius$ irb
 >> require "spec"
=> true
 >> include Spec::Matchers
=> Object
 >> %w(1 2 3).should have(3).items
=> true

C
---
Caius D.
removed_email_address@domain.invalid
+44 (0) 7960 268 100
http://caius.name/
Alr A. (Guest)
on 2008-10-15 11:10
> Julius:~ caius$ irb
>  >> require "spec"
> => true
>  >> include Spec::Matchers
> => Object
>  >> %w(1 2 3).should have(3).items
> => true
>
> C
> ---
> Caius D.
> removed_email_address@domain.invalid
> +44 (0) 7960 268 100
> http://caius.name/

thx, its working.
This topic is locked and can not be replied to.