2010-03-30 5 views
2

J'essaie de mettre quelques spécifications autour d'un nouveau projet de rails 3 sur lequel je travaille, et mon premier test ne semble pas pouvoir trouver un modèle.rspec & rails 3 Je ne trouve pas l'objet du modèle

J'ai installé rspec de la ligne de commande en utilisant:

sudo gem install rspec --pre 

puis je mets ce qui suit dans mon Gemfile

gem "rspec-rails", ">= 2.0.0.beta.1" 

Mais quand je lance mon test je reçois

./spec/models/world_spec.rb:1: uninitialized constant World (NameError) 
rake aborted! 
Command /opt/local/bin/ruby -Ilib -Ispec "./spec/models/world_spec.rb" failed 
/opt/local/lib/ruby/gems/1.8/gems/rspec-core-2.0.0.beta.4/lib/rspec/core/rake_task.rb:71:in 'define' 
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:1112:in 'verbose' 
/opt/local/lib/ruby/gems/1.8/gems/rspec-core-2.0.0.beta.4/lib/rspec/core/rake_task.rb:57:in 'send' 
/opt/local/lib/ruby/gems/1.8/gems/rspec-core-2.0.0.beta.4/lib/rspec/core/rake_task.rb:57:in 'define' 
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:636:in 'call' 
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:636:in 'execute' 
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:631:in 'each' 
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:631:in 'execute' 
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:597:in 'invoke_with_call_chain' 
/opt/local/lib/ruby/1.8/monitor.rb:242:in 'synchronize' 
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:590:in 'invoke_with_call_chain' 
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:583:in 'invoke' 
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2051:in 'invoke_task' 
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in 'top_level' 
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in 'each' 
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in 'top_level' 
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2068:in 'standard_exception_handling' 
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2023:in 'top_level' 
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2001:in 'run' 
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2068:in 'standard_exception_handling' 
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:1998:in 'run' 
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/bin/rake:31 
/opt/local/bin/rake:19:in 'load' 
/opt/local/bin/rake:19 

Mes spécifications se trouvent dans spec/models/world_spec.rb et ressemblent à

describe World, "#hello" do 
     it "should be invalid" do 
     World.new.should be_invalid? 
     end 
    end 

J'ai essayé d'ajouter une ligne comme require "app/model/world" et require "world" mais sans succès.

Est-ce que quelqu'un sait ce que je fais mal?

Répondre

4

Semble dans des rails 3 Je dois require 'spec_helper'

require 'spec_helper' 

describe World do 
    it "should be invalid" do 
    World.new.should be_invalid? 
    end 
end 

Mais cela pourrait bien être parce que je suis en train de courir rake spec si vous utilisez watchr ou un autre mécanisme que vous pourriez être en mesure d'obtenir ce fait pour toi.

+0

Qu'avez-vous dans spec_helper? – CanCeylan

Questions connexes