V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
Caojx
V2EX  ›  Ruby on Rails

正在看 restful rail development 这本书,按照书上写的测试报错了,大佬帮我看看

  •  
  •   Caojx · 2018-12-16 20:43:49 +08:00 · 17286 次点击
    这是一个创建于 2166 天前的主题,其中的信息可能已经有所发展或是发生改变。
    rails 版本 5.2.2
    require 'test_helper'

    class SayControllerTest < ActionDispatch::IntegrationTest
    test "should get hello" do
    get say_hello_url
    assert_response :success
    end
    test "should say hello in json" do
    get say_hello_url
    assert_equal "{\"hello\":\"Rails!\"}", @response.body
    end
    test "should say hello in json" do
    get say_hello_url,{'user'=>"Join"}
    assert_equal "{\"hello\":\"Join!\"}", @response.body
    end
    end
    3 条回复    2018-12-16 21:09:25 +08:00
    Caojx
        1
    Caojx  
    OP
       2018-12-16 20:45:34 +08:00
    第三条测试,我传参不对
    Caojx
        2
    Caojx  
    OP
       2018-12-16 20:58:16 +08:00
    这是报错
    ✘ caojianxiong@MacBook-Air  ~/Ruby/hello_rails   master  rake test
    /Users/caojianxiong/Ruby/hello_rails/db/schema.rb doesn't exist yet. Run `rails db:migrate` to create it, then try again. If you do not intend to use a database, you should instead alter /Users/caojianxiong/Ruby/hello_rails/config/application.rb to limit the frameworks that will be loaded.
    rake aborted!
    test_should_say_hello_in_json is already defined in SayControllerTest
    /Users/caojianxiong/Ruby/hello_rails/test/controllers/say_controller_test.rb:12:in `<class:SayControllerTest>'
    /Users/caojianxiong/Ruby/hello_rails/test/controllers/say_controller_test.rb:3:in `<top (required)>'
    Tasks: TOP => test
    (See full trace by running task with --trace)
    zhaolion
        3
    zhaolion  
       2018-12-16 21:09:25 +08:00   ❤️ 1
    先配置一下 config/database.yaml,然后执行 `rails db:migrate`
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   3387 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 23ms · UTC 10:56 · PVG 18:56 · LAX 02:56 · JFK 05:56
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.