autoloaded 1.4.1 → 1.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/.gitignore +4 -8
- data/.rspec +1 -1
- data/.travis.yml +15 -0
- data/Gemfile +11 -10
- data/Guardfile +21 -22
- data/History.md +35 -10
- data/License.md +1 -1
- data/README.md +78 -68
- data/Rakefile +4 -0
- data/autoloaded.gemspec +41 -37
- data/bin/console +10 -0
- data/bin/setup +8 -0
- data/lib/autoloaded/autoloader.rb +24 -6
- data/lib/autoloaded/constant.rb +1 -0
- data/lib/autoloaded/deprecation.rb +0 -2
- data/lib/autoloaded/inflection.rb +0 -2
- data/lib/autoloaded/load_pathed_directory.rb +2 -4
- data/lib/autoloaded/specification.rb +2 -0
- data/lib/autoloaded/specifications.rb +3 -3
- data/lib/autoloaded/version.rb +1 -1
- data/lib/autoloaded/warning.rb +1 -3
- data/lib/tasks/lib_each.rake +15 -3
- data/lib/tasks/spec.rake +3 -6
- metadata +22 -121
- data/spec/autoloaded/autoloader_spec.rb +0 -469
- data/spec/autoloaded/constant_spec.rb +0 -53
- data/spec/autoloaded/deprecation_spec.rb +0 -23
- data/spec/autoloaded/inflection_spec.rb +0 -30
- data/spec/autoloaded/load_pathed_directory_spec.rb +0 -120
- data/spec/autoloaded/refine/string/to_source_filename_spec.rb +0 -19
- data/spec/autoloaded/specification_spec.rb +0 -98
- data/spec/autoloaded/specifications_spec.rb +0 -191
- data/spec/autoloaded/version_spec.rb +0 -3
- data/spec/autoloaded/warning_spec.rb +0 -115
- data/spec/autoloaded_macro_sharedspec.rb +0 -24
- data/spec/autoloaded_spec.rb +0 -321
- data/spec/fixtures/autoloaded_with_conventional_filename/N-est-ed.rb +0 -1
- data/spec/fixtures/autoloaded_with_conventional_filename/nest_ed.rb +0 -1
- data/spec/fixtures/autoloaded_with_conventional_filename/nested/doubly_nested.rb +0 -9
- data/spec/fixtures/autoloaded_with_conventional_filename/nested.rb +0 -16
- data/spec/fixtures/autoloaded_with_conventional_filename/old_school_autoload.rb +0 -5
- data/spec/fixtures/autoloaded_with_conventional_filename.rb +0 -12
- data/spec/fixtures/autoloaded_with_unconventional_filename/N-est-ed.rb +0 -7
- data/spec/fixtures/autoloaded_with_unconventional_filename/nest_ed.rb +0 -1
- data/spec/fixtures/autoloaded_with_unconventional_filename/old_school_autoload.rb +0 -5
- data/spec/fixtures/autoloaded_with_unconventional_filename.rb +0 -12
- data/spec/fixtures/filenames/AFilename.rb +0 -0
- data/spec/fixtures/filenames/a-file-name.rb +0 -0
- data/spec/fixtures/filenames/a-filename.rb +0 -0
- data/spec/fixtures/filenames/a_file_name.rb +0 -0
- data/spec/fixtures/filenames/a_filename.rb +0 -0
- data/spec/fixtures/filenames/afile-name.rb +0 -0
- data/spec/fixtures/filenames/afile_name.rb +0 -0
- data/spec/fixtures/not_autoloaded/nested.rb +0 -1
- data/spec/fixtures/not_autoloaded/old_school_autoload.rb +0 -5
- data/spec/fixtures/not_autoloaded.rb +0 -5
- data/spec/fixtures/old_api/autoloaded_with_conventional_filename/N-est-ed.rb +0 -1
- data/spec/fixtures/old_api/autoloaded_with_conventional_filename/nest_ed.rb +0 -1
- data/spec/fixtures/old_api/autoloaded_with_conventional_filename/nested.rb +0 -5
- data/spec/fixtures/old_api/autoloaded_with_conventional_filename/old_school_autoload.rb +0 -5
- data/spec/fixtures/old_api/autoloaded_with_conventional_filename.rb +0 -10
- data/spec/fixtures/old_api/autoloaded_with_conventional_filename_only/nested.rb +0 -5
- data/spec/fixtures/old_api/autoloaded_with_conventional_filename_only/old_school_autoload.rb +0 -5
- data/spec/fixtures/old_api/autoloaded_with_conventional_filename_only.rb +0 -10
- data/spec/fixtures/old_api/autoloaded_with_unconventional_filenames/N-est-ed.rb +0 -5
- data/spec/fixtures/old_api/autoloaded_with_unconventional_filenames/nest_ed.rb +0 -0
- data/spec/fixtures/old_api/autoloaded_with_unconventional_filenames/old_school_autoload.rb +0 -5
- data/spec/fixtures/old_api/autoloaded_with_unconventional_filenames.rb +0 -10
- data/spec/fixtures/old_api/not_autoloaded/nested.rb +0 -1
- data/spec/fixtures/old_api/not_autoloaded/old_school_autoload.rb +0 -5
- data/spec/fixtures/old_api/not_autoloaded.rb +0 -6
- data/spec/matchers.rb +0 -85
- data/spec/spec_helper.rb +0 -91
- data/spec/support/util.rb +0 -43
- data/spec/support/without_side_effects.rb +0 -37
| @@ -1,19 +0,0 @@ | |
| 1 | 
            -
            using Autoloaded::Refine::String::ToSourceFilename
         | 
