0
我在測試我的rails應用程序時遇到問題。我有我的測試驗證碼:測試中的每個循環都會僞造變量
describe Categoria do
let(:categoria) { FactoryGirl.create(:categoria) }
it { should be_valid }
describe "agregar campos" do
before { @campo = categoria.campos.build(nombre: "campo1", tipo_campo: "check_box") }
it { @campo.should be_valid }
it { @campo.should respond_to :nombre }
it { @campo.should respond_to :tipo_campo }
it { @campo.should respond_to :requerido }
describe "valores válidos" do
valores = %w[texto texto_extenso numero decimal check_box]
valores.each do |valido|
@campo.tipo_campo = valido
@campo.should be_valid
end
end
end
end
如果我運行而不堵「VALORESválidos」這個試驗中的所有其他測試都通過了,但是當我運行所有測試,我得到這個錯誤:
Rack::File headers parameter replaces cache_control after Rack 1.5.
Exception encountered: #<NoMethodError: undefined method `tipo_campo=' for nil:NilClass>
backtrace:
/home/alejo/proyectos/lachiquitienda/spec/models/categoria_spec.rb:38:in `block (4 levels) in <top (required)>'
/home/alejo/proyectos/lachiquitienda/spec/models/categoria_spec.rb:37:in `each'
/home/alejo/proyectos/lachiquitienda/spec/models/categoria_spec.rb:37:in `block (3 levels) in <top (required)>'
/home/alejo/.rvm/gems/ruby-1.9.3-p374/gems/rspec-core-2.11.1/lib/rspec/core/example_group.rb:238:in `module_eval'
/home/alejo/.rvm/gems/ruby-1.9.3-p374/gems/rspec-core-2.11.1/lib/rspec/core/example_group.rb:238:in `subclass'
/home/alejo/.rvm/gems/ruby-1.9.3-p374/gems/rspec-core-2.11.1/lib/rspec/core/example_group.rb:224:in `describe'
/home/alejo/proyectos/lachiquitienda/spec/models/categoria_spec.rb:35:in `block (2 levels) in <top (required)>'
/home/alejo/.rvm/gems/ruby-1.9.3-p374/gems/rspec-core-2.11.1/lib/rspec/core/example_group.rb:238:in `module_eval'
/home/alejo/.rvm/gems/ruby-1.9.3-p374/gems/rspec-core-2.11.1/lib/rspec/core/example_group.rb:238:in `subclass'
/home/alejo/.rvm/gems/ruby-1.9.3-p374/gems/rspec-core-2.11.1/lib/rspec/core/example_group.rb:224:in `describe'
/home/alejo/proyectos/lachiquitienda/spec/models/categoria_spec.rb:27:in `block in <top (required)>'
/home/alejo/.rvm/gems/ruby-1.9.3-p374/gems/rspec-core-2.11.1/lib/rspec/core/example_group.rb:238:in `module_eval'
/home/alejo/.rvm/gems/ruby-1.9.3-p374/gems/rspec-core-2.11.1/lib/rspec/core/example_group.rb:238:in `subclass'
/home/alejo/.rvm/gems/ruby-1.9.3-p374/gems/rspec-core-2.11.1/lib/rspec/core/example_group.rb:224:in `describe'
/home/alejo/.rvm/gems/ruby-1.9.3-p374/gems/rspec-core-2.11.1/lib/rspec/core/dsl.rb:18:in `describe'
/home/alejo/proyectos/lachiquitienda/spec/models/categoria_spec.rb:5:in `<top (required)>'
/home/alejo/.rvm/gems/ruby-1.9.3-p374/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:245:in `load'
/home/alejo/.rvm/gems/ruby-1.9.3-p374/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:245:in `block in load'
/home/alejo/.rvm/gems/ruby-1.9.3-p374/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:236:in `load_dependency'
/home/alejo/.rvm/gems/ruby-1.9.3-p374/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:245:in `load'
/home/alejo/.rvm/gems/ruby-1.9.3-p374/gems/rspec-core-2.11.1/lib/rspec/core/configuration.rb:780:in `block in load_spec_files'
/home/alejo/.rvm/gems/ruby-1.9.3-p374/gems/rspec-core-2.11.1/lib/rspec/core/configuration.rb:780:in `map'
/home/alejo/.rvm/gems/ruby-1.9.3-p374/gems/rspec-core-2.11.1/lib/rspec/core/configuration.rb:780:in `load_spec_files'
/home/alejo/.rvm/gems/ruby-1.9.3-p374/gems/rspec-core-2.11.1/lib/rspec/core/command_line.rb:22:in `run'
/home/alejo/.rvm/gems/ruby-1.9.3-p374/gems/spork-0.9.2/lib/spork/test_framework/rspec.rb:11:in `run_tests'
/home/alejo/.rvm/gems/ruby-1.9.3-p374/gems/spork-0.9.2/lib/spork/run_strategy/forking.rb:13:in `block in run'
/home/alejo/.rvm/gems/ruby-1.9.3-p374/gems/spork-0.9.2/lib/spork/forker.rb:21:in `block in initialize'
/home/alejo/.rvm/gems/ruby-1.9.3-p374/gems/spork-0.9.2/lib/spork/forker.rb:18:in `fork'
/home/alejo/.rvm/gems/ruby-1.9.3-p374/gems/spork-0.9.2/lib/spork/forker.rb:18:in `initialize'
/home/alejo/.rvm/gems/ruby-1.9.3-p374/gems/spork-0.9.2/lib/spork/run_strategy/forking.rb:9:in `new'
/home/alejo/.rvm/gems/ruby-1.9.3-p374/gems/spork-0.9.2/lib/spork/run_strategy/forking.rb:9:in `run'
/home/alejo/.rvm/gems/ruby-1.9.3-p374/gems/spork-0.9.2/lib/spork/server.rb:48:in `run'
/home/alejo/.rvm/rubies/ruby-1.9.3-p374/lib/ruby/1.9.1/drb/drb.rb:1548:in `perform_without_block'
/home/alejo/.rvm/rubies/ruby-1.9.3-p374/lib/ruby/1.9.1/drb/drb.rb:1508:in `perform'
/home/alejo/.rvm/rubies/ruby-1.9.3-p374/lib/ruby/1.9.1/drb/drb.rb:1586:in `block (2 levels) in main_loop'
/home/alejo/.rvm/rubies/ruby-1.9.3-p374/lib/ruby/1.9.1/drb/drb.rb:1582:in `loop'
/home/alejo/.rvm/rubies/ruby-1.9.3-p374/lib/ruby/1.9.1/drb/drb.rb:1582:in `block in main_loop'
[Finished in 5.9s]
爲什麼@campo零iniside每個循環?
在此先感謝
非常感謝,這工作。這就是我喜歡stackoverflow的原因 – Alejo 2013-02-27 16:44:44