Repository: rails/rails
File: railties/test/generators/actions_test.rb (Ruby)

Code before:
      end
    end
  end

  test "rails_command with inline option" do
    run_generator
    assert_not_called(generator, :run) do
      action :rails_command, "generate model MyModel", inline: true
    end
    assert_file "app/models/my_model.rb", /MyModel/
  end

  test "rails_command with inline option should raise on failure" do
    run_generator
    error = assert_raises do
      action :rails_command, "generate model 1234567890", inline: true
    end
    assert_match(/1234567890/, error.message)
  end

  test "route should add route" do
    run_generator
    route_commands = ['get "foo"', 'get "bar"', 'get "baz"']
    route_commands.each do |route_command|
      action :route, route_command
    end
    assert_routes route_commands
  end

  test "route should indent routing code" do
    run_generator
    route_commands = ['get "foo"', 'get "bar"', 'get "baz"']
    action :route, route_commands.join("\n")
    assert_routes route_commands
  end

  test "route should be idempotent" do
    run_generator
    route_command = 'root "welcome#index"'

    # runs first time
    action :route, route_command
    assert_routes route_command

    content = File.read(File.expand_path("config/routes.rb", destination_root))

    # runs second time
    action :route, route_command
    assert_file "config/routes.rb", content
  end


Review comment (suggestion):
Wow, thanks for remembering about this and finding a nicer and faster way to unit test this Zak! 🙇

I took the liberty to change your last commit from `"about"` to `"new myapp"`, which I think better reflects the use case I was trying to fix. Also removed the `run_generator` call, inspired by the terseness of the test on line 510, and it still worked. But I can roll back if you prefer the way it looked before.

Code after:
      end
    end
  end

  test "rails_command with inline option" do
    run_generator
    assert_not_called(generator, :run) do
      action :rails_command, "generate model MyModel", inline: true
    end
    assert_file "app/models/my_model.rb", /MyModel/
  end

  test "rails_command with inline option should raise on failure" do
    run_generator
    error = assert_raises do
      action :rails_command, "generate model 1234567890", inline: true
    end
    assert_match(/1234567890/, error.message)
  end

  test "rails_command with quiet option" do
    generator(default_arguments, quiet: true)
    assert_runs "rails new myapp", capture: true do
      action :rails_command, "new myapp"
    end
  end

  test "route should add route" do
    run_generator
    route_commands = ['get "foo"', 'get "bar"', 'get "baz"']
    route_commands.each do |route_command|
      action :route, route_command
    end
    assert_routes route_commands
  end

  test "route should indent routing code" do
    run_generator
    route_commands = ['get "foo"', 'get "bar"', 'get "baz"']
    action :route, route_commands.join("\n")
    assert_routes route_commands
  end

  test "route should be idempotent" do
    run_generator
    route_command = 'root "welcome#index"'

    # runs first time
    action :route, route_command
    assert_routes route_command