zenspider / minitest-matchers

33 stars 7 forks source link

uninitialized constant Object::Test - When using ValidAttribute & Minitest-Matchers #2

Closed rosstimson closed 13 years ago

rosstimson commented 13 years ago

I cannot seem to get ValidAttribute working with Minitest-Matchers and get uninitialized constant Object::Test as soon as I try running rake test. As soon as I remove ValidAttribute from my app everything works fine. I have also tried with Shoulda-Context and it seemed to work as expected. I originally posted this issue as a ValidAttribute issue but got advised that it was more appropriate as an issue with Minitest-Matchers itself (original issue: https://github.com/bcardarella/valid_attribute/issues/14) Apologies in advance if I'm being a n00b here.

System

rake aborted!
uninitialized constant Object::Test
/Users/rosstimson/.rvm/gems/ruby-1.9.2-p290@global/gems/rake-0.9.2/lib/rake/ext/module.rb:36:in `const_missing'
/Users/rosstimson/.rvm/gems/ruby-1.9.2-p290/gems/valid_attribute-1.2.0/lib/valid_attribute/test_unit.rb:1:in `<top (required)>'
/Users/rosstimson/.rvm/gems/ruby-1.9.2-p290/gems/valid_attribute-1.2.0/lib/valid_attribute.rb:13:in `require'
/Users/rosstimson/.rvm/gems/ruby-1.9.2-p290/gems/valid_attribute-1.2.0/lib/valid_attribute.rb:13:in `<top (required)>'
/Users/rosstimson/.rvm/gems/ruby-1.9.2-p290/gems/bundler-1.0.18/lib/bundler/runtime.rb:68:in `require'
/Users/rosstimson/.rvm/gems/ruby-1.9.2-p290/gems/bundler-1.0.18/lib/bundler/runtime.rb:68:in `block (2 levels) in require'
/Users/rosstimson/.rvm/gems/ruby-1.9.2-p290/gems/bundler-1.0.18/lib/bundler/runtime.rb:66:in `each'
/Users/rosstimson/.rvm/gems/ruby-1.9.2-p290/gems/bundler-1.0.18/lib/bundler/runtime.rb:66:in `block in require'
/Users/rosstimson/.rvm/gems/ruby-1.9.2-p290/gems/bundler-1.0.18/lib/bundler/runtime.rb:55:in `each'
/Users/rosstimson/.rvm/gems/ruby-1.9.2-p290/gems/bundler-1.0.18/lib/bundler/runtime.rb:55:in `require'
/Users/rosstimson/.rvm/gems/ruby-1.9.2-p290/gems/bundler-1.0.18/lib/bundler.rb:120:in `require'
/Users/rosstimson/code/ruby/valid-attrib/config/application.rb:7:in `<top (required)>'
/Users/rosstimson/code/ruby/valid-attrib/Rakefile:5:in `require'
/Users/rosstimson/code/ruby/valid-attrib/Rakefile:5:in `<top (required)>'
/Users/rosstimson/.rvm/gems/ruby-1.9.2-p290@global/gems/rake-0.9.2/lib/rake/rake_module.rb:25:in `load'
/Users/rosstimson/.rvm/gems/ruby-1.9.2-p290@global/gems/rake-0.9.2/lib/rake/rake_module.rb:25:in `load_rakefile'
/Users/rosstimson/.rvm/gems/ruby-1.9.2-p290@global/gems/rake-0.9.2/lib/rake/application.rb:495:in `raw_load_rakefile'
/Users/rosstimson/.rvm/gems/ruby-1.9.2-p290@global/gems/rake-0.9.2/lib/rake/application.rb:78:in `block in load_rakefile'
/Users/rosstimson/.rvm/gems/ruby-1.9.2-p290@global/gems/rake-0.9.2/lib/rake/application.rb:129:in `standard_exception_handling'
/Users/rosstimson/.rvm/gems/ruby-1.9.2-p290@global/gems/rake-0.9.2/lib/rake/application.rb:77:in `load_rakefile'
/Users/rosstimson/.rvm/gems/ruby-1.9.2-p290@global/gems/rake-0.9.2/lib/rake/application.rb:61:in `block in run'
/Users/rosstimson/.rvm/gems/ruby-1.9.2-p290@global/gems/rake-0.9.2/lib/rake/application.rb:129:in `standard_exception_handling'
/Users/rosstimson/.rvm/gems/ruby-1.9.2-p290@global/gems/rake-0.9.2/lib/rake/application.rb:59:in `run'
/Users/rosstimson/.rvm/gems/ruby-1.9.2-p290@global/gems/rake-0.9.2/bin/rake:32:in `<top (required)>'
/Users/rosstimson/.rvm/gems/ruby-1.9.2-p290/bin/rake:19:in `load'
/Users/rosstimson/.rvm/gems/ruby-1.9.2-p290/bin/rake:19:in `<main>'
wojtekmach commented 13 years ago

Hi, From your stack trace:

/Users/rosstimson/.rvm/gems/ruby-1.9.2-p290/gems/valid_attribute-1.2.0/lib/valid_attribute/test_unit.rb:1:in `<top (required)>'
/Users/rosstimson/.rvm/gems/ruby-1.9.2-p290/gems/valid_attribute-1.2.0/lib/valid_attribute.rb:13:in `require'

In valid attribute we have:

8  if defined?(RSpec)
9    require 'valid_attribute/rspec'
10 elsif defined?(MiniTest::Matchers)
11   require 'valid_attribute/minitest'
12 else
13   require 'valid_attribute/test_unit'
14 end

So it seems MiniTest::Matchers is not yet loaded. Was that your whole test_helper or do you have more requires? Maybe valid_attribute is loaded in some other place before and that require in test_helper has no effect (returns false). In order that to work minitest-matchers must be loaded before valid_attribute.

rosstimson commented 13 years ago

I made sure my requires were in the correct order (I don't have anything else in there - this is a fresh project just for testing this) and still got same error. I then moved minitest, minitest-matchers and valid_attribute into the test group in my Gemfile and it seems to work fine. I previously had these gems in no specific group in the Gemfile as I didn't think it would matter too much and the readmes for both minitest-matchers and valid_attribute do not specify that the gems must be added to just the test group.

This leads me back to my 'real' project that I'm trying to set this up with. Putting everything in the test group within the Gemfile works fine but as soon as I add in minitest-rails into the development group the error comes back. The same happens if I have minitest-matchers and valid_attribute within the test group and minitest itself without a group defined.

So this looks like it is down to something strange happening with the environments and Bundler however this is above my head. I would imagine a lot of people using these gems will be using minitest-rails and it is this which is pulling in the minitest gem into the development environment which triggers the errors.

wojtekmach commented 13 years ago

Hi, putting valid_attribute into development group triggers the error, because of Bundler autoloading. valid_attribute is autoloaded, but minitest-matchers isn't. You can however use it like this:

gem "minitest-matchers", :require => "minitest/matchers"

I'll fix it in next release.

I couldn't reproduce "(...) as soon as I add in minitest-rails into the development group the error comes back (...)" and "(...) The same happens if I have minitest-matchers and valid_attribute within the test group (...)"

rosstimson commented 13 years ago

Ah, adding the require statement within the Gemfile has done the trick. Everything works fine with the minitest gem, or more importantly the minitest-rails gem specified within the development group now too.

Thanks very much for you help and code.

ream88 commented 12 years ago

Any update on this? Problem still exists in 1.1.2

wojtekmach commented 12 years ago

Right, forgot to add this to Manifest. It's fixed in 1.1.3. Thanks!

ream88 commented 12 years ago

Thank you :)