ammeter icon indicating copy to clipboard operation
ammeter copied to clipboard

Rails 5 support

Open seanlinsley opened this issue 9 years ago • 7 comments

We're trying to get Rails 5 working with Draper: https://github.com/drapergem/draper/pull/752

Currently we've disabled the tests that use Ammeter because of this error: to_app: missing run or map statement (RuntimeError)

It specifically happens on the third line here:

require 'spec_helper'
require 'rails'
require 'ammeter/init'

Here's the full stack trace:

gems/rack-2.0.1/lib/rack/builder.rb:146:in `to_app': missing run or map statement (RuntimeError)
gems/rack-2.0.1/lib/rack/builder.rb:160:in `block in generate_map'
gems/rack-2.0.1/lib/rack/builder.rb:160:in `each'
gems/rack-2.0.1/lib/rack/builder.rb:160:in `generate_map'
gems/rack-2.0.1/lib/rack/builder.rb:145:in `to_app'
gems/capybara-2.7.1/lib/capybara/rails.rb:13:in `<top (required)>'
gems/activesupport-5.0.0/lib/active_support/dependencies.rb:293:in `require'
gems/activesupport-5.0.0/lib/active_support/dependencies.rb:293:in `block in require'
gems/activesupport-5.0.0/lib/active_support/dependencies.rb:259:in `load_dependency'
gems/activesupport-5.0.0/lib/active_support/dependencies.rb:293:in `require'
gems/rspec-rails-3.5.0/lib/rspec/rails/vendor/capybara.rb:7:in `<top (required)>'
gems/activesupport-5.0.0/lib/active_support/dependencies.rb:293:in `require'
gems/activesupport-5.0.0/lib/active_support/dependencies.rb:293:in `block in require'
gems/activesupport-5.0.0/lib/active_support/dependencies.rb:259:in `load_dependency'
gems/activesupport-5.0.0/lib/active_support/dependencies.rb:293:in `require'
gems/rspec-rails-3.5.0/lib/rspec/rails.rb:14:in `<top (required)>'
gems/activesupport-5.0.0/lib/active_support/dependencies.rb:293:in `require'
gems/activesupport-5.0.0/lib/active_support/dependencies.rb:293:in `block in require'
gems/activesupport-5.0.0/lib/active_support/dependencies.rb:259:in `load_dependency'
gems/activesupport-5.0.0/lib/active_support/dependencies.rb:293:in `require'
gems/ammeter-1.1.3/lib/ammeter/init.rb:2:in `<top (required)>'
gems/activesupport-5.0.0/lib/active_support/dependencies.rb:293:in `require'
gems/activesupport-5.0.0/lib/active_support/dependencies.rb:293:in `block in require'
gems/activesupport-5.0.0/lib/active_support/dependencies.rb:259:in `load_dependency'
gems/activesupport-5.0.0/lib/active_support/dependencies.rb:293:in `require'
  from spec/generators/controller/controller_generator_spec.rb:3:in `<top (required)>'

Here's another project that has had to deal with this issue: https://github.com/jfirebaugh/konacha/issues/216

It appears to specifically be an issue with sprockets-rails.

seanlinsley avatar Jul 04 '16 21:07 seanlinsley

Oh yea I see this error - sorry about that.

I'm not sure exactly what's going on but because ammeter is used by rspec-rails it hooks into the rspec & rails initialization with more knowledge than it should have. It'll take a little while for me to dig into what's changed and how to fix ammeter. I'll try to figure it out and get a fix out as soon as I can.

Thanks for pointing this out.

alexrothenberg avatar Jul 05 '16 13:07 alexrothenberg

Is this still an issue?

carlost avatar Mar 07 '18 18:03 carlost

@carlost yes, it is.

mvz avatar Mar 14 '18 18:03 mvz

It looks like the problem is that Rails.application is nil at that point.

It seems one work-around is to create a very small Rails application before loading rspec/rails. See this example.

mvz avatar Mar 14 '18 18:03 mvz

Very nice @mvz! Thank you for figuring this out! Do you want to create a pull request with your fix in it?

alexrothenberg avatar Mar 15 '18 18:03 alexrothenberg

When i setup an minimal app throws a error with:

ActiveRecord::ConnectionNotEstablished:
     No connection pool for 'ActiveRecord::Base' found.

is there some way to run without setup a database?

I can get this to work with minimum sqlite setup:

# application.rb
require "rails/all"

module RestApiGenerator
  class Application < ::Rails::Application
    config.secret_key_base = "ASecretString"

    config.generators do |g|
      g.orm :active_record
      g.test_framework nil
    end
  end
end

ActiveRecord::Base.establish_connection(
  adapter: "sqlite3",
  database: ":memory:"
)

require "ammeter/init"