| 2 | 
            -
             | 
| 3 | 
            -
            RSpec.describe Autoloaded::Refine::String::ToSourceFilename do
         | 
| 4 | 
            -
              {'Foo'        => 'foo',
         | 
| 5 | 
            -
               'IO'         => 'io',
         | 
| 6 | 
            -
               'MySQL2'     => 'my_sql2',
         | 
| 7 | 
            -
               'PostgreSQL' => 'postgre_sql',
         | 
| 8 | 
            -
               'Geo3D'      => 'geo3_d',
         | 
| 9 | 
            -
               'Xfiles'     => 'xfiles',
         | 
| 10 | 
            -
               'XFiles'     => 'x_files',
         | 
| 11 | 
            -
               'FOOBar'     => 'foo_bar',
         | 
| 12 | 
            -
               'FOO_BAR'    => 'foo_bar'}.each do |constant_name, filename|
         | 
| 13 | 
            -
                describe "for #{constant_name.inspect}" do
         | 
| 14 | 
            -
                  describe '#to_source_filename' do
         | 
| 15 | 
            -
                    specify { expect(constant_name.to_source_filename).to eq(filename) }
         | 
| 16 | 
            -
                  end
         | 
| 17 | 
            -
                end
         | 
| 18 | 
            -
              end
         | 
| 19 | 
            -
            end
         | 
| @@ -1,98 +0,0 @@ | |
| 1 | 
            -
            RSpec.describe Autoloaded::Specification do
         | 
| 2 | 
            -
              before :each do
         | 
| 3 | 
            -
                allow(inflector_class).to receive(:to_constant_name).
         | 
| 4 | 
            -
                                          and_return(:FromInflection1,
         | 
| 5 | 
            -
                                                     :FromInflection2,
         | 
| 6 | 
            -
                                                     :FromInflection3)
         | 
| 7 | 
            -
              end
         | 
| 8 | 
            -
             | 
| 9 | 
            -
              subject(:specification) { specification_class.new(*elements) }
         | 
| 10 | 
            -
             | 
| 11 | 
            -
              let(:specification_class) { described_class }
         | 
| 12 | 
            -
             | 
| 13 | 
            -
              let(:inflector_class) { Autoloaded::Inflection }
         | 
| 14 | 
            -
             | 
| 15 | 
            -
              specify("equals equivalent #{described_class.name}") {
         | 
| 16 | 
            -
                expect(specification_class.new('foo')).to eq(specification_class.new('foo'))
         | 
| 17 | 
            -
              }
         | 
| 18 | 
            -
             | 
| 19 | 
            -
              specify("doesn't equal #{Object.name}") {
         | 
| 20 | 
            -
                expect(specification_class.new('foo')).not_to eq(Object.new)
         | 
| 21 | 
            -
              }
         | 
| 22 | 
            -
             | 
