require "#{File.expand_path(File.dirname(__FILE__))}/helper" require 'crystal/environment' require 'crystal/spec/environment' describe "Environment basic spec" do inject :env => :environment before :all do @dir = File.expand_path(File.dirname(__FILE__)) $APP_DIR = "#{@dir}/environment_spec/app" @app_plugin_dir = "#{@dir}/environment_spec/app/app_plugin" @gem_plugin_dir = "#{@dir}/environment_spec/gem_plugin" $LOAD_PATH << @app_plugin_dir $LOAD_PATH << @gem_plugin_dir Crystal::Config::DEFAULTS['environment'] = 'test' end after :all do $LOAD_PATH.delete @app_plugin_dir $LOAD_PATH.delete @gem_plugin_dir $APP_DIR = nil end describe 'files' do with_environment :test it "find_files?" do env.file_exist?('/config/ec_layout').should be_true env.file_exist?('/ec_some_file').should be_true end it "find_file" do lambda{env.find_file('/config/ec_layout')}.should raise_error(/Found multiple files/) env.find_file('/ec_some_file').should == "#{@app_plugin_dir}/ec_some_file" lambda{env.find_file('ec_some_file')}.should raise_error(AssertionError) end it "find_files" do env.find_files('/config/ec_layout').sort.should == ["#{@app_plugin_dir}/config/ec_layout", "#{@gem_plugin_dir}/config/ec_layout"] end it "find_files_by_pattern" do env.find_files_by_pattern('/*/ec_layout').sort.should == ["#{@app_plugin_dir}/config/ec_layout", "#{@gem_plugin_dir}/config/ec_layout"] end end describe 'config' do with_environment :test it "should merge 'APP_DIR/config/config.yml' into config" do config.key?.should be_true config.key!.should == 'value' end it "should merge 'APP_DIR/config/config.environment.yml' into config" do config.key2?.should be_true config.key2!.should == 'value2test' end end describe "spec should be isolated (via swap_metadata)" do describe "first spec" do with_environment before :all do crystal.register(:spec_component) end it "check" do Micon.metadata.should include(:spec_component) end end describe "second spec" do it "check" do Micon.metadata.should_not include(:spec_component) end end end end