jasmine / jasmine-gem

Jasmine ruby gem
682 stars 274 forks source link

undefined method 'assets_environment' when using Jasmine with a Rails4 Engine #184

Closed rstammer closed 10 years ago

rstammer commented 10 years ago

I installed the gem via the development dependency in the gemspec of a Rails4 engine on Ruby 2.0.0 and initialized it rails generator rails g jasmine:install .

Starting the server works fine, but reloading the page on localhost:8888 in the browser or using rake jasmine:ci gives me the following 500:

2013-12-17 16:10:06] ERROR NameError: undefined local variable or method `assets_environment' for #<ActionView::Base:0x007fdbeae45a20>
    /Users/robinneumann/.rvm/gems/ruby-2.0.0-p247@kanyotoku/gems/jasmine-2.0.0/lib/jasmine/asset_bundle.rb:52:in `get_original_assets'
    /Users/robinneumann/.rvm/gems/ruby-2.0.0-p247@kanyotoku/gems/jasmine-2.0.0/lib/jasmine/asset_bundle.rb:43:in `assets'
    /Users/robinneumann/.rvm/gems/ruby-2.0.0-p247@kanyotoku/gems/jasmine-2.0.0/lib/jasmine/asset_expander.rb:10:in `expand'
    /Users/robinneumann/.rvm/gems/ruby-2.0.0-p247@kanyotoku/gems/jasmine-2.0.0/lib/jasmine/asset_pipeline_mapper.rb:11:in `call'
    /Users/robinneumann/.rvm/gems/ruby-2.0.0-p247@kanyotoku/gems/jasmine-2.0.0/lib/jasmine/asset_pipeline_mapper.rb:11:in `block in map_src_paths'
    /Users/robinneumann/.rvm/gems/ruby-2.0.0-p247@kanyotoku/gems/jasmine-2.0.0/lib/jasmine/asset_pipeline_mapper.rb:10:in `map'
    /Users/robinneumann/.rvm/gems/ruby-2.0.0-p247@kanyotoku/gems/jasmine-2.0.0/lib/jasmine/asset_pipeline_mapper.rb:10:in `map_src_paths'
    /Users/robinneumann/.rvm/gems/ruby-2.0.0-p247@kanyotoku/gems/jasmine-2.0.0/lib/jasmine/configuration.rb:86:in `block in map'
    /Users/robinneumann/.rvm/gems/ruby-2.0.0-p247@kanyotoku/gems/jasmine-2.0.0/lib/jasmine/configuration.rb:84:in `each'
    /Users/robinneumann/.rvm/gems/ruby-2.0.0-p247@kanyotoku/gems/jasmine-2.0.0/lib/jasmine/configuration.rb:84:in `inject'
    /Users/robinneumann/.rvm/gems/ruby-2.0.0-p247@kanyotoku/gems/jasmine-2.0.0/lib/jasmine/configuration.rb:84:in `map'
    /Users/robinneumann/.rvm/gems/ruby-2.0.0-p247@kanyotoku/gems/jasmine-2.0.0/lib/jasmine/configuration.rb:37:in `js_files'
    (erb):11:in `block in render'
    /Users/robinneumann/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/erb.rb:849:in `eval'
    /Users/robinneumann/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/erb.rb:849:in `result'
    /Users/robinneumann/.rvm/gems/ruby-2.0.0-p247@kanyotoku/gems/jasmine-2.0.0/lib/jasmine/page.rb:8:in `render'
    /Users/robinneumann/.rvm/gems/ruby-2.0.0-p247@kanyotoku/gems/jasmine-2.0.0/lib/rack/jasmine/runner.rb:15:in `call'
    /Users/robinneumann/.rvm/gems/ruby-2.0.0-p247@kanyotoku/gems/rack-1.5.2/lib/rack/cascade.rb:33:in `block in call'
    /Users/robinneumann/.rvm/gems/ruby-2.0.0-p247@kanyotoku/gems/rack-1.5.2/lib/rack/cascade.rb:24:in `each'
    /Users/robinneumann/.rvm/gems/ruby-2.0.0-p247@kanyotoku/gems/rack-1.5.2/lib/rack/cascade.rb:24:in `call'
    /Users/robinneumann/.rvm/gems/ruby-2.0.0-p247@kanyotoku/gems/rack-1.5.2/lib/rack/builder.rb:138:in `call'
    /Users/robinneumann/.rvm/gems/ruby-2.0.0-p247@kanyotoku/gems/rack-1.5.2/lib/rack/urlmap.rb:65:in `block in call'
    /Users/robinneumann/.rvm/gems/ruby-2.0.0-p247@kanyotoku/gems/rack-1.5.2/lib/rack/urlmap.rb:50:in `each'
    /Users/robinneumann/.rvm/gems/ruby-2.0.0-p247@kanyotoku/gems/rack-1.5.2/lib/rack/urlmap.rb:50:in `call'
    /Users/robinneumann/.rvm/gems/ruby-2.0.0-p247@kanyotoku/gems/jasmine-2.0.0/lib/rack/jasmine/cache_control.rb:10:in `call'
    /Users/robinneumann/.rvm/gems/ruby-2.0.0-p247@kanyotoku/gems/rack-1.5.2/lib/rack/head.rb:11:in `call'
    /Users/robinneumann/.rvm/gems/ruby-2.0.0-p247@kanyotoku/gems/rack-1.5.2/lib/rack/builder.rb:138:in `call'
    /Users/robinneumann/.rvm/gems/ruby-2.0.0-p247@kanyotoku/gems/rack-1.5.2/lib/rack/handler/webrick.rb:60:in `service'
    /Users/robinneumann/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/webrick/httpserver.rb:138:in `service'
    /Users/robinneumann/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/webrick/httpserver.rb:94:in `run'
    /Users/robinneumann/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/webrick/server.rb:295:in `block in start_thread'

Did I miss something or is this maybe a deeper problem?

ragaskar commented 10 years ago

The asset pipeline integration has been a challenge, because we usually need to talk to some not-exactly-meant-for-public-use interfaces in Rails. It sounds like one of these has broken down. If you can fix it, we're happy to take a pull, otherwise we'll have someone take a look at their soonest opportunity.

Thanks!

ragaskar commented 10 years ago

Thinking about this a little more, it's probably that the rails engine doesn't have the same sort of environment init that a regular rails app gets (which makes sense) ... I'm not sure if there's an easy way to support asset pipeline in Rails engines. You might have to put together a testing harness that includes a Rails app.

rstammer commented 10 years ago

The engine already contains a dummy app located under /spec which surely could be the host for the tests. I'm going to play with it to find a setup that works!

rstammer commented 10 years ago

Short update: It's easy doing so and running the command from /spec/dummy

rake jasmine:ci JASMINE_CONFIG_PATH=../javascripts/support/jasmine.yml

This solves my practical problem for running it. Ideally it would be cool to run it from the engine's root directory natively like the rest of the test suite, but this way is okay.

edit: To make the command accessible, I had to add some code to the engines rakefile:

begin
  require 'jasmine'
    load 'jasmine/tasks/jasmine.rake'
  rescue LoadError
    task :jasmine do
     abort "Jasmine is not available. In order to run jasmine, you must: (sudo) gem install jasmine"
  end
end
ragaskar commented 10 years ago

I think we're not going to fix this since it looks like you have an appropriate workaround. We'd prefer not to have to offer direct support for Rails engines if it's significantly different from running w/ just Rails.