| 23 | 
            -
              specify("doesn't equal #{described_class.name} with different #elements") {
         | 
| 24 | 
            -
                expect(specification_class.new('foo')).not_to eq(specification_class.new('bar'))
         | 
| 25 | 
            -
              }
         | 
| 26 | 
            -
             | 
| 27 | 
            -
              describe 'with no elements' do
         | 
| 28 | 
            -
                let(:elements) { [] }
         | 
| 29 | 
            -
             | 
| 30 | 
            -
                specify { expect(specification.match('foo/bar')).to be_nil }
         | 
| 31 | 
            -
              end
         | 
| 32 | 
            -
             | 
| 33 | 
            -
              describe 'with one nonmatching element' do
         | 
| 34 | 
            -
                let(:elements) { ['foo/bar'] }
         | 
| 35 | 
            -
             | 
| 36 | 
            -
                specify { expect(specification.match('foo/baz')).to be_nil }
         | 
| 37 | 
            -
              end
         | 
| 38 | 
            -
             | 
| 39 | 
            -
              describe 'with one matching string element' do
         | 
| 40 | 
            -
                let(:elements) { ['FOO/BAR'] }
         | 
| 41 | 
            -
             | 
| 42 | 
            -
                specify { expect(specification.match('foo/bar')).to eq(:FromInflection1) }
         | 
| 43 | 
            -
              end
         | 
| 44 | 
            -
             | 
| 45 | 
            -
              describe 'with one matching symbol element' do
         | 
| 46 | 
            -
                let(:elements) { [:FROMINFLECTION1] }
         | 
| 47 | 
            -
             | 
| 48 | 
            -
                specify { expect(specification.match('foo/bar')).to eq(:FROMINFLECTION1) }
         | 
| 49 | 
            -
              end
         | 
| 50 | 
            -
             | 
| 51 | 
            -
              describe 'with two string elements, the second of which is matching' do
         | 
| 52 | 
            -
                let(:elements) { %w(foo/bar baz/qux) }
         | 
| 53 | 
            -
             | 
| 54 | 
            -
                specify { expect(specification.match('baz/qux')).to eq(:FromInflection1) }
         | 
| 55 | 
            -
              end
         | 
| 56 | 
            -
             | 
| 57 | 
            -
              describe 'with two symbol elements, the second of which is matching' do
         | 
| 58 | 
            -
                let(:elements) { %i(Foo FromInflection2) }
         | 
| 59 | 
            -
             | 
| 60 | 
            -
                specify { expect(specification.match('baz/qux')).to eq(:FromInflection2) }
         | 
| 61 | 
            -
              end
         | 
| 62 | 
            -
             | 
| 63 | 
            -
              describe 'with a nonmatching hash element' do
         | 
| 64 | 
            -
                let(:elements) { [{Foo: 'bar/baz'}] }
         | 
| 65 | 
            -
             | 
| 66 | 
            -
                specify { expect(specification.match('bar/qux')).to be_nil }
         | 
| 67 | 
            -
              end
         | 
| 68 | 
            -
             | 
| 69 | 
            -
              describe 'with a hash element in which a key matches' do
         | 
| 70 | 
            -
                let(:elements) { [{FromInflection1: 'bar/baz'}] }
         | 
| 71 | 
            -
             | 
| 72 | 
            -
                specify { expect(specification.match('foo')).to eq('bar/baz') }
         | 
| 73 | 
            -
              end
         | 
| 74 | 
            -
             | 
| 75 | 
            -
              describe 'with a hash element in which a value matches' do
         | 
| 76 | 
            -
                let(:elements) { [{Foo: 'bar/baz'}] }
         | 
| 77 | 
            -
             | 
| 78 | 
            -
                specify { expect(specification.match('bar/baz')).to eq(:Foo) }
         | 
| 79 | 
            -
              end
         | 
| 80 | 
            -
             | 
| 81 | 
            -
              describe 'with a hash element in which an array key has a match' do
         | 
| 82 | 
            -
                let(:elements) { [{%i(Foo FromInflection2) => 'bar/baz'}] }
         | 
| 83 | 
            -
             | 
| 84 | 
            -
                specify { expect(specification.match('qux')).to eq('bar/baz') }
         | 
| 85 | 
            -
              end
         | 
