Skip to content
Browse files

refactor generator tests to use block form of Tempfile

  • Loading branch information...
1 parent 8bbd21c commit 65251820ef0ab7f3cffb38130de3dd41af8d72be @tenderlove tenderlove committed Jan 8, 2014
Showing with 30 additions and 36 deletions.
  1. +30 −36 railties/test/generators/app_generator_test.rb
View
66 railties/test/generators/app_generator_test.rb
@@ -164,55 +164,49 @@ def test_config_database_is_added_by_default
end
def test_add_gemfile_entry
- template = Tempfile.open 'my_template'
- template.puts 'gemfile_entry "tenderlove"'
- template.flush
-
- run_generator([destination_root, "-m", template.path])
- assert_file "Gemfile", /tenderlove/
- ensure
- template.close
- template.unlink
+ Tempfile.open('my_template') do |template|
+ template.puts 'gemfile_entry "tenderlove"'
+ template.flush
+ template.close
+ run_generator([destination_root, "-m", template.path])
+ assert_file "Gemfile", /tenderlove/
+ end
end
def test_add_skip_entry
- template = Tempfile.open 'my_template'
- template.puts 'add_gem_entry_filter { |gem| gem.name != "jbuilder" }'
- template.flush
+ Tempfile.open 'my_template' do |template|
+ template.puts 'add_gem_entry_filter { |gem| gem.name != "jbuilder" }'
+ template.flush
- run_generator([destination_root, "-m", template.path])
- assert_file "Gemfile" do |contents|
- assert_no_match 'jbuilder', contents
+ run_generator([destination_root, "-m", template.path])
+ assert_file "Gemfile" do |contents|
+ assert_no_match 'jbuilder', contents
+ end
end
- ensure
- template.close
- template.unlink
end
def test_skip_turbolinks_when_it_is_not_on_gemfile
- template = Tempfile.open 'my_template'
- template.puts 'add_gem_entry_filter { |gem| gem.name != "turbolinks" }'
- template.flush
+ Tempfile.open 'my_template' do |template|
+ template.puts 'add_gem_entry_filter { |gem| gem.name != "turbolinks" }'
+ template.flush
- run_generator([destination_root, "-m", template.path])
- assert_file "Gemfile" do |contents|
- assert_no_match 'turbolinks', contents
- end
+ run_generator([destination_root, "-m", template.path])
+ assert_file "Gemfile" do |contents|
+ assert_no_match 'turbolinks', contents
+ end
- assert_file "app/views/layouts/application.html.erb" do |contents|
- assert_no_match 'turbolinks', contents
- end
+ assert_file "app/views/layouts/application.html.erb" do |contents|
+ assert_no_match 'turbolinks', contents
+ end
- assert_file "app/views/layouts/application.html.erb" do |contents|
- assert_no_match('data-turbolinks-track', contents)
- end
+ assert_file "app/views/layouts/application.html.erb" do |contents|
+ assert_no_match('data-turbolinks-track', contents)
+ end
- assert_file "app/assets/javascripts/application.js" do |contents|
- assert_no_match 'turbolinks', contents
+ assert_file "app/assets/javascripts/application.js" do |contents|
+ assert_no_match 'turbolinks', contents
+ end
end
- ensure
- template.close
- template.unlink
end
def test_config_another_database

0 comments on commit 6525182

Please sign in to comment.
Something went wrong with that request. Please try again.