diff options
Diffstat (limited to 'railties')
-rw-r--r-- | railties/CHANGELOG.md | 4 | ||||
-rw-r--r-- | railties/lib/rails/generators/actions.rb | 18 | ||||
-rw-r--r-- | railties/lib/rails/test_unit/reporter.rb | 12 | ||||
-rw-r--r-- | railties/test/generators/actions_test.rb | 8 | ||||
-rw-r--r-- | railties/test/test_unit/reporter_test.rb | 1 |
5 files changed, 38 insertions, 5 deletions
diff --git a/railties/CHANGELOG.md b/railties/CHANGELOG.md index 7367f0a813..7c0d4e3b31 100644 --- a/railties/CHANGELOG.md +++ b/railties/CHANGELOG.md @@ -1,3 +1,7 @@ +* Adding support for passing a block to the `add_source` action of a custom generator + + *Mike Dalton*, *Hirofumi Wakasugi* + * `assert_file` understands paths with special characters (eg. `v0.1.4~alpha+nightly`). diff --git a/railties/lib/rails/generators/actions.rb b/railties/lib/rails/generators/actions.rb index 70a20801a0..560a553789 100644 --- a/railties/lib/rails/generators/actions.rb +++ b/railties/lib/rails/generators/actions.rb @@ -63,12 +63,26 @@ module Rails # Add the given source to +Gemfile+ # + # If block is given, gem entries in block are wrapped into the source group. + # # add_source "http://gems.github.com/" - def add_source(source, options={}) + # + # add_source "http://gems.github.com/" do + # gem "rspec-rails" + # end + def add_source(source, options={}, &block) log :source, source in_root do - prepend_file "Gemfile", "source #{quote(source)}\n", verbose: false + if block + append_file "Gemfile", "source #{quote(source)} do", force: true + @in_group = true + instance_eval(&block) + @in_group = false + append_file "Gemfile", "\nend\n", force: true + else + prepend_file "Gemfile", "source #{quote(source)}\n", verbose: false + end end end diff --git a/railties/lib/rails/test_unit/reporter.rb b/railties/lib/rails/test_unit/reporter.rb index faf551f381..09b8675cf8 100644 --- a/railties/lib/rails/test_unit/reporter.rb +++ b/railties/lib/rails/test_unit/reporter.rb @@ -7,7 +7,7 @@ module Rails self.executable = "bin/rails test" def report - return if results.empty? + return if filtered_results.empty? io.puts io.puts "Failed tests:" io.puts @@ -15,14 +15,20 @@ module Rails end def aggregated_results # :nodoc: - filtered_results = results.dup - filtered_results.reject!(&:skipped?) unless options[:verbose] filtered_results.map do |result| location, line = result.method(result.name).source_location "#{self.executable} #{relative_path_for(location)}:#{line}" end.join "\n" end + def filtered_results + if options[:verbose] + results + else + results.reject(&:skipped?) + end + end + def relative_path_for(file) file.sub(/^#{Rails.root}\/?/, '') end diff --git a/railties/test/generators/actions_test.rb b/railties/test/generators/actions_test.rb index 4a4317c4f4..2857dae07e 100644 --- a/railties/test/generators/actions_test.rb +++ b/railties/test/generators/actions_test.rb @@ -47,6 +47,14 @@ class ActionsTest < Rails::Generators::TestCase assert_file 'Gemfile', /source 'http:\/\/gems\.github\.com'/ end + def test_add_source_with_block_adds_source_to_gemfile_with_gem + run_generator + action :add_source, 'http://gems.github.com' do + gem 'rspec-rails' + end + assert_file 'Gemfile', /source 'http:\/\/gems\.github\.com' do\n gem 'rspec-rails'\nend/ + end + def test_gem_should_put_gem_dependency_in_gemfile run_generator action :gem, 'will-paginate' diff --git a/railties/test/test_unit/reporter_test.rb b/railties/test/test_unit/reporter_test.rb index f9c7888bc6..3066ba82d6 100644 --- a/railties/test/test_unit/reporter_test.rb +++ b/railties/test/test_unit/reporter_test.rb @@ -32,6 +32,7 @@ class TestUnitReporterTest < ActiveSupport::TestCase @reporter.record(passing_test) @reporter.record(skipped_test) @reporter.report + assert_no_match 'Failed tests:', @output.string assert_rerun_snippet_count 0 end |