| 86 | 
            -
             | 
| 87 | 
            -
              describe 'with a hash element in which a an array value has a match' do
         | 
| 88 | 
            -
                let(:elements) { [{Foo: %w(bar/baz qux/quux)}] }
         | 
| 89 | 
            -
             | 
| 90 | 
            -
                specify { expect(specification.match('qux/quux')).to eq(:Foo) }
         | 
| 91 | 
            -
              end
         | 
| 92 | 
            -
             | 
| 93 | 
            -
              describe 'with a nonmatching string and a hash element in which an array key has a match' do
         | 
| 94 | 
            -
                let(:elements) { ['foo', {%i(Bar FromInflection2) => 'baz/qux'}] }
         | 
| 95 | 
            -
             | 
| 96 | 
            -
                specify { expect(specification.match('quux')).to eq('baz/qux') }
         | 
| 97 | 
            -
              end
         | 
| 98 | 
            -
            end
         | 
| @@ -1,191 +0,0 @@ | |
| 1 | 
            -
            RSpec.describe Autoloaded::Specifications do
         | 
| 2 | 
            -
              subject(:specifications) { specifications_class.new }
         | 
| 3 | 
            -
             | 
| 4 | 
            -
              let(:specifications_class) { described_class }
         | 
| 5 | 
            -
             | 
| 6 | 
            -
              describe 'empty' do
         | 
| 7 | 
            -
                describe '#except' do
         | 
| 8 | 
            -
                  subject(:except) { specifications.except }
         | 
| 9 | 
            -
             | 
| 10 | 
            -
                  specify { is_expected.to be_empty }
         | 
| 11 | 
            -
                end
         | 
| 12 | 
            -
             | 
| 13 | 
            -
                describe '#only' do
         | 
| 14 | 
            -
                  subject(:only) { specifications.only }
         | 
| 15 | 
            -
             | 
| 16 | 
            -
                  specify { is_expected.to be_empty }
         | 
| 17 | 
            -
                end
         | 
| 18 | 
            -
             | 
| 19 | 
            -
                describe '#with' do
         | 
| 20 | 
            -
                  subject(:with) { specifications.with }
         | 
| 21 | 
            -
             | 
| 22 | 
            -
                  specify { is_expected.to be_empty }
         | 
| 23 | 
            -
                end
         | 
| 24 | 
            -
             | 
| 25 | 
            -
                describe '#validate! :except' do
         | 
| 26 | 
            -
                  specify { expect { specifications.validate! :except }.not_to raise_error }
         | 
| 27 | 
            -
                end
         | 
| 28 | 
            -
             | 
| 29 | 
            -
                describe '#validate! :only' do
         | 
| 30 | 
            -
                  specify { expect { specifications.validate! :only }.not_to raise_error }
         | 
| 31 | 
            -
                end
         | 
| 32 | 
            -
             | 
| 33 | 
            -
                describe '#validate! :with' do
         | 
| 34 | 
            -
                  specify { expect { specifications.validate! :with }.not_to raise_error }
         | 
| 35 | 
            -
                end
         | 
| 36 | 
            -
              end
         | 
| 37 | 
            -
             | 
| 38 | 
            -
              describe 'with #except' do
         | 
| 39 | 
            -
                before :each do
         | 
| 40 | 
            -
                  specifications.except << :foo
         | 
| 41 | 
            -
                end
         | 
| 42 | 
            -
             | 
| 43 | 
            -
                describe '#except' do
         | 
| 44 | 
            -
                  subject(:except) { specifications.except }
         | 
| 45 | 
            -
             | 
| 46 | 
            -
                  specify { is_expected.to contain_exactly(:foo) }
         | 
| 47 | 
            -
                end
         | 
| 48 | 
            -
             | 
| 49 | 
            -
                describe '#only' do
         | 
| 50 | 
            -
                  subject(:only) { specifications.only }
         | 
| 51 | 
            -
             | 
| 52 | 
            -
                  specify { is_expected.to be_empty }
         | 
| 53 | 
            -
                end
         | 
| 54 | 
            -
             | 
| 55 | 
            -
                describe '#with' do
         | 
| 56 | 
            -
                  subject(:with) { specifications.with }
         | 
| 57 | 
            -
             | 
