This commit is contained in:
Loic Nageleisen 2014-12-10 18:33:15 +01:00
commit 32b99b62bf
20 changed files with 644 additions and 0 deletions

0
spec/fixtures/empty_package.rb vendored Normal file
View file

68
spec/package_spec.rb Normal file
View file

@ -0,0 +1,68 @@
require 'package'
RSpec.describe Package do
context 'instance' do
let(:package) { Package.new('spec/fixtures/empty_package') }
it { expect(package).to be_a Module }
end
end
RSpec.describe 'Kernel#import' do
before(:each) { Package.reload! }
[Module, Object].each do |ctx|
let(:package_name) { 'spec/fixtures/empty_package' }
let(:target) { nil }
let(:pak) do
t = target
n = package_name
context.instance_eval { import(n, to: t) }
end
context "called inside #{ctx.name}.new" do
let(:context) { ctx.new }
it 'should import a package as a value' do
expect(pak).to be_a Package
expect(context).not_to respond_to :empty_package
expect do
context.instance_eval { EmptyPackage }
end.to raise_error NameError
expect do
context.instance_eval { empty_package }
end.to raise_error NameError
end
it 'should import a package as a method' do
pak = nil
context = Module.new do
pak = import('spec/fixtures/empty_package', to: :method)
end
expect(context).to respond_to :empty_package
expect(context.empty_package).to eq pak
end
it 'should import a package as a const' do
pak = nil
context = Module.new do
pak = import('spec/fixtures/empty_package', to: :const)
end
expect(context).to have_constant :EmptyPackage
expect(context::EmptyPackage).to eq pak
end
it 'should import a package as a local' do
pending 'not ready yet'
context = Module.new do
import('spec/fixtures/empty_package', to: :local)
end
expect(context.instance_eval { empty_package }).to be_a Package
end
end
end
end

26
spec/spec_helper.rb Normal file
View file

@ -0,0 +1,26 @@
if ENV['COVERAGE'] == 'yes'
require 'simplecov'
SimpleCov.start
end
require 'support/matchers'
require 'pry'
RSpec.configure do |config|
config.expect_with :rspec do |expectations|
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
end
config.mock_with :rspec do |mocks|
mocks.verify_partial_doubles = true
end
config.disable_monkey_patching!
config.warnings = true
config.default_formatter = 'doc' if config.files_to_run.one?
config.order = :random
Kernel.srand config.seed
end

5
spec/support/matchers.rb Normal file
View file

@ -0,0 +1,5 @@
RSpec::Matchers.define :have_constant do |const|
match do |owner|
owner.const_defined?(const)
end
end