require_relative 'spec_helper' require 'minitest/stub_const' require 'wright/util' describe Wright::Util do def stub_os(target_os) RbConfig.stub_const(:CONFIG, 'target_os' => target_os) do yield end end def without_bundler if defined?(Bundler) Object.stub_remove_const(:Bundler) { yield } else yield end end def with_bundler if defined?(Bundler) yield else fake_bundler = Class.new def fake_bundler.with_clean_env; end Object.stub_const(:Bundler, fake_bundler) { yield } end end describe 'filename_to_classname' do it 'should convert filenames to class names' do classname = Wright::Util.filename_to_classname('foo_bar/baz') classname.must_equal 'FooBar::Baz' end end describe 'class_to_resource_name' do it 'should convert classes to resource names' do resource_name = Wright::Util.class_to_resource_name(Object) resource_name.must_equal 'object' end end describe 'os_family' do before(:each) do @debian_os_release = < { mock.with_clean_env } mock.expect(:with_clean_env, []) mock.expect(:inside_block, []) with_bundler do Bundler.stub(:with_clean_env, with_clean_env_stub) do Wright::Util.bundler_clean_env { mock.inside_block } end end mock.verify end end end