[rspec-users] Where do a set the description on a should satisfy.

GregD gditrick at fuse.net
Fri Sep 24 14:29:39 EDT 2010

Hi all,

Newbie here and I'm using rspec with jruby to test a java class, but
this is
more of a rspec question.

I have a java HashMap object and want to make sure a key exists.  I
have this as
my test:

    context :toHashMap do
      subject { @var_list.toHashMap }

      it { should satisfy{|a| a.contains_key?(var1) } }
      it { should satisfy{|a| a.contains_key?(var2) } }
      it { should satisfy{|a| a.contains_key?(var3) } }

@var_list is set to another java object that has a method toHashMap
that returns
a HashMap.  var1, var2 and var3 are set using let(:var1), etc.  If the
one of
these fails, I get this telling me that I need to supply a description

'Java::LibraryLanguage::XmlVariableList when added duplicate variables
different values toHashMap should When you call a matcher in an
example without
a String, like this:

specify { object.should matcher }

or this:

it { should matcher }

RSpec expects the matcher to have a #description method. You should
add a String to the example this matcher is being used in, or give it
description method. Then you won't have to suffer this lengthy warning
expected {var01=2, var02=this-is-a-string} to satisfy block

I'd like to put 'contain the key <blah>' in place of 'When you call a
matcher in
an example without a String'

Where do I put that string?  I thought I could just do:

it "should contain the key #{var1}" { should satisify{|a|
} }

But, the loading complains on that.  Where can a put a custom
description into
this code (easily/polite way).



More information about the rspec-users mailing list