Don't indent blank lines in named base generators #5902

merged 1 commit into from Apr 25, 2012


None yet

4 participants


This method is not documented, but I use it in my generators.

code = <<-ROUTES.strip_heredoc
  get "admin/login"

  get "admin/logout"

route indent(code).strip

And this code also used for example here:

Ruby on Rails member

Do you mind adding a test for this?


I added test which check indented blank lines (It fails on master and passes this PR)

@josevalim josevalim merged commit 33d8091 into rails:master Apr 25, 2012
@carlosantoniodasilva carlosantoniodasilva commented on the diff Apr 25, 2012
@@ -61,6 +61,14 @@ def test_invokes_default_template_engine_even_with_no_action
run_generator ["account"]
assert_file "app/views/test_app/account"
+ def test_namespaced_controller_dont_indent_blank_lines
+ run_generator
+ assert_file "app/controllers/test_app/account_controller.rb"
+ File.readlines(File.expand_path("app/controllers/test_app/account_controller.rb", destination_root)).each do |line|
+ assert_no_match line.chomp, /^\s+$/, "Don't indent blank lines"
+ end
carlosantoniodasilva Apr 25, 2012 Ruby on Rails member

I think you can give a block to assert_file, to receive it's content as argument, and assert against it (more). Something like:

    assert_file "app/controllers/test_app/account_controller.rb" do |content|
      assert_no_match /^\s+$/, content, "Don't indent blank lines"  

Could you give it a try? Thanks.


@carlosantoniodasilva good point! I didn't think about that. #5997 - Did you mean this?

Ruby on Rails member

@avakhov yeah exactly, perfect! Thanks :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment