Skip to content

Commit fdf59ec

Browse files
committed
Updating usage of Aruba.
This gets both specs and features passing without deprecation warnings using Aruba 0.14.2, as discussed in rspec#2437. Two caveats: * There is a 1.0.0 pre-release version of Aruba, but it requires Cucumber 2, and that’s a whole different can of worms to open. * The gemspec notes that Aruba 0.7 is broken on MRI 1.8.7. I’m not sure if 0.14 is happier, but perhaps Travis will tell us. If it’s not, I guess this change can’t be merged in until RSpec 4 is on the cards?
1 parent 18d0e0e commit fdf59ec

18 files changed

+69
-60
lines changed

features/command_line/only_failures.feature

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,9 @@ Feature: Only Failures
105105

106106
Scenario: Running `rspec --only-failures` with spec files that pass doesn't run anything
107107
When I run `rspec spec/passing_spec.rb --only-failures`
108-
Then it should pass with "0 examples, 0 failures"
108+
Then it should pass with output "0 examples, 0 failures"
109109

110110
Scenario: Clear error given when using `--only-failures` without configuring `example_status_persistence_file_path`
111111
Given I have not configured `example_status_persistence_file_path`
112112
When I run `rspec --only-failures`
113-
Then it should fail with "To use `--only-failures`, you must first set `config.example_status_persistence_file_path`."
113+
Then it should fail with output "To use `--only-failures`, you must first set `config.example_status_persistence_file_path`."

features/configuration/fail_if_no_examples.feature

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ Feature: fail if no examples
2424

2525
Scenario: Examples file name is not matched by RSpec pattern, thus there are no examples run
2626
When I run `rspec`
27-
Then it should fail with "0 examples, 0 failures"
27+
Then it should fail with output "0 examples, 0 failures"
2828

2929
Scenario: Examples file name is matched by RSpec pattern, 1 example is run
3030
When I run `rspec --pattern spec/**/*.spec.rb`
31-
Then it should pass with "1 example, 0 failures"
31+
Then it should pass with output "1 example, 0 failures"

features/filtering/filter_run_when_matching.feature

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ Feature: filter_run_when_matching
4444

4545
Scenario: The filter is ignored when nothing is focused
4646
When I run `rspec --format doc`
47-
Then it should pass with "2 examples, 0 failures"
47+
Then it should pass with output "2 examples, 0 failures"
4848
And the output should contain:
4949
"""
5050
A group
@@ -56,7 +56,7 @@ Feature: filter_run_when_matching
5656
Scenario: Examples can be focused with `fit`
5757
Given I have changed `it "has a passing example"` to `fit "has a passing example"` in "spec/example_spec.rb"
5858
When I run `rspec --format doc`
59-
Then it should pass with "1 example, 0 failures"
59+
Then it should pass with output "1 example, 0 failures"
6060
And the output should contain:
6161
"""
6262
A group
@@ -66,7 +66,7 @@ Feature: filter_run_when_matching
6666
Scenario: Groups can be focused with `fdescribe` or `fcontext`
6767
Given I have changed `context` to `fcontext` in "spec/example_spec.rb"
6868
When I run `rspec --format doc`
69-
Then it should pass with "1 example, 0 failures"
69+
Then it should pass with output "1 example, 0 failures"
7070
And the output should contain:
7171
"""
7272
A group

features/formatters/configurable_colors.feature

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Feature: Configurable colors
1212
Colors are specified as symbols. Options are `:black`, `:red`, `:green`,
1313
`:yellow`, `:blue`, `:magenta`, `:cyan`, and `:white`.
1414

15-
@ansi
15+
@keep-ansi-escape-sequences
1616
Scenario: Customizing the failure color
1717
Given a file named "custom_failure_color_spec.rb" with:
1818
"""ruby

features/step_definitions/additional_cli_steps.rb

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,19 @@
44

