diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2014-01-08 12:05:40 -0800 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2014-01-08 12:05:52 -0800 |
commit | 65251820ef0ab7f3cffb38130de3dd41af8d72be (patch) | |
tree | b2c6e73c81f8495ab868fd21caf2ff20d6d92275 | |
parent | 8bbd21cccfd0939915da327fe54228730a10dbb2 (diff) | |
download | rails-65251820ef0ab7f3cffb38130de3dd41af8d72be.tar.gz rails-65251820ef0ab7f3cffb38130de3dd41af8d72be.tar.bz2 rails-65251820ef0ab7f3cffb38130de3dd41af8d72be.zip |
refactor generator tests to use block form of Tempfile
-rw-r--r-- | railties/test/generators/app_generator_test.rb | 66 |
1 files changed, 30 insertions, 36 deletions
diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index e584c01da9..195f13bdc3 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -164,55 +164,49 @@ class AppGeneratorTest < Rails::Generators::TestCase 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 |