• 卸载 rvm 后重装,搞定,试用了一下 rbenv,太差劲,比 rvm 差远了。

  • 已经解决了,是版本混乱造成的

  • 我安装的 rails 版本是 5.0.2,可是执行 bundle install 以后 gem 多了一个 5.0.7.2,是不是这个原因造成错误的?有高手能说一下吗?

    depot gem list --local rails
    
    *** LOCAL GEMS ***
    
    coffee-rails (4.2.2)
    jquery-rails (4.5.0)
    rails (5.0.7.2, 5.0.2)
    rails-dom-testing (2.0.3)
    rails-html-sanitizer (1.4.3)
    sass-rails (5.0.7)
    sprockets-rails (3.2.2)
    
  • 运行 3 次 rails test ,报的错误是不一样的,头大啊。

      depot rails test
    Running via Spring preloader in process 21252
    Run options: --seed 5941
    
    # Running:
    
    F
    
    Failure:
    ProductsControllerTest#test_should_update_product [/Users/sun/Desktop/rubywork/depot/test/controllers/products_controller_test.rb:44]:
    Expected response to be a <3XX: redirect>, but was a <422: Unprocessable Entity>
    
    
    Traceback (most recent call last):
        27: from -e:1:in `<main>'
        26: from /Users/sun/.rvm/rubies/ruby-2.6.0/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
        25: from /Users/sun/.rvm/rubies/ruby-2.6.0/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
        24: from /Users/sun/.rvm/gems/ruby-2.6.0@rails5.0.2/gems/spring-2.1.1/lib/spring/application/boot.rb:19:in `<top (required)>'
        23: from /Users/sun/.rvm/gems/[email protected]/gems/spring-2.1.1/lib/spring/application.rb:139:in `run'
        22: from /Users/sun/.rvm/gems/[email protected]/gems/spring-2.1.1/lib/spring/application.rb:139:in `loop'
        21: from /Users/sun/.rvm/gems/ruby-2.6.0@rails5.0.2/gems/spring-2.1.1/lib/spring/application.rb:145:in `block in run'
        20: from /Users/sun/.rvm/gems/[email protected]/gems/spring-2.1.1/lib/spring/application.rb:180:in `serve'
        19: from /Users/sun/.rvm/gems/[email protected]/gems/spring-2.1.1/lib/spring/application.rb:180:in `fork'
        18: from /Users/sun/.rvm/gems/ruby-2.6.0@rails5.0.2/gems/minitest-5.16.3/lib/minitest.rb:83:in `block in autorun'
        17: from /Users/sun/.rvm/gems/[email protected]/gems/minitest-5.16.3/lib/minitest.rb:159:in `run'
        16: from /Users/sun/.rvm/gems/[email protected]/gems/minitest-5.16.3/lib/minitest.rb:182:in `__run'
        15: from /Users/sun/.rvm/gems/ruby-2.6.0@rails5.0.2/gems/minitest-5.16.3/lib/minitest.rb:182:in `map'
        14: from /Users/sun/.rvm/gems/[email protected]/gems/minitest-5.16.3/lib/minitest.rb:182:in `block in __run'
        13: from /Users/sun/.rvm/gems/[email protected]/gems/railties-5.0.7.2/lib/rails/test_unit/line_filtering.rb:9:in `run'
        12: from /Users/sun/.rvm/gems/ruby-2.6.0@rails5.0.2/gems/minitest-5.16.3/lib/minitest.rb:350:in `run'
        11: from /Users/sun/.rvm/gems/[email protected]/gems/minitest-5.16.3/lib/minitest.rb:378:in `with_info_handler'
        10: from /Users/sun/.rvm/gems/[email protected]/gems/minitest-5.16.3/lib/minitest.rb:391:in `on_signal'
         9: from /Users/sun/.rvm/gems/ruby-2.6.0@rails5.0.2/gems/minitest-5.16.3/lib/minitest.rb:351:in `block in run'
         8: from /Users/sun/.rvm/gems/[email protected]/gems/minitest-5.16.3/lib/minitest.rb:351:in `each'
         7: from /Users/sun/.rvm/gems/[email protected]/gems/minitest-5.16.3/lib/minitest.rb:352:in `block (2 levels) in run'
         6: from /Users/sun/.rvm/gems/ruby-2.6.0@rails5.0.2/gems/minitest-5.16.3/lib/minitest.rb:365:in `run_one_method'
         5: from /Users/sun/.rvm/gems/[email protected]/gems/minitest-5.16.3/lib/minitest.rb:890:in `record'
         4: from /Users/sun/.rvm/gems/[email protected]/gems/minitest-5.16.3/lib/minitest.rb:890:in `each'
         3: from /Users/sun/.rvm/gems/ruby-2.6.0@rails5.0.2/gems/minitest-5.16.3/lib/minitest.rb:891:in `block in record'
         2: from /Users/sun/.rvm/gems/[email protected]/gems/railties-5.0.7.2/lib/rails/test_unit/reporter.rb:23:in `record'
         1: from /Users/sun/.rvm/gems/[email protected]/gems/railties-5.0.7.2/lib/rails/test_unit/reporter.rb:70:in `format_rerun_snippet'
    /Users/sun/.rvm/gems/ruby-2.6.0@rails5.0.2/gems/railties-5.0.7.2/lib/rails/test_unit/reporter.rb:70:in `method': undefined method `test_should_update_product' for class `Minitest::Result' (NameError)
      depot rails test
    Running via Spring preloader in process 21268
    Run options: --seed 59470
    
    # Running:
    
    F
    
    Failure:
    ProductTest#test_product_price_must_be_positive [/Users/sun/Desktop/rubywork/depot/test/models/product_test.rb:29]:
    Expected false to be truthy.
    
    
    Traceback (most recent call last):
        27: from -e:1:in `<main>'
        26: from /Users/sun/.rvm/rubies/ruby-2.6.0/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
        25: from /Users/sun/.rvm/rubies/ruby-2.6.0/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
        24: from /Users/sun/.rvm/gems/ruby-2.6.0@rails5.0.2/gems/spring-2.1.1/lib/spring/application/boot.rb:19:in `<top (required)>'
        23: from /Users/sun/.rvm/gems/[email protected]/gems/spring-2.1.1/lib/spring/application.rb:139:in `run'
        22: from /Users/sun/.rvm/gems/[email protected]/gems/spring-2.1.1/lib/spring/application.rb:139:in `loop'
        21: from /Users/sun/.rvm/gems/ruby-2.6.0@rails5.0.2/gems/spring-2.1.1/lib/spring/application.rb:145:in `block in run'
        20: from /Users/sun/.rvm/gems/[email protected]/gems/spring-2.1.1/lib/spring/application.rb:180:in `serve'
        19: from /Users/sun/.rvm/gems/[email protected]/gems/spring-2.1.1/lib/spring/application.rb:180:in `fork'
        18: from /Users/sun/.rvm/gems/ruby-2.6.0@rails5.0.2/gems/minitest-5.16.3/lib/minitest.rb:83:in `block in autorun'
        17: from /Users/sun/.rvm/gems/[email protected]/gems/minitest-5.16.3/lib/minitest.rb:159:in `run'
        16: from /Users/sun/.rvm/gems/[email protected]/gems/minitest-5.16.3/lib/minitest.rb:182:in `__run'
        15: from /Users/sun/.rvm/gems/ruby-2.6.0@rails5.0.2/gems/minitest-5.16.3/lib/minitest.rb:182:in `map'
        14: from /Users/sun/.rvm/gems/[email protected]/gems/minitest-5.16.3/lib/minitest.rb:182:in `block in __run'
        13: from /Users/sun/.rvm/gems/[email protected]/gems/railties-5.0.7.2/lib/rails/test_unit/line_filtering.rb:9:in `run'
        12: from /Users/sun/.rvm/gems/ruby-2.6.0@rails5.0.2/gems/minitest-5.16.3/lib/minitest.rb:350:in `run'
        11: from /Users/sun/.rvm/gems/[email protected]/gems/minitest-5.16.3/lib/minitest.rb:378:in `with_info_handler'
        10: from /Users/sun/.rvm/gems/[email protected]/gems/minitest-5.16.3/lib/minitest.rb:391:in `on_signal'
         9: from /Users/sun/.rvm/gems/ruby-2.6.0@rails5.0.2/gems/minitest-5.16.3/lib/minitest.rb:351:in `block in run'
         8: from /Users/sun/.rvm/gems/[email protected]/gems/minitest-5.16.3/lib/minitest.rb:351:in `each'
         7: from /Users/sun/.rvm/gems/[email protected]/gems/minitest-5.16.3/lib/minitest.rb:352:in `block (2 levels) in run'
         6: from /Users/sun/.rvm/gems/ruby-2.6.0@rails5.0.2/gems/minitest-5.16.3/lib/minitest.rb:365:in `run_one_method'
         5: from /Users/sun/.rvm/gems/[email protected]/gems/minitest-5.16.3/lib/minitest.rb:890:in `record'
         4: from /Users/sun/.rvm/gems/[email protected]/gems/minitest-5.16.3/lib/minitest.rb:890:in `each'
         3: from /Users/sun/.rvm/gems/ruby-2.6.0@rails5.0.2/gems/minitest-5.16.3/lib/minitest.rb:891:in `block in record'
         2: from /Users/sun/.rvm/gems/[email protected]/gems/railties-5.0.7.2/lib/rails/test_unit/reporter.rb:23:in `record'
         1: from /Users/sun/.rvm/gems/[email protected]/gems/railties-5.0.7.2/lib/rails/test_unit/reporter.rb:70:in `format_rerun_snippet'
    /Users/sun/.rvm/gems/ruby-2.6.0@rails5.0.2/gems/railties-5.0.7.2/lib/rails/test_unit/reporter.rb:70:in `method': undefined method `test_product_price_must_be_positive' for class `Minitest::Result' (NameError)
      depot rails test
    Running via Spring preloader in process 21274
    Run options: --seed 10657
    
    # Running:
    
    ....F
    
    Failure:
    ProductsControllerTest#test_should_create_product [/Users/sun/Desktop/rubywork/depot/test/controllers/products_controller_test.rb:25]:
    "Product.count" didn't change by 1.
    Expected: 3
      Actual: 2
    
    
    Traceback (most recent call last):
        27: from -e:1:in `<main>'
        26: from /Users/sun/.rvm/rubies/ruby-2.6.0/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
        25: from /Users/sun/.rvm/rubies/ruby-2.6.0/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
        24: from /Users/sun/.rvm/gems/[email protected]/gems/spring-2.1.1/lib/spring/application/boot.rb:19:in `<top (required)>'
        23: from /Users/sun/.rvm/gems/ruby-2.6.0@rails5.0.2/gems/spring-2.1.1/lib/spring/application.rb:139:in `run'
        22: from /Users/sun/.rvm/gems/[email protected]/gems/spring-2.1.1/lib/spring/application.rb:139:in `loop'
        21: from /Users/sun/.rvm/gems/[email protected]/gems/spring-2.1.1/lib/spring/application.rb:145:in `block in run'
        20: from /Users/sun/.rvm/gems/ruby-2.6.0@rails5.0.2/gems/spring-2.1.1/lib/spring/application.rb:180:in `serve'
        19: from /Users/sun/.rvm/gems/[email protected]/gems/spring-2.1.1/lib/spring/application.rb:180:in `fork'
        18: from /Users/sun/.rvm/gems/[email protected]/gems/minitest-5.16.3/lib/minitest.rb:83:in `block in autorun'
        17: from /Users/sun/.rvm/gems/ruby-2.6.0@rails5.0.2/gems/minitest-5.16.3/lib/minitest.rb:159:in `run'
        16: from /Users/sun/.rvm/gems/[email protected]/gems/minitest-5.16.3/lib/minitest.rb:182:in `__run'
        15: from /Users/sun/.rvm/gems/[email protected]/gems/minitest-5.16.3/lib/minitest.rb:182:in `map'
        14: from /Users/sun/.rvm/gems/ruby-2.6.0@rails5.0.2/gems/minitest-5.16.3/lib/minitest.rb:182:in `block in __run'
        13: from /Users/sun/.rvm/gems/[email protected]/gems/railties-5.0.7.2/lib/rails/test_unit/line_filtering.rb:9:in `run'
        12: from /Users/sun/.rvm/gems/[email protected]/gems/minitest-5.16.3/lib/minitest.rb:350:in `run'
        11: from /Users/sun/.rvm/gems/ruby-2.6.0@rails5.0.2/gems/minitest-5.16.3/lib/minitest.rb:378:in `with_info_handler'
        10: from /Users/sun/.rvm/gems/[email protected]/gems/minitest-5.16.3/lib/minitest.rb:391:in `on_signal'
         9: from /Users/sun/.rvm/gems/[email protected]/gems/minitest-5.16.3/lib/minitest.rb:351:in `block in run'
         8: from /Users/sun/.rvm/gems/ruby-2.6.0@rails5.0.2/gems/minitest-5.16.3/lib/minitest.rb:351:in `each'
         7: from /Users/sun/.rvm/gems/[email protected]/gems/minitest-5.16.3/lib/minitest.rb:352:in `block (2 levels) in run'
         6: from /Users/sun/.rvm/gems/[email protected]/gems/minitest-5.16.3/lib/minitest.rb:365:in `run_one_method'
         5: from /Users/sun/.rvm/gems/ruby-2.6.0@rails5.0.2/gems/minitest-5.16.3/lib/minitest.rb:890:in `record'
         4: from /Users/sun/.rvm/gems/[email protected]/gems/minitest-5.16.3/lib/minitest.rb:890:in `each'
         3: from /Users/sun/.rvm/gems/[email protected]/gems/minitest-5.16.3/lib/minitest.rb:891:in `block in record'
         2: from /Users/sun/.rvm/gems/ruby-2.6.0@rails5.0.2/gems/railties-5.0.7.2/lib/rails/test_unit/reporter.rb:23:in `record'
         1: from /Users/sun/.rvm/gems/[email protected]/gems/railties-5.0.7.2/lib/rails/test_unit/reporter.rb:70:in `format_rerun_snippet'
    /Users/sun/.rvm/gems/[email protected]/gems/railties-5.0.7.2/lib/rails/test_unit/reporter.rb:70:in `method': undefined method `test_should_create_product' for class `Minitest::Result' (NameError)
    
  • 为什么我的代码都是按书上来的,也仔细检查了,可是 rails test 的时候一会儿报这个错误,一会儿报那个错误

  • 中扣号也可以表达正则表达式的

  • 谢谢