Skip to content
This repository was archived by the owner on Nov 30, 2024. It is now read-only.

Make specs and features global configuration proof #2602

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions features/command_line/init.feature
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Feature: `--init` option
Scenario: Accept and use the recommended settings in `spec_helper` (which are initially commented out)
Given I have a brand new project with no files
And I have run `rspec --init`
And I unset XDG_CONFIG_HOME environment var
When I accept the recommended settings by removing `=begin` and `=end` from `spec/spec_helper.rb`
And I create "spec/addition_spec.rb" with the following content:
"""ruby
Expand Down
1 change: 1 addition & 0 deletions features/command_line/warnings_option.feature
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@ Feature: `--warnings` option (run with warnings enabled)
end
end
"""
And I unset XDG_CONFIG_HOME environment var
When I run `rspec example_spec.rb`
Then the output should not contain "warning"
2 changes: 2 additions & 0 deletions features/configuration/profile.feature
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ Feature: Profile examples
"""

Scenario: By default does not show profile
Given I unset XDG_CONFIG_HOME environment var
When I run `rspec spec`
Then the examples should all pass
And the output should not contain "example 1"
Expand All @@ -92,6 +93,7 @@ Feature: Profile examples
"""ruby
RSpec.configure { |c| c.profile_examples = true }
"""
And I unset XDG_CONFIG_HOME environment var
When I run `rspec spec`
Then the examples should all pass
And the output should contain "Top 10 slowest examples"
Expand Down
5 changes: 3 additions & 2 deletions features/formatters/configurable_colors.feature
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@ Feature: Configurable colors
end
end
"""
When I run `rspec custom_failure_color_spec.rb --format progress`
Then the failing example is printed in magenta
And I unset XDG_CONFIG_HOME environment var
When I run `rspec custom_failure_color_spec.rb --format progress`
Then the failing example is printed in magenta
7 changes: 7 additions & 0 deletions features/step_definitions/additional_cli_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,13 @@
end
end

Given(/^I unset XDG_CONFIG_HOME environment var$/) do
step %q{I set the environment variables to:}, table(%{
| variable | value |
| XDG_CONFIG_HOME | |
})
end

module Normalization
def normalize_failure_output(text)
whitespace_normalized = text.lines.map { |line| line.sub(/\s+$/, '').sub(/:in .*$/, '') }.join
Expand Down
2 changes: 1 addition & 1 deletion spec/integration/spec_file_load_errors_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
EOS
end

it 'nicely handles load-time errors in user spec files' do
it 'nicely handles load-time errors in user spec files', :isolated_home => true do
write_file_formatted "1_spec.rb", "
boom

Expand Down
6 changes: 3 additions & 3 deletions spec/integration/suite_hooks_errors_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def run_spec_expecting_non_zero(before_or_after)
normalize_durations(last_cmd_stdout)
end

it 'nicely formats errors in `before(:suite)` hooks and exits with non-zero' do
it 'nicely formats errors in `before(:suite)` hooks and exits with non-zero', :isolated_home => true do
output = run_spec_expecting_non_zero(:before)
expect(output).to eq unindent(<<-EOS)

Expand All @@ -67,7 +67,7 @@ def run_spec_expecting_non_zero(before_or_after)
EOS
end

it 'nicely formats errors in `after(:suite)` hooks and exits with non-zero' do
it 'nicely formats errors in `after(:suite)` hooks and exits with non-zero', :isolated_home => true do
output = run_spec_expecting_non_zero(:after)
expect(output).to eq unindent(<<-EOS)
.
Expand All @@ -85,7 +85,7 @@ def run_spec_expecting_non_zero(before_or_after)
EOS
end

it 'nicely formats errors from multiple :suite hooks of both types and exits with non-zero' do
it 'nicely formats errors from multiple :suite hooks of both types and exits with non-zero', :isolated_home => true do
write_file "the_spec.rb", "
RSpec.configure do |c|
c.before(:suite) { raise 'before 1' }
Expand Down
2 changes: 1 addition & 1 deletion spec/rspec/core/formatters/documentation_formatter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def execution_result(values)
end

# The backtrace is slightly different on JRuby/Rubinius so we skip there.
it 'produces the expected full output', :if => RSpec::Support::Ruby.mri? do
it 'produces the expected full output', :isolated_home => true, :if => RSpec::Support::Ruby.mri? do
output = run_example_specs_with_formatter("doc")
output.gsub!(/ +$/, '') # strip trailing whitespace

Expand Down
4 changes: 2 additions & 2 deletions spec/rspec/core/formatters/html_formatter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ def extract_backtrace_from(doc)
end
end

describe 'produced HTML', :slow, :if => RUBY_VERSION >= '2.0.0' do
it "is identical to the one we designed manually", :pending => (defined?(RUBY_ENGINE) && RUBY_ENGINE == 'jruby') do
describe 'produced HTML', :slow, :isolated_home => true, :if => RUBY_VERSION >= '2.0.0' do
it 'is identical to the one we designed manually', :pending => (defined?(RUBY_ENGINE) && RUBY_ENGINE == 'jruby') do
expect(actual_html).to eq(expected_html)
end

Expand Down
2 changes: 1 addition & 1 deletion spec/rspec/core/formatters/progress_formatter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
end

