pat / combustion

Simple, elegant testing for Rails Engines
MIT License
708 stars 51 forks source link

undefined method 'assets' #67

Closed machisuji closed 8 years ago

machisuji commented 9 years ago

Hey,

I'm trying to use combustion for testing my rails engine, but unfortunately upon running the specs I get the following error:

undefined method `assets' for #<Rails::Engine::Configuration:0x007f81708a4aa0> (NoMethodError)

When calling:

config.assets.precompile += %w( myscript.js )

I tried initialising :sprockets too and added it to the gemfile. Doesn't help, though. Any ideas?

spec_helper.rb:

require 'rubygems'
require 'bundler/setup'

require 'rails'
require 'action_controller/railtie'
require 'action_view/railtie'
require 'sprockets/railtie'
require 'jquery/rails'

require 'combustion'
require 'capybara/rspec'

Combustion.initialize! :action_view, :action_controller, :sprockets

require 'rspec/rails'
require 'capybara/rails'

RSpec.configure do |config|
  config.use_transactional_fixtures = true
end
pat commented 9 years ago

Hi Markus

Which version of Rails do you have bundled?

machisuji commented 9 years ago

Hey, it's rails 3.2.21.

pat commented 9 years ago

I don't suppose this engine is available on GitHub so I can use it to reproduce the issue locally? :)

machisuji commented 9 years ago

Hey, the gem is not quite public yet. Nothing secret, really, just a formality. Have to check back with people before making it public. So for the time being I invited you to a team and gave you read access to my fork.

On the branch feature/specs I gave combustion a try and got stuck with the problem above.

machisuji commented 9 years ago

Never mind, I made it public.

pat commented 9 years ago

lobby_boy? I don't think you've pushed the feature/specs branch.

machisuji commented 9 years ago

Yes, I pushed it to my fork.

pat commented 9 years ago

Right, so the issue, from my local testing, is that config in the scope of the engine, is the engine's configuration, not the app's. You want to do this instead, within the engine definition:

initializer "lobby_boy.assets.precompile" do |app|
  app.config.assets.precompile += %w( jquery.js js.cookie-1.5.1.min.js )
end
dancallaghan commented 7 years ago

To anyone who stumbles across this issue, I fixed it by adding sprockets-rails as a dependency:

# yourgem.gemspec
Gem::Specification.new do |s|
  # Rest of gemspec

  s.add_development_dependency "combustion"
  s.add_development_dependency "sprockets-rails"
end

Then include the sprockets railtie in Combustion:

Combustion.initialize! :active_record, :action_controller, :action_view, :sprockets

or:

Combustion.initialize! :all

Might be going about it the wrong way, but it got me onto the next roadblock.