gas 0.1.8 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,83 +0,0 @@
1
- require './spec/spec_helper'
2
-
3
- require './lib/gas'
4
-
5
- describe Gas::Config do
6
-
7
- before :each do
8
- @name = 'Fredrik Wallgren'
9
- @email = 'fredrik.wallgren@gmail.com'
10
- @nickname = 'walle'
11
- config = "[#{@nickname}]\n name = #{@name}\n email = #{@email}\n\n[user2]\n name = foo\n email = bar"
12
- @config = Gas::Config.new nil, config
13
- end
14
-
15
- it 'should be able to parse users from config format' do
16
- @config.users.count.should be 2
17
- @config.users[0].name.should eq @name
18
- @config.users[0].email.should eq @email
19
- @config.users[0].nickname.should eq @nickname
20
- end
21
-
22
- it 'should output the users in the correct format' do
23
- user1 = Gas::User.new 'Fredrik Wallgren', 'fredrik.wallgren@gmail.com', 'walle'
24
- user2 = Gas::User.new 'foo', 'bar', 'user2'
25
- users = [user1, user2]
26
- config = Gas::Config.new users
27
-
28
- stub(config).is_current_user { false }
29
-
30
- config.to_s.should == " [walle]\n name = Fredrik Wallgren\n email = fredrik.wallgren@gmail.com\n [user2]\n name = foo\n email = bar"
31
- end
32
-
33
- it 'should be able to tell if a nickname exists' do
34
- user1 = Gas::User.new 'Fredrik Wallgren', 'fredrik.wallgren@gmail.com', 'walle'
35
- user2 = Gas::User.new 'foo', 'bar', 'user2'
36
- users = [user1, user2]
37
- config = Gas::Config.new users
38
- config.exists?('walle').should be_true
39
- config.exists?('foo').should be_false
40
- config.exists?('user2').should be_true
41
- end
42
-
43
- it 'should be able to get a user from a nickname' do
44
- user1 = Gas::User.new 'Fredrik Wallgren', 'fredrik.wallgren@gmail.com', 'walle'
45
- user2 = Gas::User.new 'foo', 'bar', 'user2'
46
- users = [user1, user2]
47
- config = Gas::Config.new users
48
- config.get('walle').should eq user1
49
- config.get('user2').should eq user2
50
- config['walle'].should eq user1
51
- config['user2'].should eq user2
52
- config[:walle].should eq user1
53
- config[:user2].should eq user2
54
- end
55
-
56
- it 'should be able to add users' do
57
- user1 = Gas::User.new 'Fredrik Wallgren', 'fredrik.wallgren@gmail.com', 'walle'
58
- user2 = Gas::User.new 'foo', 'bar', 'user2'
59
- users = [user1]
60
- config = Gas::Config.new users
61
- config.users.count.should be 1
62
- config.add user2
63
- config.users.count.should be 2
64
- end
65
-
66
- it 'should be able to delete users by nickname' do
67
- user1 = Gas::User.new 'Fredrik Wallgren', 'fredrik.wallgren@gmail.com', 'walle'
68
- user2 = Gas::User.new 'foo', 'bar', 'user2'
69
- users = [user1, user2]
70
- config = Gas::Config.new users
71
- config.users.count.should be 2
72
- config.delete 'walle'
73
- config.users.count.should be 1
74
- config.delete 'user2'
75
- config.users.count.should be 0
76
- end
77
-
78
- it 'should remove the ssh keys from .gas appropriately'
79
-
80
- it 'should remove the keys from .ssh if present'
81
-
82
- end
83
-
@@ -1,85 +0,0 @@
1
- require './spec/spec_helper'
2
-
3
- require './lib/gas'
4
- #require './lib/gas/user'
5
-
6
- describe Gas::Gitconfig do
7
-
8
- before :each do
9
- @name = 'Fredrik Wallgren'
10
- @email = 'fredrik.wallgren@gmail.com'
11
- @nickname = 'Fred'
12
- @gitconfig = Gas::Gitconfig.new
13
- end
14
-
15
- it 'should be able to get current user from gitconfig' do
16
- mock_cli_call(@gitconfig, 'git config --global --get user.name') { @name + "\n" }
17
- mock_cli_call(@gitconfig, 'git config --global --get user.email') { @email + "\n" }
18
-
19
- user = @gitconfig.current_user
20
- user.name.should eq @name
21
- user.email.should eq @email
22
- end
23
-
24
- it 'should return nil if no current user is present in gitconfig' do
25
- mock_cli_call(@gitconfig, 'git config --global --get user.name') { nil }
26
- mock_cli_call(@gitconfig, 'git config --global --get user.email') { nil }
27
-
28
- @gitconfig.current_user.should be_nil
29
- end
30
-
31
-
32
- describe "Multiple users" do
33
-
34
- before :each do
35
- @user1 = Gas::User.new(@name, @email, @nickname) # create a primary user for testing
36
- end
37
-
38
- it "should be able to set the current user" do
39
- # setup the cli interrupt things...
40
- mock_cli_call(@gitconfig, "git config --global user.name \"#{@user1.name}\"") { nil }
41
- mock_cli_call(@gitconfig, "git config --global user.email \"#{@user1.email}\"") { nil }
42
- mock_cli_call(@gitconfig, 'git config --global --get user.name') { @user1.name + "\n" }
43
- mock_cli_call(@gitconfig, 'git config --global --get user.email') { @user1.email + "\n" }
44
-
45
- @gitconfig.change_user @user1
46
-
47
- user = @gitconfig.current_user
48
- user.name.should eq @user1.name
49
- user.email.should eq @user1.email
50
- user.nickname.should eq @user1.nickname
51
- end
52
-
53
- it 'should be able to change the current user' do
54
- name = 'Test Testsson'
55
- email = 'test@testsson.com'
56
- nickname = 'test'
57
-
58
- # User 1 cli interrupt things...
59
- mock_cli_call(@gitconfig, "git config --global user.name \"#{@name}\"") { nil }
60
- mock_cli_call(@gitconfig, "git config --global user.email \"#{@email}\"") { nil }
61
- mock_cli_call(@gitconfig, 'git config --global --get user.name') { @name + "\n" }
62
- mock_cli_call(@gitconfig, 'git config --global --get user.email') { @email + "\n" }
63
-
64
- @gitconfig.change_user @user1
65
-
66
- user = @gitconfig.current_user
67
- user.name.should eq @name
68
- user.email.should eq @email # test that the user switch worked (paranoid, huh?)
69
-
70
- # User 2 cli interrupt things...
71
- mock_cli_call(@gitconfig, "git config --global user.name \"#{name}\"") { nil }
72
- mock_cli_call(@gitconfig, "git config --global user.email \"#{email}\"") { nil }
73
- mock_cli_call(@gitconfig, 'git config --global --get user.name') { name + "\n" }
74
- mock_cli_call(@gitconfig, 'git config --global --get user.email') { email + "\n" }
75
-
76
- @user2 = Gas::User.new(name, email, nickname) # create user 2
77
- @gitconfig.change_user @user2
78
-
79
- user = @gitconfig.current_user
80
- user.name.should eq name
81
- user.email.should eq email # test that the user changed appropriately
82
- end
83
-
84
- end
85
- end
@@ -1,107 +0,0 @@
1
- require './spec/spec_helper'
2
- require './lib/gas'
3
-
4
-
5
- describe Gas::GithubSpeaker do
6
-
7
- before :each do
8
- config = "[#{@nickname}]\n name = #{@name}\n email = #{@email}\n\n[user2]\n name = foo\n email = bar"
9
- @config = Gas::Config.new nil, config
10
- @user = @config.users[0]
11
-
12
- @username = "aTestGitAccount" # be VERY careful when plugging in your own testing account here...
13
- @password = "plzdon'thackthetestaccount1" # It will delete ALL keys associated with that account if you run the tests
14
-
15
- @sample_rsa = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQDn74QR9yHb+hcid8iH3+FTaEwnKtwjttseJDbIA2PaivN2uvESrvHlp8Ss/cRox3fFu34QR5DpdOhlfULjTX7yKVuxhaNrAJaqg8rX8hgr9U1Botnyy1DBueEyyA3o1fxRkmwTf6FNnkt1BxWP635tD0lbmUubwaadXjQqPOf3Uw=="
16
-
17
- VCR.use_cassette('instantiate_github_speaker') do
18
- @github_speaker = Gas::GithubSpeaker.new(@user, @username, @password)
19
- end
20
- end
21
-
22
- describe "test keys" do
23
-
24
- describe "with no keys..." do
25
- after :each do
26
- delete_all_keys_in_github_account!(@github_speaker)
27
- end
28
-
29
- it "should post_key! all the way up to github" do
30
- initial_length = 'VCR introduces scope =('
31
- final_length = ''
32
-
33
- VCR.use_cassette('get_keys-find_none') do
34
- initial_length = get_keys(@username, @password).length
35
- end
36
-
37
- VCR.use_cassette('githubspeaker-post_key') do # this test has been saved under fixtures/install-delete-a-key.yml
38
- @github_speaker.post_key! @sample_rsa
39
- end
40
-
41
- VCR.use_cassette('get_keys-find_one') do
42
- final_length = get_keys(@username, @password).length
43
- end
44
-
45
- (final_length - initial_length).should be(1)
46
- end
47
-
48
- it "should expose an empty array when no keys..." do
49
- VCR.use_cassette('check_keys-empty') do
50
- @github_speaker.keys.empty?.should be_true
51
- end
52
- end
53
-
54
- it "should expose a key created..." do
55
- VCR.use_cassette('github_speaker-post_key') do
56
- @github_speaker.post_key! @sample_rsa
57
- end
58
-
59
- @github_speaker.keys.empty?.should be_false
60
- end
61
- end
62
-
63
- describe "with a key" do
64
- before :each do
65
- VCR.use_cassette('github_speaker-post_key') do
66
- @github_speaker.post_key! @sample_rsa
67
- end
68
-
69
- @key_id = @github_speaker.keys.first['id']
70
- end
71
-
72
- after :each do
73
- delete_all_keys_in_github_account!(@github_speaker)
74
- end
75
-
76
- it "should remove_key! from github" do
77
- initial_length = ''
78
- final_length = ''
79
-
80
- VCR.use_cassette('get_keys-find_one') do
81
- initial_length = get_keys(@username, @password).length
82
- end
83
-
84
- VCR.use_cassette('githubspeaker-remove_key') do
85
- @github_speaker.remove_key! @sample_rsa
86
- end
87
-
88
- VCR.use_cassette('get_keys-find_none') do
89
- final_length = get_keys(@username, @password).length
90
- end
91
-
92
- (final_length - initial_length).should be(-1)
93
- end
94
-
95
- it "should remove a key from @keys" do
96
- #require 'pry';binding.pry
97
- Gas::GithubSpeaker.publicize_methods do
98
- @github_speaker.remove_key_from_keys @key_id
99
- end
100
-
101
- @github_speaker.keys.empty?.should be_true
102
- end
103
- end
104
-
105
- end
106
-
107
- end
@@ -1,56 +0,0 @@
1
- require './spec/spec_helper'
2
-
3
- require './lib/gas'
4
-
5
- describe Gas::Settings do
6
-
7
- before(:all) do
8
- @subject = Gas::Settings.new
9
- end
10
-
11
- it 'should respond to base_dir' do
12
- @subject.should respond_to :base_dir
13
- end
14
-
15
- it 'should give default value for base_dir' do
16
- @subject.base_dir.should == '~'
17
- end
18
-
19
- it 'should respond to gas_dir' do
20
- @subject.should respond_to :gas_dir
21
- end
22
-
23
- it 'should give default value for gas_dir' do
24
- @subject.gas_dir.should == "#{@subject.base_dir}/.gas"
25
- end
26
-
27
- it 'should respond to ssh_dir' do
28
- @subject.should respond_to :ssh_dir
29
- end
30
-
31
- it 'should give default value for ssh_dir' do
32
- @subject.ssh_dir.should == "#{@subject.base_dir}/.ssh"
33
- end
34
-
35
- it 'should respond to github_server' do
36
- @subject.should respond_to :github_server
37
- end
38
-
39
- it 'should give default value for github_server' do
40
- @subject.github_server.should == 'api.github.com'
41
- end
42
-
43
- it 'should be configurable' do
44
- @subject.configure do |s|
45
- s.base_dir = 'test'
46
- s.gas_dir = 'foo'
47
- s.ssh_dir = 'bar'
48
- s.github_server = 'foobar'
49
- end
50
- @subject.base_dir.should eq 'test'
51
- @subject.gas_dir.should eq "#{@subject.base_dir}/foo"
52
- @subject.ssh_dir.should eq "#{@subject.base_dir}/bar"
53
- @subject.github_server.should eq 'foobar'
54
- end
55
-
56
- end