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

Improve output from rspec -v. #2304

Merged
merged 1 commit into from
Jul 26, 2016
Merged
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
2 changes: 2 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ Enhancements:
* Improve metadata filtering so that it can match against any object
that implements `===` instead of treating regular expressions as
special. (Myron Marston, #2294)
* Improve `rspec -v` so that it prints out the versions of each part of
RSpec to prevent confusion. (Myron Marston, #2304)

Bug Fixes:

Expand Down
20 changes: 19 additions & 1 deletion lib/rspec/core/invocations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,25 @@ def bisect_formatter_for(argument)
# @private
class PrintVersion
def call(_options, _err, out)
out.puts RSpec::Core::Version::STRING
overall_version = RSpec::Core::Version::STRING
unless overall_version =~ /[a-zA-Z]+/
overall_version = overall_version.split('.').first(2).join('.')
end

out.puts "RSpec #{overall_version}"

[:Core, :Expectations, :Mocks, :Rails, :Support].each do |const_name|
lib_name = const_name.to_s.downcase
begin
require "rspec/#{lib_name}/version"
rescue LoadError
# Not worth mentioning libs that are not installed
nil
else
out.puts " - rspec-#{lib_name} #{RSpec.const_get(const_name)::Version::STRING}"
end
end

0
end
end
Expand Down
42 changes: 38 additions & 4 deletions spec/rspec/core/invocations_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,46 @@ def run_invocation
end

describe Invocations::PrintVersion do
it "prints the version and returns a zero exit code" do
it "prints the major.minor version of RSpec as a whole" do
stub_const("RSpec::Core::Version::STRING", "9.18.23")
run_invocation
expect(out.string).to include("RSpec 9.18\n")
end

exit_code = run_invocation
it "prints off the whole version if it's a pre-release" do
stub_const("RSpec::Core::Version::STRING", "9.18.0-beta1")
run_invocation
expect(out.string).to include("RSpec 9.18.0-beta1\n")
end

expect(exit_code).to eq(0)
expect(out.string).to include("#{RSpec::Core::Version::STRING}\n")
it "prints off the version of each part of RSpec" do
[:Core, :Expectations, :Mocks, :Support].each_with_index do |const_name, index|
# validate that this is an existing const
expect(RSpec.const_get(const_name)::Version::STRING).to be_a String

stub_const("RSpec::#{const_name}::Version::STRING", "9.2.#{index}")
end

run_invocation

expect(out.string).to include(
"- rspec-core 9.2.0",
"- rspec-expectations 9.2.1",
"- rspec-mocks 9.2.2",
"- rspec-support 9.2.3"
)
end

it "indicates a part is not installed if it cannot be loaded" do
expect { require 'rspec/rails/version' }.to raise_error(LoadError)

run_invocation

expect(out.string).not_to include("rspec-rails")
end

it "returns a zero exit code" do
expect(run_invocation).to eq 0
end
end

Expand Down