Forum: RSpec Stubbing #javascript_include_tag in a helper spec

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.
Nick H. (Guest)
on 2008-11-01 00:27
(Received via mailing list)
When writing specs for a helper method, how do you set an expectation
for #javascript_include_tag ?

describe NeighbourhoodsHelper do
   describe '#initialise_map' do
     it 'should include the "foo" JS file' do
       # expectation here
       helper.foobar
     end
   end
end

I've tried replacing "# expectation here" with the following, but none
of them result in the desired behaviour:

ActionView
::Helpers::AssetTagHelper.should_receive :javascript_include_tag
@controller.should_receive :javascript_include_tag
@controller.instance_eval
{ @template }.should_receive :javascript_include_tag

Thanks!
Nick
David C. (Guest)
on 2008-11-01 00:52
(Received via mailing list)
On Fri, Oct 31, 2008 at 5:26 PM, Nick H. <removed_email_address@domain.invalid>
wrote:
> end
>
> I've tried replacing "# expectation here" with the following, but none of
> them result in the desired behaviour:
>
> ActionView::Helpers::AssetTagHelper.should_receive :javascript_include_tag
> @controller.should_receive :javascript_include_tag
> @controller.instance_eval { @template }.should_receive
> :javascript_include_tag

Assuming that you intend to have a helper method that calls out to
javascript_include_tag, then:

  helper.should_receive :javascript_include_tag

Let us know if that works for you.
Nick H. (Guest)
on 2008-11-01 01:15
(Received via mailing list)
On 2008-10-31, at 18:50, David C. wrote:
> Assuming that you intend to have a helper method that calls out to
> javascript_include_tag, then:
>
>  helper.should_receive :javascript_include_tag
>
> Let us know if that works for you.

Hah, so easy. Why didn't I think of that?  =P  Thanks, mate!
This topic is locked and can not be replied to.