Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rspec - Failure/Error: render - ActionView::Template::Error #31

Closed
abrisse opened this issue Apr 16, 2013 · 8 comments
Closed

Rspec - Failure/Error: render - ActionView::Template::Error #31

abrisse opened this issue Apr 16, 2013 · 8 comments

Comments

@abrisse
Copy link
Contributor

abrisse commented Apr 16, 2013

I switched from rabl to rabl-rails. It works great except during the tests (rspec).

My view:

object :@media

attributes :types

My test:

describe 'v1/medias/show' do
  it 'should render a valid json' do
    render # it fails here
    expect { JSON.parse(rendered) }.to_not raise_error(JSON::ParserError)
  end
end

The error:

 Failure/Error: render
     ActionView::Template::Error:
       undefined method `start_with?' for :__memoized:Symbol
     # ./app/views/v1/medias/show.rabl:2:in `_app_views_v__medias_show_rabl___3750579331352501291_55842580'
     # ./spec/views/v1/medias_view_show_spec.rb:14:in `block (2 levels) in <top (required)>'
@ccocchi
Copy link
Owner

ccocchi commented Apr 16, 2013

Which version on rabl-rails do you used?

@abrisse
Copy link
Contributor Author

abrisse commented Apr 16, 2013

0.3.1

@ccocchi
Copy link
Owner

ccocchi commented Apr 16, 2013

There is only one place in the code source where I used start_with? without using to_s before it when dealing with assigns in action_controller.

Which version of rails are you using? Do you use another gem that deals with controller or it is vanilla rails ?

@abrisse
Copy link
Contributor Author

abrisse commented Apr 16, 2013

I am using rails 3.2.13. The problem only occurs with rspec. Is there any way to see the compiled view '_app_views_v__medias_show_rabl___3750579331352501291_55842580' ?

@ccocchi
Copy link
Owner

ccocchi commented Apr 16, 2013

Hmm, I also use RSpec and I never ran into this issue. No the compiled view is from ActionView so I don't really know if you can see it.

But, you can try to monkey patch RablRails in you spec_helper.rb with this:

module RablRails
  module Renderers
    class Base

      private

      def setup_render_context
        @_context.instance_variable_get(:@_assigns).each_pair { |k, v|
          instance_variable_set("@#{k}", v) unless k.to_s.start_with?('_')
        }
      end
    end
  end
end

That should fix your issue, and I will include it in the next release.

@abrisse
Copy link
Contributor Author

abrisse commented Apr 16, 2013

Yep it fixes the problem. Thanks!

@abrisse
Copy link
Contributor Author

abrisse commented May 24, 2013

I close this issue but you should create an entry in the Wiki addressing this problem.

@abrisse abrisse closed this as completed May 24, 2013
@ccocchi
Copy link
Owner

ccocchi commented May 28, 2013

Added in #37

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants