rspec / rspec-core

RSpec runner and formatters
http://rspec.info
MIT License
1.23k stars 764 forks source link

Rpsec.configuration before doesn't run #105

Closed emerleite closed 14 years ago

emerleite commented 14 years ago

Hi, I'm using Rspec 2.0.0.beta.19 and having some issues with Rspec.configuration | Rspec.configure

When I use Rspec.configure, fixture_path doesn't exists anymore and I receive an error. When I use Rspec.configuration, config.before is not executed anymore.

I think this is an issue.

Thanks,

Emerson

dchelimsky commented 14 years ago

It is now RSpec.configure (with a capital "S"). Please change Rspec to RSpec and report back if that works.

emerleite commented 14 years ago

Doesn't work. I receive undefined method `fixture_path=' for #RSpec::Core::Configuration:0x101566948 (NoMethodError) same as when I use Rspec.configure

When I use Rspec.configuration It works, but the before statement doesn't execute.

Cheers,

Emerson

justinko commented 14 years ago

You forgot to add require "rspec/rails" above the configuration block.

dchelimsky commented 14 years ago

@emerlite - is @justinko correct? Please verify so I can close this. Thx.

emerleite commented 14 years ago

No, he isn't. I've alread added the require statement

dchelimsky commented 14 years ago

@emerleite - please post your spec_helper and any error messages you're seeing.

dchelimsky commented 14 years ago

@emerleite - also, what is the command you're using to run and where do the files that are failing live (i.e. directories and filenames)

emerleite commented 14 years ago
Rspec.configure do |config|
  config.mock_with :rspec
  config.fixture_path = "#{::Rails.root}/spec/fixtures"
  config.before :each do
    CleanDatabase.clean!
  end
end

The error is:

