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

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.
Ff97ca87af59ee68ceff5877a8365788?d=identicon&s=25 Jarmo Pertman (juuser)
on 2009-05-07 21:09
(Received via mailing list)
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
--
View this message in context:
http://www.nabble.com/-RSpec--implicit-receiver-fo...
Sent from the rspec-users mailing list archive at Nabble.com.
5d38ab152e1e3e219512a9859fcd93af?d=identicon&s=25 David Chelimsky (Guest)
on 2009-05-07 23:03
(Received via mailing list)
On Thu, May 7, 2009 at 11:14 AM, juuuser <jarmo.p@gmail.com> 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?
This topic is locked and can not be replied to.