| 58 | 
            -
                  specify { is_expected.to be_empty }
         | 
| 59 | 
            -
                end
         | 
| 60 | 
            -
             | 
| 61 | 
            -
                describe '#validate! :except' do
         | 
| 62 | 
            -
                  specify { expect { specifications.validate! :except }.not_to raise_error }
         | 
| 63 | 
            -
                end
         | 
| 64 | 
            -
             | 
| 65 | 
            -
                describe '#validate! :only' do
         | 
| 66 | 
            -
                  specify { expect { specifications.validate! :only }.not_to raise_error }
         | 
| 67 | 
            -
                end
         | 
| 68 | 
            -
             | 
| 69 | 
            -
                describe '#validate! :with' do
         | 
| 70 | 
            -
                  specify { expect { specifications.validate! :with }.not_to raise_error }
         | 
| 71 | 
            -
                end
         | 
| 72 | 
            -
             | 
| 73 | 
            -
                describe 'and #only' do
         | 
| 74 | 
            -
                  before :each do
         | 
| 75 | 
            -
                    specifications.only << :bar
         | 
| 76 | 
            -
                  end
         | 
| 77 | 
            -
             | 
| 78 | 
            -
                  describe '#except' do
         | 
| 79 | 
            -
                    subject(:except) { specifications.except }
         | 
| 80 | 
            -
             | 
| 81 | 
            -
                    specify { is_expected.to contain_exactly(:foo) }
         | 
| 82 | 
            -
                  end
         | 
| 83 | 
            -
             | 
| 84 | 
            -
                  describe '#only' do
         | 
| 85 | 
            -
                    subject(:only) { specifications.only }
         | 
| 86 | 
            -
             | 
| 87 | 
            -
                    specify { is_expected.to contain_exactly(:bar) }
         | 
| 88 | 
            -
                  end
         | 
| 89 | 
            -
             | 
| 90 | 
            -
                  describe '#with' do
         | 
| 91 | 
            -
                    subject(:with) { specifications.with }
         | 
| 92 | 
            -
             | 
| 93 | 
            -
                    specify { is_expected.to be_empty }
         | 
| 94 | 
            -
                  end
         | 
| 95 | 
            -
             | 
| 96 | 
            -
                  describe '#validate! :except' do
         | 
| 97 | 
            -
                    specify {
         | 
| 98 | 
            -
                      expect {
         | 
| 99 | 
            -
                        specifications.validate! :except
         | 
| 100 | 
            -
                      }.to raise_error(RuntimeError,
         | 
| 101 | 
            -
                                       "can't specify `except' when `only' is already specified")
         | 
| 102 | 
            -
                    }
         | 
| 103 | 
            -
                  end
         | 
| 104 | 
            -
             | 
| 105 | 
            -
                  describe '#validate! :only' do
         | 
| 106 | 
            -
                    specify {
         | 
| 107 | 
            -
                      expect {
         | 
| 108 | 
            -
                        specifications.validate! :only
         | 
| 109 | 
            -
                      }.to raise_error(RuntimeError,
         | 
| 110 | 
            -
                                       "can't specify `only' when `except' is already specified")
         | 
| 111 | 
            -
                    }
         | 
| 112 | 
            -
                  end
         | 
| 113 | 
            -
             | 
| 114 | 
            -
                  describe '#validate! :with' do
         | 
| 115 | 
            -
                    specify { expect { specifications.validate! :with }.not_to raise_error }
         | 
| 116 | 
            -
                  end
         | 
| 117 | 
            -
                end
         | 
| 118 | 
            -
              end
         | 
| 119 | 
            -
             | 
| 120 | 
            -
              describe 'with #only' do
         | 
| 121 | 
            -
                before :each do
         | 
| 122 | 
            -
                  specifications.only << :foo
         | 
| 123 | 
            -
                end
         | 
| 124 | 
            -
             | 
| 125 | 
            -
                describe '#except' do
         | 
| 126 | 
            -
                  subject(:except) { specifications.except }
         | 
| 127 | 
            -
             | 
| 128 | 
            -
                  specify { is_expected.to be_empty }
         | 
| 129 | 
            -
                end
         | 
| 130 | 
            -
             | 
| 131 | 
            -
                describe '#only' do
         | 