55
Then /^the output should contain all of these:$/ do |table|
66
table.raw.flatten.each do |string|
7-
assert_partial_output(string, all_output)
7+
expect(all_commands.map { |c| c.output }.join("\n")).to include(string)
88
end
99
end
1010

1111
Then /^the output should not contain any of these:$/ do |table|
1212
table.raw.flatten.each do |string|
13-
expect(all_output).not_to include(string)
13+
expect(all_commands.map { |c| c.output }.join("\n")).not_to include(string)
1414
end
1515
end
1616

1717
Then /^the output should contain one of the following:$/ do |table|
1818
matching_output = table.raw.flatten.select do |string|
19-
all_output.include?(string)
19+
all_commands.map { |c| c.output }.join("\n").include?(string)
2020
end
2121

2222
expect(matching_output.count).to eq(1)
@@ -28,7 +28,7 @@
2828
step %q{the exit status should be 0}
2929
end
3030

31-
Then /^it should pass with "(.*?)"$/ do |string|
31+
Then /^it should pass with output "(.*?)"$/ do |string|
3232
step %Q{the output should contain "#{string}"}
3333
step %q{the exit status should be 0}
3434
end
@@ -37,7 +37,9 @@
3737
step %q{the output should not contain "0 examples"}
3838
step %q{the output should not contain "0 failures"}
3939
step %q{the exit status should be 1}
40-
example_summary = /(\d+) examples?, (\d+) failures?/.match(all_output)
40+
example_summary = /(\d+) examples?, (\d+) failures?/.match(
41+
all_commands.map { |c| c.output }.join("\n")
42+
)
4143
example_count, failure_count = example_summary.captures
4244
expect(failure_count).to eq(example_count)
4345
end
@@ -69,7 +71,7 @@
6971
Then /^the backtrace\-normalized output should contain:$/ do |partial_output|
7072
# ruby 1.9 includes additional stuff in the backtrace,
7173
# so we need to normalize it to compare it with our expected output.
72-
normalized_output = all_output.split("\n").map do |line|
74+
normalized_output = all_commands.map { |c| c.output }.map do |line|
7375
line =~ /(^\s+# [^:]+:\d+)/ ? $1 : line # http://rubular.com/r/zDD7DdWyzF
7476
end.join("\n")
7577

@@ -84,7 +86,7 @@
8486
Then /^the failing example is printed in magenta$/ do
8587
# \e[35m = enable magenta
8688
# \e[0m = reset colors
87-
expect(all_output).to include("\e[35m" + "F" + "\e[0m")
89+
expect(all_commands.map { |c| c.output }.join("\n")).to include("\e[35m" + "F" + "\e[0m")
8890
end
8991

9092
Then /^the output from `([^`]+)` should contain "(.*?)"$/ do |cmd, expected_output|
@@ -98,24 +100,24 @@
98100
end
99101

100102
Given /^I have a brand new project with no files$/ do
101-
in_current_dir do
103+
cd "." do
102104
expect(Dir["**/*"]).to eq([])
103105
end
104106
end
105107

106108
Given /^I have run `([^`]*)`$/ do |cmd|
107109
fail_on_error = true
108-
run_simple(unescape(cmd), fail_on_error)
110+
run_simple(sanitize_text(cmd), fail_on_error)
109111
end
110112

111113
Given(/^a vendored gem named "(.*?)" containing a file named "(.*?)" with:$/) do |gem_name, file_name, file_contents|
112114
gem_dir = "vendor/#{gem_name}-1.2.3"
113115
step %Q{a file named "#{gem_dir}/#{file_name}" with:}, file_contents
114-
set_env('RUBYOPT', ENV['RUBYOPT'] + " -I#{gem_dir}/lib")
116+
set_environment_variable('RUBYOPT', ENV['RUBYOPT'] + " -I#{gem_dir}/lib")
115117
end
116118

117119
When "I accept the recommended settings by removing `=begin` and `=end` from `spec/spec_helper.rb`" do
118-
in_current_dir do
120+
cd "." do
119121
spec_helper = File.read("spec/spec_helper.rb")
120122
expect(spec_helper).to include("=begin", "=end")
121123

@@ -138,20 +140,21 @@
138140
end
139141

140142
When(/^I fix "(.*?)" by replacing "(.*?)" with "(.*?)"$/) do |file_name, original, replacement|
141-
in_current_dir do
143+
cd "." do
142144
contents = File.read(file_name)
143145
expect(contents).to include(original)
144146
fixed = contents.sub(original, replacement)
145147
File.open(file_name, "w") { |f| f.write(fixed) }
146148
end
147149
end
148150

149-
Then(/^it should fail with "(.*?)"$/) do |snippet|
150-
assert_failing_with(snippet)
151+
Then(/^it should fail with output "(.*?)"$/) do |snippet|
152+
expect(all_commands).not_to include_an_object(be_successfully_executed)
153+
expect(all_commands.map { |c| c.output }.join("\n")).to include(snippet)
151154
end
152155

153156
Given(/^I have not configured `example_status_persistence_file_path`$/) do
154-
in_current_dir do
157+
cd "." do
155158
return unless File.exist?("spec/spec_helper.rb")
156159
return unless File.read("spec/spec_helper.rb").include?("example_status_persistence_file_path")
157160
File.open("spec/spec_helper.rb", "w") { |f| f.write("") }
@@ -173,10 +176,10 @@
173176
end
174177

175178
Then(/^bisect should (succeed|fail) with output like:$/) do |succeed, expected_output|
176-
last_process = only_processes.last
179+
last_process = all_commands.last
177180
expected_status = succeed == "succeed" ? 0 : 1
178-
expect(last_exit_status).to eq(expected_status),
179-
"Expected exit status of #{expected_status} but got #{last_exit_status} \n\n" \
181+
expect(last_process.exit_status).to eq(expected_status),
182+
"Expected exit status of #{expected_status} but got #{last_process.exit_status} \n\n" \
180183
"Output:\n\n#{last_process.stdout}"
181184

182185
expected = normalize_durations(expected_output)
@@ -186,18 +189,18 @@
186189
end
187190

188191
When(/^I run `([^`]+)` and abort in the middle with ctrl\-c$/) do |cmd|
189-
set_env('RUBYOPT', ENV['RUBYOPT'] + " -r#{File.expand_path("../../support/send_sigint_during_bisect.rb", __FILE__)}")
192+
set_environment_variable('RUBYOPT', ENV['RUBYOPT'] + " -r#{File.expand_path("../../support/send_sigint_during_bisect.rb", __FILE__)}")
190193
step "I run `#{cmd}`"
191194
end
192195

193196
Then(/^it should fail and list all the failures:$/) do |string|
194197
step %q{the exit status should not be 0}
195-
expect(normalize_failure_output(all_output)).to include(normalize_failure_output(string))
198+
expect(normalize_failure_output(all_commands.map { |c| c.output }.join("\n"))).to include(normalize_failure_output(string))
196199
end
197200

198201
Then(/^it should pass and list all the pending examples:$/) do |string|
199202
step %q{the exit status should be 0}
200-
expect(normalize_failure_output(all_output)).to include(normalize_failure_output(string))
203+
expect(normalize_failure_output(all_commands.map { |c| c.output }.join("\n"))).to include(normalize_failure_output(string))
201204
end
202205

203206
Then(/^the output should report "slow before context hook" as the slowest example group$/) do
@@ -213,19 +216,21 @@
213216
# - "Nested" group listed (it should be the outer group)
214217
# - The example group class name is listed (it should be the location)
215218

216-
expect(all_output).not_to match(/nested/i)
217-
expect(all_output).not_to match(/inf/i)
218-
expect(all_output).not_to match(/\b0 examples/i)
219+
output = all_commands.map { |c| c.output }.join("\n")
220+
221+
expect(output).not_to match(/nested/i)
222+
expect(output).not_to match(/inf/i)
223+
expect(output).not_to match(/\b0 examples/i)
219224

220225
seconds = '\d+(?:\.\d+)? seconds'
221226

222-
expect(all_output).to match(
227+
expect(output).to match(
223228
%r{Top 1 slowest example groups?:\n\s+slow before context hook\n\s+#{seconds} average \(#{seconds} / 1 example\) \./spec/example_spec\.rb:1}
224229
)
225230
end
226231

227232
Given(/^I have changed `([^`]+)` to `([^`]+)` in "(.*?)"$/) do |old_code, new_code, file_name|
228-
in_current_dir do
233+
cd "." do
229234
file_content = File.read(file_name)
230235
expect(file_content).to include(old_code)
231236
new_file_content = file_content.sub(old_code, new_code)

features/step_definitions/core_standalone_steps.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
if RUBY_VERSION.to_f >= 1.9 # --disable-gems is invalid on 1.8.7
33
# Ensure the gem versions of rspec-mocks and rspec-expectations
44
# won't be loaded if available on the developers machine.
5-
set_env('RUBYOPT', ENV['RUBYOPT'] + ' --disable-gems')
5+
set_environment_variable('RUBYOPT', ENV['RUBYOPT'] + ' --disable-gems')
66
end
77

88
# This will make `require_expect_syntax_in_aruba_specs.rb` (loaded
99
# automatically when the specs run) remove rspec-mocks and
1010
# rspec-expectations from the load path.
11-
set_env('REMOVE_OTHER_RSPEC_LIBS_FROM_LOAD_PATH', 'true')
11+
set_environment_variable('REMOVE_OTHER_RSPEC_LIBS_FROM_LOAD_PATH', 'true')
1212
end
1313

1414
Given(/^rspec-expectations is not installed$/) do

features/support/env.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Before do
44
# Force ids to be printed unquoted for consistency
5-
set_env('SHELL', '/usr/bin/bash')
5+
set_environment_variable('SHELL', '/usr/bin/bash')
66

77
if RUBY_PLATFORM =~ /java/ || defined?(Rubinius)
88
@aruba_timeout_seconds = 120
@@ -13,12 +13,12 @@
1313

1414
Aruba.configure do |config|
1515
config.before_cmd do |cmd|
16-
set_env('JRUBY_OPTS', "-X-C #{ENV['JRUBY_OPTS']}") # disable JIT since these processes are so short lived
16+
set_environment_variable('JRUBY_OPTS', "-X-C #{ENV['JRUBY_OPTS']}") # disable JIT since these processes are so short lived
1717
end
1818
end if RUBY_PLATFORM == 'java'
1919

2020
Aruba.configure do |config|
2121
config.before_cmd do |cmd|
22-
set_env('RBXOPT', "-Xint=true #{ENV['RBXOPT']}") # disable JIT since these processes are so short lived
22+
set_environment_variable('RBXOPT', "-Xint=true #{ENV['RBXOPT']}") # disable JIT since these processes are so short lived
2323
end
2424
end if defined?(Rubinius)

features/support/require_expect_syntax_in_aruba_specs.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
if defined?(Cucumber)
22
require 'shellwords'
33
Before('~@allow-should-syntax', '~@with-clean-spec-opts') do
4-
set_env('SPEC_OPTS', "-r#{Shellwords.escape(__FILE__)}")
4+
set_environment_variable('SPEC_OPTS', "-r#{Shellwords.escape(__FILE__)}")
55
end
66

77
Before('@oneliner-should') do
8-
set_env('ALLOW_ONELINER_SHOULD', 'true')
8+
set_environment_variable('ALLOW_ONELINER_SHOULD', 'true')
99
end
1010
else
1111
if ENV['REMOVE_OTHER_RSPEC_LIBS_FROM_LOAD_PATH']

rspec-core.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ Gem::Specification.new do |s|
3939

4040
s.add_development_dependency "cucumber", "~> 1.3"
4141
s.add_development_dependency "minitest", "~> 5.3"
42-
s.add_development_dependency "aruba", "~> 0.6.2" # 0.7 is broken on ruby 1.8.7
42+
s.add_development_dependency "aruba", "~> 0.14.2" # 0.7 is broken on ruby 1.8.7
4343

4444
s.add_development_dependency "coderay", "~> 1.1.1"
4545

spec/integration/fail_if_no_examples_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
RSpec.describe 'Fail if no examples' do
44
include_context "aruba support"
5-
before { clean_current_dir }
5+
before { setup_aruba }
66

77
context 'when 1 passing example' do
88
def passing_example(fail_if_no_examples)

spec/integration/failed_line_detection_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
RSpec.describe 'Failed line detection' do
44
include_context "aruba support"
5-
before { clean_current_dir }
5+
before { setup_aruba }
66

77
it "finds the source of a failure in a spec file that is defined at the current directory instead of in the normal `spec` subdir" do
88
write_file "the_spec.rb", "
@@ -32,7 +32,7 @@
3232
end
3333
"
3434

35-
file = in_current_dir { "#{Dir.pwd}/failing_spec.rb" }
35+
file = cd(".") { "#{Dir.pwd}/failing_spec.rb" }
3636
load file
3737
run_command "passing_spec.rb"
3838

spec/integration/filtering_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
RSpec.describe 'Filtering' do
44
include_context "aruba support"
5-
before { clean_current_dir }
5+
before { setup_aruba }
66

77
it 'prints a rerun command for shared examples in external files that works to rerun' do
88
write_file "spec/support/shared_examples.rb", "
@@ -205,7 +205,7 @@ def run_rerun_command_for_failing_spec
205205
expect(last_cmd_stdout).to match(/3 examples, 0 failures/)
206206

207207
# Using absolute paths...
208-
spec_root = in_current_dir { File.expand_path("spec") }
208+
spec_root = cd(".") { File.expand_path("spec") }
209209
run_command "#{spec_root}/file_1_spec.rb[1:1,1:3] #{spec_root}/file_2_spec.rb[1:2]"
210210
expect(last_cmd_stdout).to match(/3 examples, 0 failures/)
211211
end

spec/integration/order_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@
131131
end
132132

133133
describe '--order defined on CLI with --order rand in .rspec' do
134-
after { remove_file '.rspec' }
134+
after { remove '.rspec' }
135135

136136
it "overrides --order rand with --order defined" do
137137
write_file '.rspec', '--order rand'
@@ -147,7 +147,7 @@
147147
end
148148

149149
context 'when a custom order is configured' do
150-
after { remove_file 'spec/custom_order_spec.rb' }
150+
after { remove 'spec/custom_order_spec.rb' }
151151

152152
before do
153153
write_file 'spec/custom_order_spec.rb', "

spec/integration/output_stream_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
RSpec.describe 'Output stream' do
44
include_context 'aruba support'
5-
before { clean_current_dir }
5+
before { setup_aruba }
66

77
context 'when a formatter set in a configure block' do
88
it 'writes to the right output stream' do
@@ -21,7 +21,7 @@
2121

2222
run_command ''
2323
expect(last_cmd_stdout).to be_empty
24-
in_current_dir do
24+
cd "." do
2525
expect(File.read('saved_output')).to include('1 example, 0 failures')
2626
end
2727
end
@@ -42,7 +42,7 @@
4242

4343
run_command ''
4444
expect(last_cmd_stdout).to be_empty
45-
in_current_dir do
45+
cd "." do
4646
expect(File.read('saved_output')).to include('1 example, 0 failures')
4747
end
4848
end
@@ -64,7 +64,7 @@
6464

6565
run_command ''
6666
expect(last_cmd_stdout).to be_empty
67-
in_current_dir do
67+
cd "." do
6868
expect(File.read('saved_output')).to include('1 example, 0 failures')
6969
end
7070
end

0 commit comments

Comments
 (0)