0

I've spent the last 2 days reading everything I could find on blogs, in books, in other gems' source, and on SO and I can't for the life of me figure this out. Admittedly I'm new to writing Ruby gems, Rails engines, and am not entirely familiar with all the RSpec view methods (but I'm learning as much as I can access).

I've made my project public on Github (albeit in the early stages, but this is based on some markup I've been reusing on recent projects that I'm slowly trying to pull into this gem) here:

https://github.com/robmclarty/admin_bar-rails

I've stopped adding new features while I figure out how to get my tests working. The main issue is a test I'm trying to run that simply renders a view partial (something I can build on to check other stuff later) like this:

render :partial => 'admin_bar-rails/bar.html.haml'
rendered.should contain 'admin-panel'

...but I get a NameError from RSpec regarding view_renderer as follows:

Failures:

  1) rendering admin bar should render an empty admin bar
     Failure/Error: render :partial => 'admin_bar-rails/bar.html.haml'
     NameError:
       undefined local variable or method `view_renderer' for #<RSpec::Core::ExampleGroup::Nested_2:0x007f99f260ec88>
     # ./spec/views/admin_bar-rails/bar.html.haml_spec.rb:13:in `block (2 levels) in <top (required)>'

I've tried including and requiring all kinds of stuff that I've read about (as you can see from the commented lines in my code), but I can't get it to pass.

This is mostly an "insert dynamic markup into views" gem so I (and you) can reuse some common templates in other Rails projects. Am I just going about this wrong? Do people even test views like this inside gems? Can anyone point me to some other gem examples that are more view/asset-heavy that use RSpec?

tshepang
  • 12,111
  • 21
  • 91
  • 136
robmclarty
  • 2,215
  • 2
  • 20
  • 21

1 Answers1

0

Ended up taking an alternate path by compiling the markup that I previously had in a view partial and creating the same thing through content_tag calls in a helper method. This has a couple of benefits: 1) keeps all the relevant code in one place, 2) makes the parts easier to test, and 3) simplifies the gem because now I don't need any views at all (just Ruby/Rails code).

Note: I removed the old gem I linked to in my question and replaced it with the following:

http://github.com/robmclarty/admin_nav-rails

robmclarty
  • 2,215
  • 2
  • 20
  • 21