| 132 | 
            -
                  subject(:only) { specifications.only }
         | 
| 133 | 
            -
             | 
| 134 | 
            -
                  specify { is_expected.to contain_exactly(:foo) }
         | 
| 135 | 
            -
                end
         | 
| 136 | 
            -
             | 
| 137 | 
            -
                describe '#with' do
         | 
| 138 | 
            -
                  subject(:with) { specifications.with }
         | 
| 139 | 
            -
             | 
| 140 | 
            -
                  specify { is_expected.to be_empty }
         | 
| 141 | 
            -
                end
         | 
| 142 | 
            -
             | 
| 143 | 
            -
                describe '#validate! :except' do
         | 
| 144 | 
            -
                  specify { expect { specifications.validate! :except }.not_to raise_error }
         | 
| 145 | 
            -
                end
         | 
| 146 | 
            -
             | 
| 147 | 
            -
                describe '#validate! :only' do
         | 
| 148 | 
            -
                  specify { expect { specifications.validate! :only }.not_to raise_error }
         | 
| 149 | 
            -
                end
         | 
| 150 | 
            -
             | 
| 151 | 
            -
                describe '#validate! :with' do
         | 
| 152 | 
            -
                  specify { expect { specifications.validate! :with }.not_to raise_error }
         | 
| 153 | 
            -
                end
         | 
| 154 | 
            -
              end
         | 
| 155 | 
            -
             | 
| 156 | 
            -
              describe 'with #with' do
         | 
| 157 | 
            -
                before :each do
         | 
| 158 | 
            -
                  specifications.with << :foo
         | 
| 159 | 
            -
                end
         | 
| 160 | 
            -
             | 
| 161 | 
            -
                describe '#except' do
         | 
| 162 | 
            -
                  subject(:except) { specifications.except }
         | 
| 163 | 
            -
             | 
| 164 | 
            -
                  specify { is_expected.to be_empty }
         | 
| 165 | 
            -
                end
         | 
| 166 | 
            -
             | 
| 167 | 
            -
                describe '#only' do
         | 
| 168 | 
            -
                  subject(:only) { specifications.only }
         | 
| 169 | 
            -
             | 
| 170 | 
            -
                  specify { is_expected.to be_empty }
         | 
| 171 | 
            -
                end
         | 
| 172 | 
            -
             | 
| 173 | 
            -
                describe '#with' do
         | 
| 174 | 
            -
                  subject(:with) { specifications.with }
         | 
| 175 | 
            -
             | 
| 176 | 
            -
                  specify { is_expected.to contain_exactly(:foo) }
         | 
| 177 | 
            -
                end
         | 
| 178 | 
            -
             | 
| 179 | 
            -
                describe '#validate! :except' do
         | 
| 180 | 
            -
                  specify { expect { specifications.validate! :except }.not_to raise_error }
         | 
| 181 | 
            -
                end
         | 
| 182 | 
            -
             | 
| 183 | 
            -
                describe '#validate! :only' do
         | 
| 184 | 
            -
                  specify { expect { specifications.validate! :only }.not_to raise_error }
         | 
| 185 | 
            -
                end
         | 
| 186 | 
            -
             | 
| 187 | 
            -
                describe '#validate! :with' do
         | 
| 188 | 
            -
                  specify { expect { specifications.validate! :with }.not_to raise_error }
         | 
| 189 | 
            -
                end
         | 
| 190 | 
            -
              end
         | 
| 191 | 
            -
            end
         | 
| @@ -1,115 +0,0 @@ | |
| 1 | 
            -
            require 'stringio'
         | 
| 2 | 
            -
             | 
| 3 | 
            -
            RSpec.describe Autoloaded::Warning do
         | 
| 4 | 
            -
              before :each do
         | 
| 5 | 
            -
                warning_module.io = io
         | 
| 6 | 
            -
              end
         | 
| 7 | 
            -
             | 
| 8 | 
            -
              let(:warning_module) { described_class }
         | 
| 9 | 
            -
             | 
| 10 | 
            -
              let(:io) { StringIO.new }
         | 
| 11 | 
            -
             | 
| 12 | 
            -
              describe '.enable' do
         | 
| 13 | 
            -
                describe 'simple form' do
         | 
