Try requiring the files manually, Rails autoloading is sometimes a bit funny.

Jon Rowe
---------------------------
[email protected]
jonrowe.co.uk


On Tuesday, 15 December 2015 at 23:19, Arup Rakshit wrote:

> Hi,
> 
> I have very similar index action test pattern in 100+ controllers. That is 
> why I am thinking to run them from a single file. Here is my code to meet the 
> same need :
> 
> require 'spec_helper' Dir[Rails.root.join('app','admin', '**', '*')].each do 
> | file_name | admin_controller = File.basename(file_name, '.rb') 
> RSpec.describe "Admin::#{ admin_controller.classify 
> }sController".constantize, type: :controller do render_views let(:login_with) 
> { create(:full_admin_user) } login_admin_user include_examples "index" end end
> 
> But, once I run it, getting below error :
> 
> /Users/arup/.rvm/gems/ruby-2.2.3@admin/gems/activesupport-4.2.5/lib/active_support/inflector/methods.rb:263:in
>  `const_get': uninitialized constant Admin::AccountingsController (NameError) 
> from 
> /Users/arup/.rvm/gems/ruby-2.2.3@admin/gems/activesupport-4.2.5/lib/active_support/inflector/methods.rb:263:in
>  `block in constantize' from 
> /Users/arup/.rvm/gems/ruby-2.2.3@admin/gems/activesupport-4.2.5/lib/active_support/inflector/methods.rb:259:in
>  `each' from 
> /Users/arup/.rvm/gems/ruby-2.2.3@admin/gems/activesupport-4.2.5/lib/active_support/inflector/methods.rb:259:in
>  `inject' from 
> /Users/arup/.rvm/gems/ruby-2.2.3@admin/gems/activesupport-4.2.5/lib/active_support/inflector/methods.rb:259:in
>  `constantize' from 
> /Users/arup/.rvm/gems/ruby-2.2.3@admin/gems/activesupport-4.2.5/lib/active_support/core_ext/string/inflections.rb:66:in
>  `constantize' from 
> /Users/arup/eligible/admin/spec/controllers/controller_index_action_spec.rb:7:in
>  `block in <top (required)>' from /Users/arup/eligible/admin/spec/c
ontrollers/controller_index_action_spec.rb:4:in `each' from 
/Users/arup/eligible/admin/spec/controllers/controller_index_action_spec.rb:4:in
 `<top (required)>'
> 
> Those test are for ActiveAdmin controllers. When I run the same test as below 
> :
> 
> require 'spec_helper' RSpec.describe Admin::AccountingsController, type: 
> :controller do render_views let(:full_admin_user) { create(:full_admin_user) 
> } let(:login_with) { full_admin_user } login_admin_user include_examples 
> "index" end
> 
> 
> It works like a charm. Now my question is why the code given at top of this 
> thread didn't work ? 
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "rspec" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to [email protected] 
> (mailto:[email protected]).
> To post to this group, send email to [email protected] 
> (mailto:[email protected]).
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/rspec/a5f0915a-870e-4595-a600-45134bbe9546%40googlegroups.com
>  
> (https://groups.google.com/d/msgid/rspec/a5f0915a-870e-4595-a600-45134bbe9546%40googlegroups.com?utm_medium=email&utm_source=footer).
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"rspec" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rspec/3EF299ACC4C84603B0115339999B9618%40jonrowe.co.uk.
For more options, visit https://groups.google.com/d/optout.

Reply via email to