How do I generate specs for existing controllers?

后端 未结 3 1065
孤城傲影
孤城傲影 2020-12-08 14:11

I have several controllers already set up. Now I want to start writing spec tests for them. Is there a command that generates the spec files automatically? I know rails does

3条回答
  •  孤街浪徒
    2020-12-08 14:59

    If you've configured rspec in application.rb:

    config.generators do |g|
      g.test_framework      :rspec
    end
    

    then rails g controller things will work. Opt not to overwrite files as they're generated.

    All a spec looks like when it's generated is the following:

    require 'spec_helper'
    
    describe ThingsController do
    
      it "should be successful" do
        get :index
        response.should be_successful
      end
    
    end
    

    I often create the specs manually, as it's rather trivial.

提交回复
热议问题