Permalink
Browse files

Remove warning configuration from spec_helper.rb

Resolve #1162

In RSpec 3.0, `rspec --init` added `--warnings` to `.rspec`. This wasn't
a good decision and many users asked how to get rid of the metric ton of
warnings they were getting from rails, gems, etc, so we've changed it so
that it'll be in the generated `spec_helper.rb` instead, in the
commented out section, so that users have to op-in to it.

However, many gems used by Rails apps are not warning free. Leaving this
config option turned on by default in the `spec_helper.rb` configuration
will continue to cause issues for many users.

This completely removes the setting from the generated `spec_helper.rb`,
along with the comment suggesting it is recommended to be enabled. We do
not suggest that it is enabled for Rails apps by default.
  • Loading branch information...
cupakromer committed Aug 29, 2014
1 parent 953750d commit b94729be43abc27054e7d73734b64ed8fe89567c
@@ -36,11 +36,28 @@ def generate_rspec_init(tmpdir)
:report_stream => StringIO.new
)
initializer.run
gsub_file File.join(tmpdir, 'spec', 'spec_helper.rb'),
spec_helper_path = File.join(tmpdir, 'spec', 'spec_helper.rb')
replace_generator_command(spec_helper_path)
remove_warnings_configuration(spec_helper_path)
end
def replace_generator_command(spec_helper_path)
gsub_file spec_helper_path,
'rspec --init',
'rails generate rspec:install',
:verbose => false
end
def remove_warnings_configuration(spec_helper_path)
empty_line = '^\n'
comment_line = '^\s*#.+\n'
gsub_file spec_helper_path,
/#{empty_line}(#{comment_line})+\s+config\.warnings = true\n/,
'',
:verbose => false
end
end
end
end
@@ -48,6 +48,11 @@ def use_transactional_fixtures
expect(spec_helper).to match(generator_command_notice)
end
it "does not configure warnings in the spec/spec_helper.rb" do
run_generator
expect(spec_helper).not_to match(/\bconfig.warnings\b/m)
end
context "generates spec/rails_helper.rb" do
specify "requiring respec/rails" do
run_generator

0 comments on commit b94729b

Please sign in to comment.