spec/cli_spec.rb in socialcast-1.1.0 vs spec/cli_spec.rb in socialcast-1.1.1

- old
+ new

@@ -1,14 +1,13 @@ require 'spec_helper' describe Socialcast::CLI do describe '#share' do - # Expects -u=emily@socialcast.com -p=demo --domain=demo.socialcast.com context 'with a basic message' do before do - File.stub(:open).with(/credentials.yml/).and_yield(File.read(File.join(File.dirname(__FILE__), 'fixtures', 'credentials.yml'))) + Socialcast.stub(:credentials).and_return(YAML.load_file(File.join(File.dirname(__FILE__), 'fixtures', 'credentials.yml'))) stub_request(:post, "https://ryan%40socialcast.com:foo@test.staging.socialcast.com/api/messages.json"). with(:body => /message\_type\"\:null/). with(:body => /testing/). to_return(:status => 200, :body => "", :headers => {}) @@ -19,11 +18,11 @@ end end context 'with a message_type message' do before do - File.stub(:open).with(/credentials.yml/).and_yield(File.read(File.join(File.dirname(__FILE__), 'fixtures', 'credentials.yml'))) + Socialcast.stub(:credentials).and_return(YAML.load_file(File.join(File.dirname(__FILE__), 'fixtures', 'credentials.yml'))) stub_request(:post, "https://ryan%40socialcast.com:foo@test.staging.socialcast.com/api/messages.json"). with(:body => /message\_type\"\:review\_request/). with(:body => /please\sreview/). to_return(:status => 200, :body => "", :headers => {}) @@ -31,25 +30,38 @@ end it 'should send a POST with a message body of "please review" and message_type of "review_request"' do # See expectations end end + context "with a proxy" do + before do + Socialcast.stub(:credentials).and_return(YAML.load_file(File.join(File.dirname(__FILE__), 'fixtures', 'credentials_with_proxy.yml'))) + stub_request(:post, "https://ryan%40socialcast.com:foo@test.staging.socialcast.com/api/messages.json"). + with(:body => /message\_type\"\:null/). + with(:body => /testing/). + to_return(:status => 200, :body => "", :headers => {}) + + Socialcast::CLI.start ['share', 'testing'] + end + it 'should send a POST with a message body of "testing" and nil message-type' do + # See expectations + end + end end describe '#provision' do 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'))) File.should_receive(:exists?).with('/my/path/to/ldap.yml').and_return(true) File.stub(:open).with(/users.xml.gz/, anything).and_yield(@result) - File.stub(:open).with(/credentials.yml/).and_yield(File.read(File.join(File.dirname(__FILE__), 'fixtures', 'credentials.yml'))) RestClient::Resource.any_instance.should_not_receive(:post) Kernel.should_receive(:abort).once Socialcast::CLI.start ['provision', '-c', '/my/path/to/ldap.yml'] @@ -60,15 +72,14 @@ 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'))) File.should_receive(:exists?).with('/my/path/to/ldap.yml').and_return(true) File.stub(:open).with(/users.xml.gz/, anything).and_yield(@result) - File.stub(:open).with(/credentials.yml/).and_yield(File.read(File.join(File.dirname(__FILE__), 'fixtures', 'credentials.yml'))) RestClient::Resource.any_instance.should_receive(:post).once Kernel.should_not_receive(:abort) Socialcast::CLI.start ['provision', '-c', '/my/path/to/ldap.yml', '-f'] @@ -81,15 +92,14 @@ @entry[:mail] = 'ryan@example.com' 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'))) File.should_receive(:exists?).with('/my/path/to/ldap.yml').and_return(true) File.stub(:open).with(/users.xml.gz/, anything).and_yield(@result) - File.stub(:open).with(/credentials.yml/).and_yield(File.read(File.join(File.dirname(__FILE__), 'fixtures', 'credentials.yml'))) RestClient::Resource.any_instance.stub(:post) Socialcast::CLI.start ['provision', '-c', '/my/path/to/ldap.yml'] end it 'resolves absolute path without using current process directory' do end # see expectations @@ -101,13 +111,13 @@ 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'))) File.stub(:open).with(/users.xml.gz/, anything).and_yield(@result) - File.stub(:open).with(/credentials.yml/).and_yield(File.read(File.join(File.dirname(__FILE__), 'fixtures', 'credentials.yml'))) RestClient::Resource.any_instance.stub(:post) Socialcast::CLI.start ['provision', '-c', 'spec/fixtures/ldap.yml'] end @@ -123,13 +133,13 @@ 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'))) File.stub(:open).with(/users.xml.gz/, anything).and_yield(@result) - File.stub(:open).with(/credentials.yml/).and_yield(File.read(File.join(File.dirname(__FILE__), 'fixtures', 'credentials.yml'))) RestClient::Resource.any_instance.stub(:post) Socialcast::CLI.start ['provision', '-c', 'spec/fixtures/ldap.yml'] end @@ -145,13 +155,13 @@ 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'))) File.stub(:open).with(/users.xml.gz/, anything).and_yield(@result) - File.stub(:open).with(/credentials.yml/).and_yield(File.read(File.join(File.dirname(__FILE__), 'fixtures', 'credentials.yml'))) RestClient::Resource.any_instance.stub(:post) Socialcast::CLI.start ['provision', '-c', 'spec/fixtures/ldap.yml'] end @@ -168,13 +178,13 @@ 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'))) File.stub(:open).with(/users.xml.gz/, anything).and_yield(@result) - File.stub(:open).with(/credentials.yml/).and_yield(File.read(File.join(File.dirname(__FILE__), 'fixtures', 'credentials.yml'))) RestClient::Resource.any_instance.stub(:post) Socialcast::CLI.start ['provision', '-c', 'spec/fixtures/ldap.yml'] end @@ -193,13 +203,13 @@ 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'))) File.stub(:open).with(/users.xml.gz/, anything).and_yield(@result) - File.stub(:open).with(/credentials.yml/).and_yield(File.read(File.join(File.dirname(__FILE__), 'fixtures', 'credentials.yml'))) RestClient::Resource.any_instance.stub(:post) Socialcast::CLI.start ['provision', '-c', 'spec/fixtures/ldap.yml'] end @@ -218,13 +228,13 @@ 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'))) File.stub(:open).with(/users.xml.gz/, anything).and_yield(@result) - File.stub(:open).with(/credentials.yml/).and_yield(File.read(File.join(File.dirname(__FILE__), 'fixtures', 'credentials.yml'))) RestClient::Resource.any_instance.stub(:post) Socialcast::CLI.start ['provision', '-c', 'spec/fixtures/ldap.yml'] end @@ -245,12 +255,12 @@ 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'))) File.stub(:open).with(/users.xml.gz/, anything).and_yield(@result) - File.stub(:open).with(/credentials.yml/).and_yield(File.read(File.join(File.dirname(__FILE__), 'fixtures', 'credentials.yml'))) RestClient::Resource.any_instance.stub(:post) Socialcast::CLI.start ['provision', '-c', 'spec/fixtures/ldap.yml'] end