| 14 | 
            -
                  describe 'with nil argument' do
         | 
| 15 | 
            -
                    specify('sets .enabled? as expected') {
         | 
| 16 | 
            -
                      warning_module.enable nil
         | 
| 17 | 
            -
                      expect(warning_module.enabled?).to eq(false)
         | 
| 18 | 
            -
                    }
         | 
| 19 | 
            -
                  end
         | 
| 20 | 
            -
             | 
| 21 | 
            -
                  describe 'with false argument' do
         | 
| 22 | 
            -
                    specify('sets .enabled? as expected') {
         | 
| 23 | 
            -
                      warning_module.enable false
         | 
| 24 | 
            -
                      expect(warning_module.enabled?).to eq(false)
         | 
| 25 | 
            -
                    }
         | 
| 26 | 
            -
                  end
         | 
| 27 | 
            -
             | 
| 28 | 
            -
                  describe 'with string argument' do
         | 
| 29 | 
            -
                    specify('sets .enabled? as expected') {
         | 
| 30 | 
            -
                      warning_module.enable 'foo'
         | 
| 31 | 
            -
                      expect(warning_module.enabled?).to eq(true)
         | 
| 32 | 
            -
                    }
         | 
| 33 | 
            -
                  end
         | 
| 34 | 
            -
             | 
| 35 | 
            -
                  describe 'with true argument' do
         | 
| 36 | 
            -
                    specify('sets .enabled? as expected') {
         | 
| 37 | 
            -
                      warning_module.enable true
         | 
| 38 | 
            -
                      expect(warning_module.enabled?).to eq(true)
         | 
| 39 | 
            -
                    }
         | 
| 40 | 
            -
                  end
         | 
| 41 | 
            -
             | 
| 42 | 
            -
                  specify("returns #{Autoloaded::Warning.name}") {
         | 
| 43 | 
            -
                    expect(warning_module.enable('foo')).to eq(warning_module)
         | 
| 44 | 
            -
                  }
         | 
| 45 | 
            -
                end
         | 
| 46 | 
            -
             | 
| 47 | 
            -
                describe 'block form' do
         | 
| 48 | 
            -
                  specify('returns the result of the block') {
         | 
| 49 | 
            -
                    result = warning_module.enable('foo') do
         | 
| 50 | 
            -
                      :block_result
         | 
| 51 | 
            -
                    end
         | 
| 52 | 
            -
                    expect(result).to eq(:block_result)
         | 
| 53 | 
            -
                  }
         | 
| 54 | 
            -
             | 
| 55 | 
            -
                  describe 'if the block returns' do
         | 
| 56 | 
            -
                    specify('resets .enabled?') {
         | 
| 57 | 
            -
                      expect {
         | 
| 58 | 
            -
                        warning_module.enable(false) { }
         | 
| 59 | 
            -
                      }.not_to change { warning_module.enabled? }
         | 
| 60 | 
            -
                      expect {
         | 
| 61 | 
            -
                        warning_module.enable(true) { }
         | 
| 62 | 
            -
                      }.not_to change { warning_module.enabled? }
         | 
| 63 | 
            -
                    }
         | 
| 64 | 
            -
                  end
         | 
| 65 | 
            -
             | 
| 66 | 
            -
                  describe 'if the block raises an error' do
         | 
| 67 | 
            -
                    specify('resets .enabled?') {
         | 
| 68 | 
            -
                      expect {
         | 
| 69 | 
            -
                        begin
         | 
| 70 | 
            -
                          warning_module.enable(false) do
         | 
| 71 | 
            -
                            1 / 0
         | 
| 72 | 
            -
                          end
         | 
| 73 | 
            -
                        rescue ZeroDivisionError
         | 
| 74 | 
            -
                        end
         | 
| 75 | 
            -
                      }.not_to change { warning_module.enabled? }
         | 
| 76 | 
            -
                      expect {
         | 
| 77 | 
            -
                        begin
         | 
| 78 | 
            -
                          warning_module.enable(true) do
         | 
| 79 | 
            -
                            1 / 0
         | 
| 80 | 
            -
                          end
         | 
| 81 | 
            -
                        rescue ZeroDivisionError
         | 
| 82 | 
            -
                        end
         | 
| 83 | 
            -
                      }.not_to change { warning_module.enabled? }
         | 
| 84 | 
            -
                    }
         | 
