spec/cli_spec.rb in socialcast-1.1.2 vs spec/cli_spec.rb in socialcast-1.1.3

- old
+ new

@@ -61,18 +61,23 @@ end end describe '#provision' do + before do + Socialcast::CLI.instance_eval do # to supress warning from stubbing load_configuration + @no_tasks = true + end + end context 'with 0 users found in ldap' do before do Net::LDAP.any_instance.stub(:search).and_return(nil) @result = '' Zlib::GzipWriter.stub(:open).and_yield(@result) Socialcast.stub(:credentials).and_return(YAML.load_file(File.join(File.dirname(__FILE__), 'fixtures', 'credentials.yml'))) - File.should_receive(:open).with('/my/path/to/ldap.yml').and_yield(File.read(File.join(File.dirname(__FILE__), 'fixtures', 'ldap_without_permission_mappings.yml'))) + Socialcast::CLI.any_instance.should_receive(:load_configuration).with('/my/path/to/ldap.yml').and_return(YAML.load_file(File.join(File.dirname(__FILE__), 'fixtures', 'ldap_without_permission_mappings.yml'))) File.should_receive(:exists?).with('/my/path/to/ldap.yml').and_return(true) File.stub(:open).with(/users.xml.gz/, anything).and_yield(@result) RestClient::Resource.any_instance.should_not_receive(:post) Kernel.should_receive(:abort).once @@ -86,12 +91,13 @@ Net::LDAP.any_instance.stub(:search).and_return(nil) @result = '' Zlib::GzipWriter.stub(:open).and_yield(@result) Socialcast.stub(:credentials).and_return(YAML.load_file(File.join(File.dirname(__FILE__), 'fixtures', 'credentials.yml'))) - File.should_receive(:open).with('/my/path/to/ldap.yml').and_yield(File.read(File.join(File.dirname(__FILE__), 'fixtures', 'ldap_without_permission_mappings.yml'))) + Socialcast::CLI.any_instance.should_receive(:load_configuration).with('/my/path/to/ldap.yml').and_return(YAML.load_file(File.join(File.dirname(__FILE__), 'fixtures', 'ldap_without_permission_mappings.yml'))) File.should_receive(:exists?).with('/my/path/to/ldap.yml').and_return(true) + File.stub(:open).with(/users.xml.gz/, anything).and_yield(@result) RestClient::Resource.any_instance.should_receive(:post).once Kernel.should_not_receive(:abort) @@ -106,11 +112,11 @@ Net::LDAP.any_instance.stub(:search).and_yield(@entry) @result = '' Zlib::GzipWriter.stub(:open).and_yield(@result) Socialcast.stub(:credentials).and_return(YAML.load_file(File.join(File.dirname(__FILE__), 'fixtures', 'credentials.yml'))) - File.should_receive(:open).with('/my/path/to/ldap.yml').and_yield(File.read(File.join(File.dirname(__FILE__), 'fixtures', 'ldap_without_permission_mappings.yml'))) + Socialcast::CLI.any_instance.should_receive(:load_configuration).with('/my/path/to/ldap.yml').and_return(YAML.load_file(File.join(File.dirname(__FILE__), 'fixtures', 'ldap_without_permission_mappings.yml'))) File.should_receive(:exists?).with('/my/path/to/ldap.yml').and_return(true) File.stub(:open).with(/users.xml.gz/, anything).and_yield(@result) RestClient::Resource.any_instance.stub(:post) Socialcast::CLI.start ['provision', '-c', '/my/path/to/ldap.yml'] @@ -125,11 +131,11 @@ Net::LDAP.any_instance.stub(:search).and_yield(@entry) @result = '' Zlib::GzipWriter.stub(:open).and_yield(@result) Socialcast.stub(:credentials).and_return(YAML.load_file(File.join(File.dirname(__FILE__), 'fixtures', 'credentials.yml'))) - File.stub(:open).with(/ldap.yml/).and_yield(File.read(File.join(File.dirname(__FILE__), 'fixtures', 'ldap_without_permission_mappings.yml'))) + Socialcast::CLI.any_instance.should_receive(:load_configuration).with(/ldap\.yml/).and_return(YAML.load_file(File.join(File.dirname(__FILE__), 'fixtures', 'ldap_without_permission_mappings.yml'))) File.stub(:open).with(/users.xml.gz/, anything).and_yield(@result) RestClient::Resource.any_instance.stub(:post) Socialcast::CLI.start ['provision', '-c', 'spec/fixtures/ldap.yml'] @@ -147,11 +153,11 @@ Net::LDAP.any_instance.stub(:search).and_yield(@entry) @result = '' Zlib::GzipWriter.stub(:open).and_yield(@result) Socialcast.stub(:credentials).and_return(YAML.load_file(File.join(File.dirname(__FILE__), 'fixtures', 'credentials.yml'))) - File.stub(:open).with(/ldap.yml/).and_yield(File.read(File.join(File.dirname(__FILE__), 'fixtures', 'ldap.yml'))) + Socialcast::CLI.any_instance.should_receive(:load_configuration).with(/ldap.yml/).and_return(YAML.load_file(File.join(File.dirname(__FILE__), 'fixtures', 'ldap.yml'))) File.stub(:open).with(/users.xml.gz/, anything).and_yield(@result) RestClient::Resource.any_instance.stub(:post) Socialcast::CLI.start ['provision', '-c', 'spec/fixtures/ldap.yml'] @@ -169,11 +175,11 @@ Net::LDAP.any_instance.stub(:search).and_yield(@entry) @result = '' Zlib::GzipWriter.stub(:open).and_yield(@result) Socialcast.stub(:credentials).and_return(YAML.load_file(File.join(File.dirname(__FILE__), 'fixtures', 'credentials.yml'))) - File.stub(:open).with(/ldap.yml/).and_yield(File.read(File.join(File.dirname(__FILE__), 'fixtures', 'ldap_with_array_permission_mapping.yml'))) + Socialcast::CLI.any_instance.should_receive(:load_configuration).with(/ldap.yml/).and_return(YAML.load_file(File.join(File.dirname(__FILE__), 'fixtures', 'ldap_with_array_permission_mapping.yml'))) File.stub(:open).with(/users.xml.gz/, anything).and_yield(@result) RestClient::Resource.any_instance.stub(:post) Socialcast::CLI.start ['provision', '-c', 'spec/fixtures/ldap.yml'] @@ -192,11 +198,11 @@ Net::LDAP.any_instance.stub(:search).and_yield(@entry) @result = '' Zlib::GzipWriter.stub(:open).and_yield(@result) Socialcast.stub(:credentials).and_return(YAML.load_file(File.join(File.dirname(__FILE__), 'fixtures', 'credentials.yml'))) - File.stub(:open).with(/ldap.yml/).and_yield(File.read(File.join(File.dirname(__FILE__), 'fixtures', 'ldap.yml'))) + Socialcast::CLI.any_instance.should_receive(:load_configuration).with(/ldap.yml/).and_return(YAML.load_file(File.join(File.dirname(__FILE__), 'fixtures', 'ldap.yml'))) File.stub(:open).with(/users.xml.gz/, anything).and_yield(@result) RestClient::Resource.any_instance.stub(:post) Socialcast::CLI.start ['provision', '-c', 'spec/fixtures/ldap.yml'] @@ -217,11 +223,11 @@ Net::LDAP.any_instance.stub(:search).and_yield(@entry) @result = '' Zlib::GzipWriter.stub(:open).and_yield(@result) Socialcast.stub(:credentials).and_return(YAML.load_file(File.join(File.dirname(__FILE__), 'fixtures', 'credentials.yml'))) - File.stub(:open).with(/ldap.yml/).and_yield(File.read(File.join(File.dirname(__FILE__), 'fixtures', 'ldap_with_array_permission_mapping.yml'))) + Socialcast::CLI.any_instance.should_receive(:load_configuration).with(/ldap.yml/).and_return(YAML.load_file(File.join(File.dirname(__FILE__), 'fixtures', 'ldap_with_array_permission_mapping.yml'))) File.stub(:open).with(/users.xml.gz/, anything).and_yield(@result) RestClient::Resource.any_instance.stub(:post) Socialcast::CLI.start ['provision', '-c', 'spec/fixtures/ldap.yml'] @@ -242,11 +248,11 @@ Net::LDAP.any_instance.stub(:search).and_yield(@entry) @result = '' Zlib::GzipWriter.stub(:open).and_yield(@result) Socialcast.stub(:credentials).and_return(YAML.load_file(File.join(File.dirname(__FILE__), 'fixtures', 'credentials.yml'))) - File.stub(:open).with(/ldap.yml/).and_yield(File.read(File.join(File.dirname(__FILE__), 'fixtures', 'ldap_with_array_permission_mapping.yml'))) + Socialcast::CLI.any_instance.should_receive(:load_configuration).with(/ldap.yml/).and_return(YAML.load_file(File.join(File.dirname(__FILE__), 'fixtures', 'ldap_with_array_permission_mapping.yml'))) File.stub(:open).with(/users.xml.gz/, anything).and_yield(@result) RestClient::Resource.any_instance.stub(:post) Socialcast::CLI.start ['provision', '-c', 'spec/fixtures/ldap.yml'] @@ -269,10 +275,10 @@ Net::LDAP.any_instance.stub(:search).and_yield(@entry) @result = '' Zlib::GzipWriter.stub(:open).and_yield(@result) Socialcast.stub(:credentials).and_return(YAML.load_file(File.join(File.dirname(__FILE__), 'fixtures', 'credentials.yml'))) - File.stub(:open).with(/ldap.yml/).and_yield(File.read(File.join(File.dirname(__FILE__), 'fixtures', 'ldap_with_interpolated_values.yml'))) + Socialcast::CLI.any_instance.should_receive(:load_configuration).with(/ldap.yml/).and_return(YAML.load_file(File.join(File.dirname(__FILE__), 'fixtures', 'ldap_with_interpolated_values.yml'))) File.stub(:open).with(/users.xml.gz/, anything).and_yield(@result) RestClient::Resource.any_instance.stub(:post) Socialcast::CLI.start ['provision', '-c', 'spec/fixtures/ldap.yml']