Sha256: 37c6b60332ed19a3f5985b5e22682b518f0de4828d3ce281e045ef42b4597527

Contents?: true

Size: 1.62 KB

Versions: 29

Compression:

Stored size: 1.62 KB

Contents

require 'rspec/support/spec/shell_out'

module RSpec
  module Support
    module WarningsPrevention
      def files_to_require_for(lib)
        slash         = File::SEPARATOR
        lib_path_re   = /#{slash + lib}[^#{slash}]*#{slash}lib/
        load_path     = $LOAD_PATH.grep(lib_path_re).first
        files         = Dir["#{load_path}/**/*.rb"]
        extract_regex = /#{Regexp.escape(load_path) + File::SEPARATOR}(.+)\.rb$/

        # We sort to ensure the files are loaded in a consistent order, regardless
        # of OS. Otherwise, it could load in a different order on Travis than
        # locally, and potentially trigger a "circular require considered harmful"
        # warning or similar.
        files.sort.map { |file| file[extract_regex, 1] }
      end
    end
  end
end

RSpec.shared_examples_for "a library that issues no warnings when loaded" do |lib, *preamble_stmnts|
  include RSpec::Support::ShellOut
  include RSpec::Support::WarningsPrevention

  it "issues no warnings when loaded", :slow do
    # We want to explicitly load every file because each lib has some files that
    # aren't automatically loaded, instead being delayed based on an autoload
    # (such as for rspec-expectations' matchers) or based on a config option
    # (e.g. `config.mock_with :rr` => 'rspec/core/mocking_adapters/rr').
    statements = preamble_stmnts + files_to_require_for(lib).map do |file|
      "require '#{file}'"
    end

    command = statements.join("; ")

    stdout, stderr, status = run_ruby_with_current_load_path(command, "-w")

    expect(stdout).to eq("")
    expect(stderr).to eq("")
    expect(status.exitstatus).to eq(0)
  end
end

Version data entries

29 entries across 26 versions & 8 rubygems

Version Path
opal-rspec-0.8.0 rspec-support/upstream/lib/rspec/support/spec/prevent_load_time_warnings.rb
opal-rspec-0.8.0.alpha3 rspec-support/upstream/lib/rspec/support/spec/prevent_load_time_warnings.rb
opal-rspec-0.8.0.alpha2 rspec-support/upstream/lib/rspec/support/spec/prevent_load_time_warnings.rb
opal-rspec-0.8.0.alpha1 rspec-support/upstream/lib/rspec/support/spec/prevent_load_time_warnings.rb
opal-rspec-0.7.1 rspec-support/upstream/lib/rspec/support/spec/prevent_load_time_warnings.rb
opal-rspec-0.7.0 rspec-support/upstream/lib/rspec/support/spec/prevent_load_time_warnings.rb
opal-rspec-0.6.2 rspec-support/lib/rspec/support/spec/prevent_load_time_warnings.rb
opal-rspec-0.7.0.rc.2 rspec-support/upstream/lib/rspec/support/spec/prevent_load_time_warnings.rb
opal-rspec-0.6.1 rspec-support/lib/rspec/support/spec/prevent_load_time_warnings.rb
opal-rspec-0.6.0 rspec-support/lib/rspec/support/spec/prevent_load_time_warnings.rb
opal-rspec-0.6.0.beta1 rspec-support/lib/rspec/support/spec/prevent_load_time_warnings.rb
opal-connect-rspec-0.5.0 rspec-support/lib/rspec/support/spec/prevent_load_time_warnings.rb
able-neo4j-1.0.0 vendor/bundle/jruby/1.9/gems/rspec-support-3.1.2/lib/rspec/support/spec/prevent_load_time_warnings.rb
honeybadger-2.4.0 vendor/gems/ruby/2.1.0/gems/rspec-support-3.1.0/lib/rspec/support/spec/prevent_load_time_warnings.rb
honeybadger-2.4.0 vendor/gems/ruby/1.9.1/gems/rspec-support-3.1.0/lib/rspec/support/spec/prevent_load_time_warnings.rb
honeybadger-2.4.0 vendor/gems/ruby/2.2.0/gems/rspec-support-3.1.0/lib/rspec/support/spec/prevent_load_time_warnings.rb
opal-rspec-0.5.0 rspec-support/lib/rspec/support/spec/prevent_load_time_warnings.rb
logstash-input-beats-2.0.2 vendor/jruby/1.9/gems/rspec-support-3.1.2/lib/rspec/support/spec/prevent_load_time_warnings.rb
logstash-input-beats-2.0.2 vendor/jruby/1.9/gems/logstash-codec-json-2.0.3/vendor/gems/rspec-support-3.1.2/lib/rspec/support/spec/prevent_load_time_warnings.rb
logstash-codec-json-2.0.3 vendor/gems/rspec-support-3.1.2/lib/rspec/support/spec/prevent_load_time_warnings.rb