1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
|
require 'pathname'
RSpec.describe "Verify required rspec dependencies" do
tmp_root = Pathname.new(RSpec::Core::RubyProject.root).join("tmp")
before { FileUtils.mkdir_p tmp_root }
def with_clean_env
if Bundler.respond_to?(:with_unbundled_env)
Bundler.with_unbundled_env { yield }
else
Bundler.with_clean_env { yield }
end
end
it "fails when libraries are not required" do
script = tmp_root.join("fail_sanity_check")
File.open(script, "w") do |f|
f.write <<-EOF.gsub(/^\s+\|/, '')
|#!/usr/bin/env ruby
|RSpec::Support.require_rspec_core "project_initializer"
EOF
end
FileUtils.chmod 0777, script
with_clean_env do
expect(`bundle exec #{script} 2>&1`)
.to match(/uninitialized constant RSpec::Support/)
.or match(/undefined method `require_rspec_core' for RSpec::Support:Module/)
.or match(/undefined method `require_rspec_core' for module RSpec::Support/)
.or match(/undefined method 'require_rspec_core' for module RSpec::Support/)
expect($?.exitstatus).to eq(1)
end
end
it "passes when libraries are required", skip: RSpec::Support::Ruby.jruby? do
script = tmp_root.join("pass_sanity_check")
File.open(script, "w") do |f|
f.write <<-EOF.gsub(/^\s+\|/, '')
|#!/usr/bin/env ruby
|require 'rspec/core'
|require 'rspec/support'
|RSpec::Support.require_rspec_core "project_initializer"
EOF
end
FileUtils.chmod 0777, script
with_clean_env do
expect(`bundle exec #{script} 2>&1`).to be_empty
expect($?.exitstatus).to eq(0)
end
end
end
|