/Users/emerson.leite/Projetos/webmedia-sync/spec/spec_helper.rb:26: undefined   method `fixture_path=' for #<RSpec::Core::Configuration:0x101566948> (NoMethodError)
from /Users/emerson.leite/.rvm/gems/ruby-1.8.7-p299@webmedia-sync/gems/rspec-core-2.0.0.beta.19/lib/rspec/core.rb:61:in `configure'
from /Users/emerson.leite/Projetos/webmedia-sync/spec/spec_helper.rb:12
from /Users/emerson.leite/Projetos/webmedia-sync/spec/controllers/videos_controller_spec.rb:1:in `require'
from /Users/emerson.leite/Projetos/webmedia-sync/spec/controllers/videos_controller_spec.rb:1
from /Users/emerson.leite/.rvm/gems/ruby-1.8.7-p299@webmedia-sync/gems/rspec-core-2.0.0.beta.19/lib/rspec/core/configuration.rb:288:in `require'
from /Users/emerson.leite/.rvm/gems/ruby-1.8.7-p299@webmedia-sync/gems/rspec-core-2.0.0.beta.19/lib/rspec/core/configuration.rb:288:in `require_files_to_run'
from /Users/emerson.leite/.rvm/gems/ruby-1.8.7-p299@webmedia-sync/gems/rspec-core-2.0.0.beta.19/lib/rspec/core/configuration.rb:288:in `map'
from /Users/emerson.leite/.rvm/gems/ruby-1.8.7-p299@webmedia-sync/gems/rspec-core-2.0.0.beta.19/lib/rspec/core/configuration.rb:288:in `require_files_to_run'
from /Users/emerson.leite/.rvm/gems/ruby-1.8.7-p299@webmedia-sync/gems/rspec-core-2.0.0.beta.19/lib/rspec/core/command_line.rb:18:in `run'
from /Users/emerson.leite/.rvm/gems/ruby-1.8.7-p299@webmedia-sync/gems/rspec-core-2.0.0.beta.19/lib/rspec/core/runner.rb:46:in `run_in_process'
from /Users/emerson.leite/.rvm/gems/ruby-1.8.7-p299@webmedia-sync/gems/rspec-core-2.0.0.beta.19/lib/rspec/core/runner.rb:37:in `run'
from /Users/emerson.leite/.rvm/gems/ruby-1.8.7-p299@webmedia-sync/gems/rspec-core-2.0.0.beta.19/lib/rspec/core/runner.rb:10:in `autorun'
from /Users/emerson.leite/.rvm/gems/ruby-1.8.7-p299@webmedia-sync/bin/rspec:19
emerleite commented 14 years ago

To solve this, I changed this configuration to this:

Rspec.configure do |config|
  config.mock_with :rspec
  config.before :each do
    CleanDatabase.clean!
  end
end

Rspec.configuration do |config|
  config.fixture_path = "#{::Rails.root}/spec/fixtures"
end

It works

dchelimsky commented 14 years ago

Please post the entire spec_helper.rb file. A gist or pastie would be best so I can see the line numbers. Thx.

dchelimsky commented 14 years ago

That might remove the error, but that's just because RSpec.configuration doesn't do anything with the block that's passed to it, so fixture_path is not getting set.

emerleite commented 14 years ago

spec_helper_unit.rb - http://pastie.org/1098096 spec_helper.rb - http://pastie.org/1098094

/Users/emerson.leite/Projetos/webmedia-sync/spec/spec_helper.rb:27: undefined method `fixture_path=' for #<RSpec::Core::Configuration:0x101566948> (NoMethodError)
from /Users/emerson.leite/.rvm/gems/ruby-1.8.7-p299@webmedia-sync/gems/rspec-core-2.0.0.beta.19/lib/rspec/core.rb:61:in `configure'
from /Users/emerson.leite/Projetos/webmedia-sync/spec/spec_helper.rb:12
from /Users/emerson.leite/Projetos/webmedia-sync/spec/controllers/videos_controller_spec.rb:1:in `require'
from /Users/emerson.leite/Projetos/webmedia-sync/spec/controllers/videos_controller_spec.rb:1
from /Users/emerson.leite/.rvm/gems/ruby-1.8.7-p299@webmedia-sync/gems/rspec-core-2.0.0.beta.19/lib/rspec/core/configuration.rb:288:in `require'
from /Users/emerson.leite/.rvm/gems/ruby-1.8.7-p299@webmedia-sync/gems/rspec-core-2.0.0.beta.19/lib/rspec/core/configuration.rb:288:in `require_files_to_run'
from /Users/emerson.leite/.rvm/gems/ruby-1.8.7-p299@webmedia-sync/gems/rspec-core-2.0.0.beta.19/lib/rspec/core/configuration.rb:288:in `map'
from /Users/emerson.leite/.rvm/gems/ruby-1.8.7-p299@webmedia-sync/gems/rspec-core-2.0.0.beta.19/lib/rspec/core/configuration.rb:288:in `require_files_to_run'
from /Users/emerson.leite/.rvm/gems/ruby-1.8.7-p299@webmedia-sync/gems/rspec-core-2.0.0.beta.19/lib/rspec/core/command_line.rb:18:in `run'
from /Users/emerson.leite/.rvm/gems/ruby-1.8.7-p299@webmedia-sync/gems/rspec-core-2.0.0.beta.19/lib/rspec/core/runner.rb:46:in `run_in_process'
from /Users/emerson.leite/.rvm/gems/ruby-1.8.7-p299@webmedia-sync/gems/rspec-core-2.0.0.beta.19/lib/rspec/core/runner.rb:37:in `run'
from /Users/emerson.leite/.rvm/gems/ruby-1.8.7-p299@webmedia-sync/gems/rspec-core-2.0.0.beta.19/lib/rspec/core/runner.rb:10:in `autorun'
from /Users/emerson.leite/.rvm/gems/ruby-1.8.7-p299@webmedia-sync/bin/rspec:19
dchelimsky commented 14 years ago

I don't think this will help, but please change Rspec to RSpec.

Otherwise, I'm at a loss. It seems that the configuration form rspec-rails is not being loaded, but the one from rspec-core is.

What's in your Gemfile?

emerleite commented 14 years ago

Usign RSpec I got the same error.

My Gemfile:

gem 'rspec', '>= 2.0.0.beta.19'
gem 'rspec-core', '>= 2.0.0.beta.19', :require => 'rspec/core'
gem 'rspec-expectations', '>= 2.0.0.beta.19', :require => 'rspec/expectations'
gem 'rspec-mocks', '>= 2.0.0.beta.19', :require => 'rspec/mocks'
gem 'rspec-rails', '>= 2.0.0.beta.19'
dchelimsky commented 14 years ago

Try getting rid of everything but rspec-rails.

emerleite commented 14 years ago

Doesn't work:

