Generate only tests from existing model / controllers

前端 未结 3 629
借酒劲吻你
借酒劲吻你 2020-12-31 02:26

I have a Rails3 app that is based on someone else\'s work. For some reason they decided not to supply the tests with the app, which I am finding frustrating.

What I

3条回答
  •  Happy的楠姐
    2020-12-31 03:22

    To only generate the associated test files for an existing Rails 3 app, I use "generate resource" but skip everything that I don't want:

    rails g resource Post --skip --no-resource-route --no-migration --no-helper --no-assets
    

    Other options can be found using rails generate resource --help

    -s, [--skip]     # Skip files that already exist
    --resource-route            # Indicates when to generate resource route
    [--helper]                # Indicates when to generate helper
    [--assets]                # Indicates when to generate assets
    [--migration]            # Indicates when to generate migration
    

    Why not use generate scaffold? Because it might generate views that I'm not using.

提交回复
热议问题