# The backtrace is slightly different on JRuby/Rubinius so we skip there.
it 'produces the expected full output', :if => RSpec::Support::Ruby.mri? do
it 'produces the expected full output', :isolated_home => true, :if => RSpec::Support::Ruby.mri? do
output = run_example_specs_with_formatter("progress")
output.gsub!(/ +$/, '') # strip trailing whitespace

Expand Down
30 changes: 30 additions & 0 deletions spec/support/formatter_support.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ def expected_summary_output_for_example_specs
| # ./spec/rspec/core/resources/formatter_specs.rb:18
| # ./spec/support/formatter_support.rb:41:in `run_rspec_with_formatter'
| # ./spec/support/formatter_support.rb:3:in `run_example_specs_with_formatter'
| # ./spec/support/isolated_home_directory.rb:13
| # ./spec/spec_helper.rb:46:in `with_env_vars'
| # ./spec/support/isolated_home_directory.rb:12
| # ./spec/spec_helper.rb:57:in `without_env_vars'
| # ./spec/support/isolated_home_directory.rb:11
| # ./spec/support/isolated_home_directory.rb:7
| # ./spec/support/sandboxing.rb:16
| # ./spec/support/sandboxing.rb:7
|
Expand All @@ -89,6 +95,12 @@ def expected_summary_output_for_example_specs
| # ./spec/rspec/core/resources/formatter_specs.rb:37
| # ./spec/support/formatter_support.rb:41:in `run_rspec_with_formatter'
| # ./spec/support/formatter_support.rb:3:in `run_example_specs_with_formatter'
| # ./spec/support/isolated_home_directory.rb:13
| # ./spec/spec_helper.rb:46:in `with_env_vars'
| # ./spec/support/isolated_home_directory.rb:12
| # ./spec/spec_helper.rb:57:in `without_env_vars'
| # ./spec/support/isolated_home_directory.rb:11
| # ./spec/support/isolated_home_directory.rb:7
| # ./spec/support/sandboxing.rb:16
| # ./spec/support/sandboxing.rb:7
|
Expand Down Expand Up @@ -164,6 +176,12 @@ def expected_summary_output_for_example_specs
| # ./spec/rspec/core/resources/formatter_specs.rb:18:in `block (3 levels) in <top (required)>'
| # ./spec/support/formatter_support.rb:41:in `run_rspec_with_formatter'
| # ./spec/support/formatter_support.rb:3:in `run_example_specs_with_formatter'
| # ./spec/support/isolated_home_directory.rb:13:in `block (5 levels) in <top (required)>'
| # ./spec/spec_helper.rb:46:in `with_env_vars'
| # ./spec/support/isolated_home_directory.rb:12:in `block (4 levels) in <top (required)>'
| # ./spec/spec_helper.rb:57:in `without_env_vars'
| # ./spec/support/isolated_home_directory.rb:11:in `block (3 levels) in <top (required)>'
| # ./spec/support/isolated_home_directory.rb:7:in `block (2 levels) in <top (required)>'
| # ./spec/support/sandboxing.rb:16:in `block (3 levels) in <top (required)>'
| # ./spec/support/sandboxing.rb:7:in `block (2 levels) in <top (required)>'
|
Expand All @@ -184,6 +202,12 @@ def expected_summary_output_for_example_specs
| # ./spec/rspec/core/resources/formatter_specs.rb:37:in `block (2 levels) in <top (required)>'
| # ./spec/support/formatter_support.rb:41:in `run_rspec_with_formatter'
| # ./spec/support/formatter_support.rb:3:in `run_example_specs_with_formatter'
| # ./spec/support/isolated_home_directory.rb:13:in `block (5 levels) in <top (required)>'
| # ./spec/spec_helper.rb:46:in `with_env_vars'
| # ./spec/support/isolated_home_directory.rb:12:in `block (4 levels) in <top (required)>'
| # ./spec/spec_helper.rb:57:in `without_env_vars'
| # ./spec/support/isolated_home_directory.rb:11:in `block (3 levels) in <top (required)>'
| # ./spec/support/isolated_home_directory.rb:7:in `block (2 levels) in <top (required)>'
| # ./spec/support/sandboxing.rb:16:in `block (3 levels) in <top (required)>'
| # ./spec/support/sandboxing.rb:7:in `block (2 levels) in <top (required)>'
|
Expand Down Expand Up @@ -215,6 +239,12 @@ def expected_summary_output_for_example_specs
| # ./spec/rspec/core/resources/formatter_specs.rb:50:in `block (2 levels) in <top (required)>'
| # ./spec/support/formatter_support.rb:41:in `run_rspec_with_formatter'
| # ./spec/support/formatter_support.rb:3:in `run_example_specs_with_formatter'
| # ./spec/support/isolated_home_directory.rb:13:in `block (5 levels) in <top (required)>'
| # ./spec/spec_helper.rb:46:in `with_env_vars'
| # ./spec/support/isolated_home_directory.rb:12:in `block (4 levels) in <top (required)>'
| # ./spec/spec_helper.rb:57:in `without_env_vars'
| # ./spec/support/isolated_home_directory.rb:11:in `block (3 levels) in <top (required)>'
| # ./spec/support/isolated_home_directory.rb:7:in `block (2 levels) in <top (required)>'
| # ./spec/support/sandboxing.rb:16:in `block (3 levels) in <top (required)>'
| # ./spec/support/sandboxing.rb:7:in `block (2 levels) in <top (required)>'
|
Expand Down