0

我的对象“Line”的所有功能测试都失败了。我什至不知道从哪里开始调试这个:

21) 错误:test_should_update_line(LinesControllerTest): NoMethodError: undefined method name' for false:FalseClass c:/Ruby193/lib/ruby/gems/1.9.1/gems/factory_girl-4.0.0/lib/factory_girl/decl aration/static.rb:11:in==' c:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-3.2.3/lib/active_record/att ribute_methods/write.rb: 57:in convert_number_column_value' c:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-3.2.3/lib/active_record/att ribute_methods/write.rb:50:intype_cast_attribute_for_write' c:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-3.2.3/lib/active_record/att ribute_methods/serialization.rb:88:in type_cast_attribute_for_write' c:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-3.2.3/lib/active_record/att ribute_methods/write.rb:38:inwrite_attribute' c:/Ruby193/lib /ruby/gems/1.9.1/gems/activerecord-3.2.3/lib/active_record/att ribute_methods/dirty.rb:67:in write_attribute' c:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-3.2.3/lib/active_record/att ribute_methods/write.rb:14:inport=' c:/Ruby193/lib/ruby/gems/1.9.1/gems /factory_girl-4.0.0/lib/factory_girl/attr ibute_assigner.rb:16:in block (2 levels) in object' c:/Ruby193/lib/ruby/gems/1.9.1/gems/factory_girl-4.0.0/lib/factory_girl/attr ibute_assigner.rb:15:ineach' c:/Ruby193/lib/ruby/gems/1.9.1/gems/factory_girl-4.0.0/lib/factory_girl/attr ibute_assigner .rb:15:inblock in object' c:/Ruby193/lib/ruby/gems/1.9.1/gems/factory_girl-4.0.0/lib/factory_girl/attr ibute_assigner.rb:14:in点击' c:/Ruby193/lib/ruby/gems/1.9.1/gems/factory_girl-4.0.0/lib/factory_girl/attr ibute_assigner.rb:14:in object' c:inobject' c:/Ruby193/lib/ruby/gems/ 1.9.1/gems/factory_girl-4.0.0/lib/factory_girl/stra tegy/create.rb:9:in result' c:/Ruby193/lib/ruby/gems/1.9.1/gems/factory_girl-4.0.0/lib/factory_girl/fact ory.rb:42:inrun' c:/Ruby193/lib/ruby/gems/1.9.1/gems/factory_girl-4.0.0 /lib/factory_girl/factory_runner.rb:23:inblock in run' c:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-3.2.3/lib/active_support/n otifications.rb:125:in仪器'c:/Ruby193/lib/ruby/gems/1.9.1/gems/factory_girl-4.0.0/lib/factory_girl/factory_runner.rb:22:inrun' c:/Ruby193/lib/ruby/gems/1.9.1/gems/factory_girl-4.0.0/lib/factory_girl/stra tegy_syntax_method_registrar.rb:19:in块中的define_singular_strategy_method'

c:/code/vsdb/test/functional/lines_controller_test.rb:5:in `block in <class: LinesControllerTest>'
c:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-3.2.3/lib/active_support/c

allbacks.rb:462:in _run__987382823__setup__855471168__callbacks' c:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-3.2.3/lib/active_support/c allbacks.rb:405:in__run_callback'c:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-3.2.3/lib/active_support/c allbacks.rb:385:in _run_setup_callbacks' c:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-3.2.3/lib/active_support/c allbacks.rb:81:inrun_callbacks'c:/Ruby193 /lib/ruby/gems/1.9.1/gems/activesupport-3.2.3/lib/active_support/testing/setup_and_teardown.rb:34:in `run'

lines_controller_test.rb:

类 LinesControllerTest < ActionController::TestCase
setup do @line = FactoryGirl.create(:line)
end

test "should update line" do
  put :update, id: @line, line: { description: @line.description }
  assert_redirected_to line_path(assigns(:line))   
end

结尾

test_helper.rb:

ENV["RAILS_ENV"] = "test" 需要 File.expand_path('../../config/environment', FILE ) 需要 'rails/test_help' 需要 'capybara/rails'

class ActiveSupport::TestCase # 按字母顺序为所有测试设置 test/fixtures/*.(yml|csv) 中的所有夹具。# # 注意:你目前仍然需要在集成测试中显式声明fixtures # -- 它们还没有继承这个设置

def setup #各种所有者 @admin = FactoryGirl.create(:owner, iso:true, admin:true) @iso = FactoryGirl.create(:owner, iso:true) @isa = FactoryGirl.create(:owner) #默认为管理员 @controller.stubs(:current_owner).returns(@admin)

#fixtures for compliance rates verification
@art = FactoryGirl.create(:unit, name: "art", unit_code: "1110000", parent_unit_id: 1100000)   end

# 在此处添加更多供所有测试使用的辅助方法... end

类 ActionDispatch::IntegrationTest 包括 Capybara::DSL

def 拆解 Capybara.reset_sessions!Capybara.use_default_driver end end

4

1 回答 1

0

看起来你正在传递@line更新你应该传递的地方@line.id。尝试将其更改为:

put :update, id: @line.id, line: { description: @line.description }
于 2012-08-20T22:00:42.843 回答