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

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 :slight_smile:

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

View this message in context:
http://www.nabble.com/-RSpec--implicit-receiver-for-should-problem-when-helper-predicate-methods-are-in-use-tp23432383p23432383.html
Sent from the rspec-users mailing list archive at Nabble.com.

On Thu, May 7, 2009 at 11:14 AM, juuuser [email protected] wrote:

  end

s.ok? # true
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.

I don’t understand why you want these to pass in the first place. Can
you give an example of where the receiver should be the example
itself?