# Undefined method \`assert\_select'

**URL:** <https://www.ruby-forum.com/t/undefined-method-assert-select/168630>\
**Category:** RSpec\
**Created:** [May 23, 2009, 7:27am UTC](https://www.ruby-forum.com/t/undefined-method-assert-select/168630 "2009-05-23T07:27:38Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![sackerson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/59ef9b/32.png) [@sackerson](https://www.ruby-forum.com/u/sackerson)\
**Post date:** [May 23, 2009, 7:27am UTC](https://www.ruby-forum.com/t/undefined-method-assert-select/168630/1 "2009-05-23T07:27:38Z")

</div>

I’m having trouble getting the specs to run for a plugin where I want to  
fix a bug. (I’ve actually already found and fixed the bug, but I don’t  
want to submit a fix without a test!) When I started the specs weren’t  
running, but it may be that I’m using Rails 2.3.3 and the plugin has  
been tested on 2.1 and earlier. I went through writing a spec for a very  
simple plugin to get some perspective on how things fit together, and  
I’ve resolved some issues, but still see this error:

$ spec  
vendor/plugins/openlaszlo\_plugin/spec/swfobject\_view\_helper\_spec.rb  
FFFFFFF

1. 

NoMethodError in ‘ActionView::Helpers::SwfObjectHelper swfobject\_tag  
should call swfobject.embedSWF’  
undefined method `assert\_select’ for  
#ActiveSupport::TestCase::Subclass\_1::Subclass\_1:0x2281278  
./vendor/plugins/openlaszlo\_plugin/spec/swfobject\_view\_helper\_spec.rb:17:

line 17 is:  
html.should have\_tag(‘script’, /swfobject.embedSWF/)

Can anyone give me a hint?

Thanks,  
Sarah

---

<div class="post-metadata">

**Author:** ![sackerson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/59ef9b/32.png) [@sackerson](https://www.ruby-forum.com/u/sackerson)\
**Post date:** [May 23, 2009, 8:18pm UTC](https://www.ruby-forum.com/t/undefined-method-assert-select/168630/2 "2009-05-23T20:18:00Z")

</div>

Sarah A. wrote:

> line 17 is:  
> html.should have\_tag(‘script’, /swfobject.embedSWF/)

I order to use have\_tag, it appears I have to include:

# just enough infrastructure to get ‘assert\_select’ to work

require ‘action\_controller’  
require ‘action\_controller/assertions/selector\_assertions’  
include ActionController::Assertions::SelectorAssertions

borrowed from: [http://intertwingly.net/stories/2009/05/06/checkdepot.rb](http://intertwingly.net/stories/2009/05/06/checkdepot.rb)

Odd, because it seems like this used to work without that in a previous  
version of Rails, but I would need to investigate more to isolate what  
went wrong. I figured I would go ahead and post this as something that  
works.

Sarah

---

<div class="post-metadata">

**Author:** ![sackerson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/59ef9b/32.png) [@sackerson](https://www.ruby-forum.com/u/sackerson)\
**Post date:** [May 23, 2009, 11:39pm UTC](https://www.ruby-forum.com/t/undefined-method-assert-select/168630/3 "2009-05-23T23:39:09Z")

</div>

On Sat, May 23, 2009 at 3:00 PM, Sarah A. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> > include ActionController::Assertions::SelectorAssertions
> 
> Confirmed that this is is required in Rails 2.3.2 and not in 2.1.0,  
> although I still don’t understand why.

Me neither 🙂

What version of rspec are you using?

---

<div class="post-metadata">

**Author:** ![sackerson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/59ef9b/32.png) [@sackerson](https://www.ruby-forum.com/u/sackerson)\
**Post date:** [May 23, 2009, 9:00pm UTC](https://www.ruby-forum.com/t/undefined-method-assert-select/168630/4 "2009-05-23T21:00:02Z")

</div>

Sarah A. wrote:

> Sarah A. wrote:
> 
> > line 17 is:  
> > html.should have\_tag(‘script’, /swfobject.embedSWF/)
> 
> I order to use have\_tag, it appears I have to include:
> 
> # just enough infrastructure to get ‘assert\_select’ to work
> 
> require ‘action\_controller’  
> require ‘action\_controller/assertions/selector\_assertions’  
> include ActionController::Assertions::SelectorAssertions

Confirmed that this is is required in Rails 2.3.2 and not in 2.1.0,  
although I still don’t understand why.

Sarah

---

<div class="post-metadata">

**Author:** ![sackerson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/59ef9b/32.png) [@sackerson](https://www.ruby-forum.com/u/sackerson)\
**Post date:** [May 24, 2009, 12:22am UTC](https://www.ruby-forum.com/t/undefined-method-assert-select/168630/5 "2009-05-24T00:22:54Z")

</div>

David C. wrote:

> What version of rspec are you using?

1.2.6

---

<div class="post-metadata">

**Author:** ![sackerson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/59ef9b/32.png) [@sackerson](https://www.ruby-forum.com/u/sackerson)\
**Post date:** [May 24, 2009, 9:20pm UTC](https://www.ruby-forum.com/t/undefined-method-assert-select/168630/6 "2009-05-24T21:20:14Z")

</div>

Sarah A. wrote:

> Sarah A. wrote:
> 
> > line 17 is:  
> > html.should have\_tag(‘script’, /swfobject.embedSWF/)
> 
> I order to use have\_tag, it appears I have to include:
> 
> # just enough infrastructure to get ‘assert\_select’ to work
> 
> require ‘action\_controller’  
> require ‘action\_controller/assertions/selector\_assertions’  
> include ActionController::Assertions::SelectorAssertions

I just worked on this a bit with RailsBridge mentor, Zach M., who  
figured out that the problem was that I had not specifies a type for my  
view helper example group:

describe SwfObjectHelper, :type =\> :helper do

I thought I would post it here in case anyone else runs into the same  
issue.

Sarah

---

<div class="post-metadata">

**Author:** ![sackerson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/59ef9b/32.png) [@sackerson](https://www.ruby-forum.com/u/sackerson)\
**Post date:** [May 25, 2009, 12:55am UTC](https://www.ruby-forum.com/t/undefined-method-assert-select/168630/7 "2009-05-25T00:55:51Z")

</div>

David C. wrote:

> FYI - if you put this file in spec/helpers/swf\_object\_helper\_spec.rb,  
> then :type =\> :helper is implied, so you don’t have to make it  
> explicit.

Nice.

By the way, I’ve been enjoying The RSpec Book, but it looks like I had  
to figure out view helpers before that chapter was ready. Thank for  
your help on this list!

Sarah

---

<div class="post-metadata">

**Author:** ![sackerson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/59ef9b/32.png) [@sackerson](https://www.ruby-forum.com/u/sackerson)\
**Post date:** [May 25, 2009, 1:38am UTC](https://www.ruby-forum.com/t/undefined-method-assert-select/168630/8 "2009-05-25T01:38:06Z")

</div>

David C. wrote:

> FYI - if you put this file in spec/helpers/swf\_object\_helper\_spec.rb,  
> then :type =\> :helper is implied, so you don’t have to make it  
> explicit.

just curious… are there any other magic directories I should know  
about?

Thanks,  
Sarah

---

<div class="post-metadata">

**Author:** ![sackerson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/59ef9b/32.png) [@sackerson](https://www.ruby-forum.com/u/sackerson)\
**Post date:** [May 25, 2009, 12:18am UTC](https://www.ruby-forum.com/t/undefined-method-assert-select/168630/9 "2009-05-25T00:18:33Z")

</div>

On Sun, May 24, 2009 at 3:20 PM, Sarah A. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> > include ActionController::Assertions::SelectorAssertions
> 
> I just worked on this a bit with RailsBridge mentor, Zach M., who  
> figured out that the problem was that I had not specifies a type for my  
> view helper example group:
> 
> describe SwfObjectHelper, :type =\> :helper do

FYI - if you put this file in spec/helpers/swf\_object\_helper\_spec.rb,  
then :type =\> :helper is implied, so you don’t have to make it  
explicit.

Cheers,  
David

---

<div class="post-metadata">

**Author:** ![sackerson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/59ef9b/32.png) [@sackerson](https://www.ruby-forum.com/u/sackerson)\
**Post date:** [May 25, 2009, 6:01am UTC](https://www.ruby-forum.com/t/undefined-method-assert-select/168630/10 "2009-05-25T06:01:59Z")

</div>

On Sun, May 24, 2009 at 7:38 PM, Sarah A. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> David C. wrote:
> 
> > FYI - if you put this file in spec/helpers/swf\_object\_helper\_spec.rb,  
> > then :type =\> :helper is implied, so you don’t have to make it  
> > explicit.
> 
> just curious… are there any other magic directories I should know  
> about?

All directories under spec/ are potentially magic - rspec will always  
look at spec/:directory/:filename and see if it has an example group  
type registered for whatever directory is. So if there _is_ a foo  
example group type, it will be used for any spec file in spec/foos.

rspec-rails uses that feature of rspec to implicitly load custom  
groups for models, views, controllers and helpers in spec/models,  
spec/views, spec/controllers and spec/helpers.

Cheers,  
David
