[rspec-users] [RSpec] implicit receiver for should problem when helper predicate methods are in use

juuser Jarmo.P at gmail.com
Thu May 7 14:01:16 EDT 2009


I just upgraded RSpec and noticed that some of my specs started to
fail and it is caused by the 1.1.2 update where implicit receiver for
should is introduced.

Here is one sample example group, which works with older versions
naturally.

describe "example group" do
	it "example" do
         should be_ok
       end

	def ok?
	  true
	end
end

And gets NoMethodError of course. I tried different things to set as
subject, but was unlucky. For example, subject {self} caused
SystemStackError although I hoped that this does the trick, since self
has method ok? as expected.

I also noticed that there is accessor for subject, so I tried
something like this instead of def ok?:

def subject.ok?
   true
end

Why doesn't it work? It works when doing like this:
s = "str"
def s.ok?; true; end
s.ok? # true

I found only one way to fix them like this:
class String
    def ok?
	true
    end
end

Of course I'm not happy with that solution :)

What are my options to fix these specs? It seems to me that most
logical functionality to this problem would be to make the subject
{self} line to work as expected.

Jarmo


More information about the rspec-users mailing list