Skip to content

Commit

Permalink
use #quietly in a few places, and s/silence/capture/ where intention …
Browse files Browse the repository at this point in the history
…is capture
  • Loading branch information
fxn committed May 13, 2011
1 parent ceeab61 commit 2e5d312
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
8 changes: 4 additions & 4 deletions railties/test/generators/app_generator_test.rb
Expand Up @@ -96,7 +96,7 @@ def test_application_name_is_detected_if_it_exists_and_app_folder_renamed
generator = Rails::Generators::AppGenerator.new ["rails"], { :with_dispatchers => true }, generator = Rails::Generators::AppGenerator.new ["rails"], { :with_dispatchers => true },
:destination_root => app_moved_root, :shell => @shell :destination_root => app_moved_root, :shell => @shell
generator.send(:app_const) generator.send(:app_const)
silence(:stdout){ generator.send(:create_config_files) } quietly { generator.send(:create_config_files) }
assert_file "myapp_moved/config/environment.rb", /Myapp::Application\.initialize!/ assert_file "myapp_moved/config/environment.rb", /Myapp::Application\.initialize!/
assert_file "myapp_moved/config/initializers/session_store.rb", /_myapp_session/ assert_file "myapp_moved/config/initializers/session_store.rb", /_myapp_session/
end end
Expand All @@ -111,7 +111,7 @@ def test_rails_update_generates_correct_session_key


generator = Rails::Generators::AppGenerator.new ["rails"], { :with_dispatchers => true }, :destination_root => app_root, :shell => @shell generator = Rails::Generators::AppGenerator.new ["rails"], { :with_dispatchers => true }, :destination_root => app_root, :shell => @shell
generator.send(:app_const) generator.send(:app_const)
silence(:stdout){ generator.send(:create_config_files) } quietly { generator.send(:create_config_files) }
assert_file "myapp/config/initializers/session_store.rb", /_myapp_session/ assert_file "myapp/config/initializers/session_store.rb", /_myapp_session/
end end


Expand Down Expand Up @@ -258,7 +258,7 @@ def test_force_old_style_hash
protected protected


def action(*args, &block) def action(*args, &block)
silence(:stdout){ generator.send(*args, &block) } silence(:stdout) { generator.send(*args, &block) }
end end


end end
Expand All @@ -284,6 +284,6 @@ def builder_class
end end


def action(*args, &block) def action(*args, &block)
silence(:stdout){ generator.send(*args, &block) } silence(:stdout) { generator.send(*args, &block) }
end end
end end
16 changes: 8 additions & 8 deletions railties/test/generators/shared_generator_tests.rb
Expand Up @@ -28,7 +28,7 @@ def test_skeleton_is_created


def test_generation_runs_bundle_check def test_generation_runs_bundle_check
generator([destination_root]).expects(:bundle_command).with('check').once generator([destination_root]).expects(:bundle_command).with('check').once
silence(:stdout) { generator.invoke_all } quietly { generator.invoke_all }
end end


def test_plugin_new_generate_pretend def test_plugin_new_generate_pretend
Expand Down Expand Up @@ -88,7 +88,7 @@ def test_template_is_executed_when_supplied
template.instance_eval "def read; self; end" # Make the string respond to read template.instance_eval "def read; self; end" # Make the string respond to read


generator([destination_root], :template => path).expects(:open).with(path, 'Accept' => 'application/x-thor-template').returns(template) generator([destination_root], :template => path).expects(:open).with(path, 'Accept' => 'application/x-thor-template').returns(template)
assert_match(/It works!/, silence(:stdout){ generator.invoke_all }) assert_match(/It works!/, capture(:stdout) { generator.invoke_all })
end end


def test_template_raises_an_error_with_invalid_path def test_template_raises_an_error_with_invalid_path
Expand All @@ -103,7 +103,7 @@ def test_template_is_executed_when_supplied
template.instance_eval "def read; self; end" # Make the string respond to read template.instance_eval "def read; self; end" # Make the string respond to read


generator([destination_root], :template => path).expects(:open).with(path, 'Accept' => 'application/x-thor-template').returns(template) generator([destination_root], :template => path).expects(:open).with(path, 'Accept' => 'application/x-thor-template').returns(template)
assert_match(/It works!/, silence(:stdout){ generator.invoke_all }) assert_match(/It works!/, capture(:stdout) { generator.invoke_all })
end end


def test_template_is_executed_when_supplied_an_https_path def test_template_is_executed_when_supplied_an_https_path
Expand All @@ -112,25 +112,25 @@ def test_template_is_executed_when_supplied_an_https_path
template.instance_eval "def read; self; end" # Make the string respond to read template.instance_eval "def read; self; end" # Make the string respond to read


generator([destination_root], :template => path).expects(:open).with(path, 'Accept' => 'application/x-thor-template').returns(template) generator([destination_root], :template => path).expects(:open).with(path, 'Accept' => 'application/x-thor-template').returns(template)
assert_match(/It works!/, silence(:stdout){ generator.invoke_all }) assert_match(/It works!/, capture(:stdout) { generator.invoke_all })
end end


def test_dev_option def test_dev_option
generator([destination_root], :dev => true).expects(:bundle_command).with('install').once generator([destination_root], :dev => true).expects(:bundle_command).with('install').once
silence(:stdout) { generator.invoke_all } quietly { generator.invoke_all }
rails_path = File.expand_path('../../..', Rails.root) rails_path = File.expand_path('../../..', Rails.root)
assert_file 'Gemfile', /^gem\s+["']rails["'],\s+:path\s+=>\s+["']#{Regexp.escape(rails_path)}["']$/ assert_file 'Gemfile', /^gem\s+["']rails["'],\s+:path\s+=>\s+["']#{Regexp.escape(rails_path)}["']$/
end end


def test_edge_option def test_edge_option
generator([destination_root], :edge => true).expects(:bundle_command).with('install').once generator([destination_root], :edge => true).expects(:bundle_command).with('install').once
silence(:stdout) { generator.invoke_all } quietly { generator.invoke_all }
assert_file 'Gemfile', %r{^gem\s+["']rails["'],\s+:git\s+=>\s+["']#{Regexp.escape("git://github.com/rails/rails.git")}["']$} assert_file 'Gemfile', %r{^gem\s+["']rails["'],\s+:git\s+=>\s+["']#{Regexp.escape("git://github.com/rails/rails.git")}["']$}
end end


def test_skip_gemfile def test_skip_gemfile
generator([destination_root], :skip_gemfile => true).expects(:bundle_command).never generator([destination_root], :skip_gemfile => true).expects(:bundle_command).never
silence(:stdout) { generator.invoke_all } quietly { generator.invoke_all }
assert_no_file 'Gemfile' assert_no_file 'Gemfile'
end end
end end
Expand Down Expand Up @@ -187,7 +187,7 @@ def test_builder_option_with_http
template.instance_eval "def read; self; end" # Make the string respond to read template.instance_eval "def read; self; end" # Make the string respond to read


generator([destination_root], :builder => path).expects(:open).with(path, 'Accept' => 'application/x-thor-template').returns(template) generator([destination_root], :builder => path).expects(:open).with(path, 'Accept' => 'application/x-thor-template').returns(template)
silence(:stdout) { generator.invoke_all } quietly { generator.invoke_all }


default_files.each{ |path| assert_no_file(path) } default_files.each{ |path| assert_no_file(path) }
end end
Expand Down

0 comments on commit 2e5d312

Please sign in to comment.