NameError:未定义的局部变量或方法`current_protocol_version&#39;对于#<app:0x007fcc0cb32010> </app:0x007fcc0cb32010>

时间:2014-03-21 03:47:41

标签: ruby-on-rails ruby unit-testing timestamp nameerror

我的单元测试存在一些问题。

当我运行我的单元测试时,我遇到了一些问题:

  1. timestamp

  2. undefined loacal variable or method

  3. ========== 1 ============

    当我运行单元测试时,timpestampdate field出错。它说:

      -      "date"=>"2011-11-05T22:03:54+09:00",
      ?                           ^        ^
      +      "date"=>"2011-11-05T20:03:54+07:00",
      ?                           ^        ^
             "finished"=>1,
             "position"=>"",
             "timestamp"=>"2014-03-21T09:43:05+07:00",
             "type"=>"new type"},
           "content_id2"=>
            {"bookmark_suffix_max"=>3,
             "bookmarks"=>
              [{"date"=>"", "label"=>"", "name"=>"", "position"=>""},
               {"date"=>"", "label"=>"", "name"=>"", "position"=>""}],
      -      "date"=>"2011-11-04T22:03:54+09:00",
      ?                           ^        ^
      +      "date"=>"2011-11-04T20:03:54+07:00",
      ?                           ^        ^
             "finished"=>1,
             "position"=>"",
      -      "timestamp"=>"2011-11-04T22:03:54+09:00",
      ?                                ^        ^
      +      "timestamp"=>"2011-11-04T20:03:54+07:00",
      ?                                ^        ^
             "type"=>""}},
         "timestamp"=>"2014-03-21T09:43:05+07:00"}
    test_merge1_with_conflict_1:_should_update_bookmark_info_with_client's_'date'_field(AccountBookmarkInfoTest)
    

    是因为time_zone吗?或者是其他东西。我已经使用-修复了+,但我仍然有同样的错误。

    ============ 2 ===============

    Error: test_ContentsJsonCache.key_for_params_should_depend_all_query_parameters(ContentsJsonCacheTest)
      NameError: undefined local variable or method `current_protocol_version' for #<App:0x007fcc0a3f8800>
    app/models/app.rb:166:in `implements_purchase_bonus_feature?'
    app/models/app.rb:174:in `include_purchase_bonuses_in_contents_json?'
    app/models/contents_json_cache.rb:21:in `key_for_params'
    test/unit/contents_json_cache_test.rb:22:in `block in <class:ContentsJsonCacheTest>'
    

    current_local_version位于:

    **Controller. define : app.current_protocol_version
    
    **Models. define :
    
        attr_accessible :current_protocol_version,
                        :name,
                        ....
    **test->functional->app.controller_test.rb
    
        app = apps :one
        app.current_protocol_version = '1.1.9'
        assert_false app.implements_account_feature?
    

1 个答案:

答案 0 :(得分:0)

要修复时间戳错误,请在代码中执行此操作。

如果你有以下代码:

之前。

time.parse var

time.zone.parse var