# Why can't I use assert\_respond\_to with some objects?

**URL:** <https://www.ruby-forum.com/t/why-cant-i-use-assert-respond-to-with-some-objects/91387>\
**Category:** Ruby\
**Created:** [April 8, 2007, 3:56am UTC](https://www.ruby-forum.com/t/why-cant-i-use-assert-respond-to-with-some-objects/91387 "2007-04-08T03:56:48Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![rsanheim](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/47e85d/32.png) [@rsanheim](https://www.ruby-forum.com/u/rsanheim)\
**Post date:** [April 8, 2007, 3:56am UTC](https://www.ruby-forum.com/t/why-cant-i-use-assert-respond-to-with-some-objects/91387/1 "2007-04-08T03:56:48Z")

</div>

Hi

This question is w/i the context of Rails, but I think it relates more  
to how pretty printer works then Rails.

I’m extending the built in AbstractRequest class in Rails, and trying  
to test it. The following test errors out, when it should be failing  
(as I haven’t added the method yet):

def test\_should\_have\_site\_subdomain  
@request = ActionController::AbstractRequest.new  
assert\_respond\_to @request, :site\_subdomain  
end

with this exception:

1. Error:  
test\_should\_have\_site\_subdomain(RailsExtensionsTest):  
ArgumentError: wrong number of arguments (1 for 0)  
method method in pp.rb at line 244  
method pretty\_print in pp.rb at line 244  
method pp in pp.rb at line 126  
method group in prettyprint.rb at line 224  
method nest in prettyprint.rb at line 247  
method group in prettyprint.rb at line 223  
method group\_sub in prettyprint.rb at line 235  
method group in prettyprint.rb at line 222  
method pp in pp.rb at line 126  
method pp in pp.rb at line 69  
method guard\_inspect\_key in pp.rb at line 105  
method pp in pp.rb at line 69  
method test\_should\_have\_site\_subdomain in rails\_extensions\_test.rb at  
line 18  
method run in test\_case\_adapter.rb at line 19

So its trying to call pp with an invalid call, but I get pretty lost  
trying to figure out how it got there. Note that the test passes and  
everything is fine after I add the method, so this isn’t a huge issue  
– I would just like to have the correct failure, and not a strange  
prettyprint error, when this does fail.

assert\_respond\_to fails correctly if I just test a builtin, btw, like  
so:

def test\_string  
assert\_respond\_to ‘string’, :foo  
end

with

1. Failure:  
test\_string(RailsExtensionsTest)  
method test\_string in rails\_extensions\_test.rb at line 22  
method run in test\_case\_adapter.rb at line 19  
\<“string”\> of type expected to respond\_to?\<:foo\>.

thanks,

- Rob