| 85 | 
            -
                  end
         | 
| 86 | 
            -
                end
         | 
| 87 | 
            -
              end
         | 
| 88 | 
            -
             | 
| 89 | 
            -
              describe '.changing_autoload' do
         | 
| 90 | 
            -
                before :each do
         | 
| 91 | 
            -
                  warning_module.enable true
         | 
| 92 | 
            -
                  warning_module.changing_autoload constant_name:        :Foo,
         | 
| 93 | 
            -
                                                   old_source_filename:  'bar',
         | 
| 94 | 
            -
                                                   new_source_filename:  'baz',
         | 
| 95 | 
            -
                                                   host_source_location: 'qux.rb:123'
         | 
| 96 | 
            -
                end
         | 
| 97 | 
            -
             | 
| 98 | 
            -
                specify('writes the expected message to .io') {
         | 
| 99 | 
            -
                  expect(io.string).to eq(%Q(\e[33m*** \e[7m WARNING \e[0m Existing autoload of \e[4mFoo\e[0m from "bar" is being overridden to autoload from "baz" -- avoid this warning by using an \e[4monly\e[0m or an \e[4mexcept\e[0m specification in the block at qux.rb:123\n))
         | 
| 100 | 
            -
                }
         | 
| 101 | 
            -
              end
         | 
| 102 | 
            -
             | 
| 103 | 
            -
              describe '.existing_constant' do
         | 
| 104 | 
            -
                before :each do
         | 
| 105 | 
            -
                  warning_module.enable true
         | 
| 106 | 
            -
                  warning_module.existing_constant constant_name:        :Foo,
         | 
| 107 | 
            -
                                                   source_filename:      'bar',
         | 
| 108 | 
            -
                                                   host_source_location: 'baz.rb:123'
         | 
| 109 | 
            -
                end
         | 
| 110 | 
            -
             | 
| 111 | 
            -
                specify('writes the expected message to .io') {
         | 
| 112 | 
            -
                  expect(io.string).to eq(%Q(\e[33m*** \e[7m WARNING \e[0m Existing definition of \e[4mFoo\e[0m obviates autoloading from "bar" -- avoid this warning by using an \e[4monly\e[0m or an \e[4mexcept\e[0m specification in the block at baz.rb:123\n))
         | 
| 113 | 
            -
                }
         | 
| 114 | 
            -
              end
         | 
| 115 | 
            -
            end
         | 
| @@ -1,24 +0,0 @@ | |
| 1 | 
            -
            RSpec.shared_examples_for "an #{Autoloaded.name} macro" do |macro|
         | 
| 2 | 
            -
              before :each do
         | 
| 3 | 
            -
                allow(autoloader_class).to receive(:new).and_return(autoloader)
         | 
| 4 | 
            -
                allow_any_instance_of(autoloader_class).to receive(:autoload!)
         | 
| 5 | 
            -
              end
         | 
| 6 | 
            -
             | 
| 7 | 
            -
              let(:autoloaded_module) { Autoloaded }
         | 
| 8 | 
            -
             | 
| 9 | 
            -
              let(:autoloader) { autoloader_class.new binding }
         | 
| 10 | 
            -
             | 
| 11 | 
            -
              let(:autoloader_class) { autoloaded_module::Autoloader }
         | 
| 12 | 
            -
             | 
| 13 | 
            -
              specify("yields an #{Autoloaded::Autoloader.name}") {
         | 
| 14 | 
            -
                autoloaded_module.send macro do |autoloaded|
         | 
| 15 | 
            -
                  expect(autoloaded).to equal(autoloader)
         | 
| 16 | 
            -
                end
         | 
| 17 | 
            -
              }
         | 
| 18 | 
            -
             | 
| 19 | 
            -
              specify("calls #{Autoloaded::Autoloader.name}#autoload!") {
         | 
| 20 | 
            -
                expect(autoloader).to receive(:autoload!)
         | 
| 21 | 
            -
                autoloaded_module.send macro do |autoloaded|
         | 
| 22 | 
            -
                end
         | 
| 23 | 
            -
              }
         | 
| 24 | 
            -
            end
         |