Bug 1007631

Summary: require 'ammeter/init' fails
Product: [Fedora] Fedora Reporter: Ken Dreyer <ktdreyer>
Component: rubygem-ammeterAssignee: Josef Stribny <jstribny>
Status: CLOSED NOTABUG QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 20CC: bkabrda, hhorak, jstribny
Target Milestone: ---   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2014-04-07 07:39:31 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Ken Dreyer 2013-09-13 02:34:03 UTC
Description of problem:
I'm attempting to package rubygem-acts-as-taggable-on. When I run the test suite on Fedora 20, "require 'ammeter/init'" causes a crash. (On Fedora 19 the test suite will run without error.)

Version-Release number of selected component (if applicable):
rubygem-ammeter-0.2.9-1.fc20.noarch

How reproducible:
100%

Steps to Reproduce:
1. Create a test.rb file
2. Populate the test file with "require 'ammeter/init'"
3. Run "ruby test.rb"

Actual results:
A backtrace appears, complaining about "uninitialized constant Rails::VERSION". For example:

$ ruby test.rb 
/usr/share/gems/gems/rspec-rails-2.14.0/lib/rspec/rails/example/rails_example_group.rb:10:in `<module:RailsExampleGroup>': uninitialized constant Rails::VERSION (NameError)
	from /usr/share/gems/gems/rspec-rails-2.14.0/lib/rspec/rails/example/rails_example_group.rb:7:in `<module:Rails>'
	from /usr/share/gems/gems/rspec-rails-2.14.0/lib/rspec/rails/example/rails_example_group.rb:6:in `<module:RSpec>'
	from /usr/share/gems/gems/rspec-rails-2.14.0/lib/rspec/rails/example/rails_example_group.rb:5:in `<top (required)>'
	from /usr/share/rubygems/rubygems/core_ext/kernel_require.rb:51:in `require'
	from /usr/share/rubygems/rubygems/core_ext/kernel_require.rb:51:in `require'
	from /usr/share/gems/gems/ammeter-0.2.9/lib/ammeter/rspec/generator/example/generator_example_group.rb:4:in `<top (required)>'
	from /usr/share/rubygems/rubygems/core_ext/kernel_require.rb:51:in `require'
	from /usr/share/rubygems/rubygems/core_ext/kernel_require.rb:51:in `require'
	from /usr/share/gems/gems/ammeter-0.2.9/lib/ammeter/rspec/generator/example.rb:2:in `<top (required)>'
	from /usr/share/rubygems/rubygems/core_ext/kernel_require.rb:51:in `require'
	from /usr/share/rubygems/rubygems/core_ext/kernel_require.rb:51:in `require'
	from /usr/share/gems/gems/ammeter-0.2.9/lib/ammeter/init.rb:1:in `<top (required)>'
	from /usr/share/rubygems/rubygems/core_ext/kernel_require.rb:116:in `require'
	from /usr/share/rubygems/rubygems/core_ext/kernel_require.rb:116:in `rescue in require'
	from /usr/share/rubygems/rubygems/core_ext/kernel_require.rb:122:in `require'
	from test.rb:1:in `<main>'



Expected results:
No output (ammeter should load successfully).


Additional info:
I've narrowed the problem to this line:

require 'ammeter/rspec/generator/example/generator_example_group'

Also, adding a monkey-patch to the top of test.rb will avoid the crash:

module Rails
  module VERSION
    MAJOR = 4
    MINOR = 0
    TINY = 0
    PRE = ""

    STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".")
  end

  def self.version
    VERSION::STRING
  end
end

This doesn't seem ideal, because I would need to add this monkey patch to the gem that I'm attempting to package (acts-as-taggable-on). What is the best solution?

Comment 1 Josef Stribny 2013-09-23 10:23:39 UTC
Hi,

you need to require 'rails' since the file you mentioned [1] relies on the Rails VERSION constant as requiring 'ammeter' already does [2]. Monkey patch is a bad idea, rubygem-ammeter has rubygem-railties as a dependency. Just require Rails before 'ammeter/init' or require 'ammeter' instead.

The order of requires should be probably changed in ammeter/init.rb so that rails requirement comes first. I filled the pull request to upstream[3].

[1] https://github.com/rspec/rspec-rails/blob/master/lib/rspec/rails/example/rails_example_group.rb#L10
[2] https://github.com/alexrothenberg/ammeter/blob/master/lib/ammeter.rb
[3] https://github.com/alexrothenberg/ammeter/pull/22

Comment 2 Ken Dreyer 2013-09-23 12:51:12 UTC
Cool, thanks. On acts-as-taggable-on's side, do you think it would be appropriate for acts-as-taggable-on to first try loading "ammeter/init", catch the LoadError, and then try "ammeter"?

Comment 3 Josef Stribny 2013-09-23 13:49:17 UTC
Well, I am not sure. First of all it might be that upstream now prefers requiring just 'ammeter'. If the test suite works with requiring 'ammeter', I would change that line to load ammeter (using sed for example). You can change it back in the spec file when it's fixed and you know that upstream of acts-as-taggable-on continue to use it and that it has been fixed.

Comment 4 Ken Dreyer 2013-09-23 14:43:49 UTC
I was wondering if the ammeter upstream developer has altered his preference for "ammeter" vs "ammeter/init". If that's the case, how can we make ammeter consumers (like acts-as-taggable-on) be forwards- and backwards- compatible?

Comment 5 Josef Stribny 2014-04-07 07:39:31 UTC
Unfortunately upstream is sort of unresponsive in this matter. It's probably not a bug from their point of view. Please require just 'ammeter' for now.

Comment 6 Ken Dreyer 2014-12-06 18:12:50 UTC
Thanks Josef. And just to close the loop as far as acts-as-taggable-on is concerned, upstream has removed the dependency on ammeter.