Forum: RSpec undefined method `assert_select'

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.
20ee0d23c969c7740d3c936a4675bb23?d=identicon&s=25 Sarah Allen (ultrasaurus)
on 2009-05-23 07:27
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
20ee0d23c969c7740d3c936a4675bb23?d=identicon&s=25 Sarah Allen (ultrasaurus)
on 2009-05-23 20:18
Sarah Allen 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

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
20ee0d23c969c7740d3c936a4675bb23?d=identicon&s=25 Sarah Allen (ultrasaurus)
on 2009-05-23 21:00
Sarah Allen wrote:
> Sarah Allen 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
5d38ab152e1e3e219512a9859fcd93af?d=identicon&s=25 David Chelimsky (Guest)
on 2009-05-23 23:39
(Received via mailing list)
On Sat, May 23, 2009 at 3:00 PM, Sarah Allen <lists@ruby-forum.com>
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?
20ee0d23c969c7740d3c936a4675bb23?d=identicon&s=25 Sarah Allen (ultrasaurus)
on 2009-05-24 00:22
David Chelimsky wrote:
> What version of rspec are you using?

1.2.6
20ee0d23c969c7740d3c936a4675bb23?d=identicon&s=25 Sarah Allen (ultrasaurus)
on 2009-05-24 21:20
Sarah Allen wrote:
> Sarah Allen 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 Moazeni, 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
5d38ab152e1e3e219512a9859fcd93af?d=identicon&s=25 David Chelimsky (Guest)
on 2009-05-25 00:18
(Received via mailing list)
On Sun, May 24, 2009 at 3:20 PM, Sarah Allen <lists@ruby-forum.com>
wrote:
>> include ActionController::Assertions::SelectorAssertions
>
> I just worked on this a bit with RailsBridge mentor, Zach Moazeni, 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
20ee0d23c969c7740d3c936a4675bb23?d=identicon&s=25 Sarah Allen (ultrasaurus)
on 2009-05-25 00:55
David Chelimsky 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
20ee0d23c969c7740d3c936a4675bb23?d=identicon&s=25 Sarah Allen (ultrasaurus)
on 2009-05-25 01:38
David Chelimsky 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
5d38ab152e1e3e219512a9859fcd93af?d=identicon&s=25 David Chelimsky (Guest)
on 2009-05-25 06:01
(Received via mailing list)
On Sun, May 24, 2009 at 7:38 PM, Sarah Allen <lists@ruby-forum.com>
wrote:
> David Chelimsky 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
This topic is locked and can not be replied to.