/Users/emerson.leite/.rvm/gems/ruby-1.8.7-p299@webmedia-sync/gems/dm-rails-1.0.3/lib/dm-rails/railties/log_subscriber.rb:4: uninitialized constant ActiveSupport::LogSubscriber (NameError)
from /Users/emerson.leite/.rvm/gems/ruby-1.8.7-p299@webmedia-sync/gems/dm-rails-1.0.3/lib/dm-rails/railtie.rb:16:in `require'
from /Users/emerson.leite/.rvm/gems/ruby-1.8.7-p299@webmedia-sync/gems/dm-rails-1.0.3/lib/dm-rails/railtie.rb:16
from /Users/emerson.leite/.rvm/gems/ruby-1.8.7-p299@webmedia-sync/gems/dm-rails-1.0.3/lib/dm-rails.rb:1:in `require'
from /Users/emerson.leite/.rvm/gems/ruby-1.8.7-p299@webmedia-sync/gems/dm-rails-1.0.3/lib/dm-rails.rb:1
from /Users/emerson.leite/Projetos/webmedia-sync/.bundle/environment.rb:329:in `require'
from /Users/emerson.leite/Projetos/webmedia-sync/.bundle/environment.rb:329:in `require'
from /Users/emerson.leite/Projetos/webmedia-sync/.bundle/environment.rb:324:in `each'
from /Users/emerson.leite/Projetos/webmedia-sync/.bundle/environment.rb:324:in `require'
from /Users/emerson.leite/Projetos/webmedia-sync/.bundle/environment.rb:323:in `each'
from /Users/emerson.leite/Projetos/webmedia-sync/.bundle/environment.rb:323:in `require'
from /Users/emerson.leite/Projetos/webmedia-sync/config/application.rb:9
from /Users/emerson.leite/Projetos/webmedia-sync/spec/../config/environment.rb:2:in `require'
from /Users/emerson.leite/Projetos/webmedia-sync/spec/../config/environment.rb:2
from /Users/emerson.leite/Projetos/webmedia-sync/spec/spec_helper_unit.rb:2:in `require'
from /Users/emerson.leite/Projetos/webmedia-sync/spec/spec_helper_unit.rb:2
from /Users/emerson.leite/Projetos/webmedia-sync/spec/spec_helper.rb:4:in `require'
from /Users/emerson.leite/Projetos/webmedia-sync/spec/spec_helper.rb:4
from /Users/emerson.leite/Projetos/webmedia-sync/spec/controllers/videos_controller_spec.rb:1:in `require'
from /Users/emerson.leite/Projetos/webmedia-sync/spec/controllers/videos_controller_spec.rb:1
from /Users/emerson.leite/.rvm/gems/ruby-1.8.7-p299@webmedia-sync/gems/rspec-core-2.0.0.beta.19/lib/rspec/core/configuration.rb:288:in `require'
from /Users/emerson.leite/.rvm/gems/ruby-1.8.7-p299@webmedia-sync/gems/rspec-core-2.0.0.beta.19/lib/rspec/core/configuration.rb:288:in `require_files_to_run'
from /Users/emerson.leite/.rvm/gems/ruby-1.8.7-p299@webmedia-sync/gems/rspec-core-2.0.0.beta.19/lib/rspec/core/configuration.rb:288:in `map'
from /Users/emerson.leite/.rvm/gems/ruby-1.8.7-p299@webmedia-sync/gems/rspec-core-2.0.0.beta.19/lib/rspec/core/configuration.rb:288:in `require_files_to_run'
from /Users/emerson.leite/.rvm/gems/ruby-1.8.7-p299@webmedia-sync/gems/rspec-core-2.0.0.beta.19/lib/rspec/core/command_line.rb:18:in `run'
from /Users/emerson.leite/.rvm/gems/ruby-1.8.7-p299@webmedia-sync/gems/rspec-core-2.0.0.beta.19/lib/rspec/core/runner.rb:46:in `run_in_process'
from /Users/emerson.leite/.rvm/gems/ruby-1.8.7-p299@webmedia-sync/gems/rspec-core-2.0.0.beta.19/lib/rspec/core/runner.rb:37:in `run'
from /Users/emerson.leite/.rvm/gems/ruby-1.8.7-p299@webmedia-sync/gems/rspec-core-2.0.0.beta.19/lib/rspec/core/runner.rb:10:in `autorun'
from /Users/emerson.leite/.rvm/gems/ruby-1.8.7-p299@webmedia-sync/bin/rspec:19
justinko commented 14 years ago

The fact that you're using dm-rails (data mapper) would be nice to know, don't ya think?

emerleite commented 14 years ago

Yep. My fault, but adding the other rspec gems this error dissapear.

justinko commented 14 years ago

1.) Get rid of spec_helper_unit.rb (or not require it) 2.) Make your spec_helper.rb look EXACTLY like this: http://github.com/datamapper/dm-rails

emerleite commented 14 years ago

Doesn't make sense, because in this docs config.fixture_path is commented. So obviously I'll not receive the error. Any other sugestion? Cheers

justinko commented 14 years ago

Obviously, uncomment that line. If you're still having issues after that, it is a dm-rails issue.

dm-rails needs to support RSpec, not RSpec supports dm-rails.

Good luck.

dchelimsky commented 14 years ago

@emerleite - what's the latest on this?

emerleite commented 14 years ago

Probably really a dm-rails bug. You can close it.

Cheers

dchelimsky commented 14 years ago

Cool. Thanks. Please do feel free to open a new one if you are able to narrow this down to rspec.

Cheers, David