ruby on rails 3 - Getting uninitialized constant (NameError) inside decorators when running rspec tests via rake -


in app use engine (blogit) want add changes / behaviours.

i followed guides on how override engine controllers/models , added following:

the code

in config/initializer/blogit.rb

# requires extension ruby files in lib/blogit. dir[rails.root.join("lib/blogit/*.rb")].each {|f| require f} 

in lib/blogit/engine.rb

module blogit   class engine < ::rails::engine     isolate_namespace blogit      config.to_prepare       dir.glob(rails.root + "app/decorators/**/blogit/*_decorator*.rb").each |c|         require_dependency(c)       end     end   end end 

in app/decorators/controllers/blogit/comments_controller_decorator.rb

blogit::commentscontroller.class_eval   def create     rails.logger.info "decorated controller action"     # ... overridden stripped ...   end end 

in app/decorators/models/blogit/comment_decorator.rb

blogit::comment.class_eval   belongs_to :user end 

to mentioned:

  • i have created migration add user reference comments model, since app uses devise , want logged_in users able comment. (therefore don't need standard behaviour, i'm going override it.)

the problem

if run rake weird error:

/users/kassi/.rvm/rubies/ruby-1.9.3-p392-railsexpress/bin/ruby -s rspec ./spec/controllers/home_controller_spec.rb ./spec/models/user_spec.rb /users/kassi/demo/app/decorators/controllers/blogit/comments_controller_decorator.rb:3:in `<top (required)>': uninitialized constant blogit::commentscontroller (nameerror) 

however, if run first line rake mentions hand (.../ruby -s ...), tests being run successfully.

in project i'm using guard spork. running guard let tests pass without error.

the app runs fine, i.e. starts without errors , i'm able comment want. decorator action code being executed.

so what's different when running rake? why break?

note:

  • adding require "blogit" or require "blogit/comments_controller" doesn't help. can't find controller using require.

a demo application

since problem part of bigger project, created new app scratch testing purposes contains relevant stuff: basic rails app, rspec, devise, blogit , decorators. can found here: https://github.com/kassi/decorator_demo_rspec (git://github.com/kassi/decorator_demo_rspec.git)

another repo using testunit (which working!) can found here: https://github.com/kassi/decorator_demo_testunit (git://github.com/kassi/decorator_demo_testunit.git)

instead of performing require statements yourself, can try activesupport-decorators you.


Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -